Problem with LMGET after an LMPUT & LMADD
Posted: Fri Jun 10, 2011 12:50 am
My program reads a member of a PDS, and processes statements within it. If the member does not exist, then i create it with a dummy statement; but i get a RC=* when i attempt to read that member within the same program invocation. If i run the program again after the member has been created, i can read it it successfully. I think i'm missing a FREE, or specifying the wrong DATAID, or ??? Any suggestions as to what's missing in the attached code?
/* REXX */
PARSE SOURCE s1 s2 s3 s4 s5 s6 s7 s8 s9
thislib = s5
membr = "$MYDSN$"
prefix = sysvar('SYSPREF') /* tso profile prefix */
uid = sysvar('SYSUID') /* tso userid */
If prefix = '' then prefix = uid /* use uid if null prefix */
If prefix <> '' & prefix <> uid then /* different prefix than uid */
prefix = prefix || '.' || uid /* use prefix.uid */
call S100_PDS_Get_Member
say " CYaBy..."
exit (0)
S100_PDS_Get_Member:
Address ISPEXEC
"LMINIT DATAID(MYDSNS) DATASET('"thislib"') ENQ(SHR)"
"LMOPEN DATAID("mydsns") option(input)"
"LMMFIND DATAID("mydsns") MEMBER("membr")"
if rc = 8 then /* member not there, so add it... */
do
Say "Member '"thislib"("membr")' is not there; creating... "
"LMMLIST DATAID("mydsns") OPTION(FREE)" /* free the list */
"LMCLOSE DATAID("mydsns")" /* close as input, reopen as output */
"LMFREE DATAID("mydsns")"
"LMINIT DATAID(MYDSNS) DATASET('"thislib"') ENQ(SHRW)"
"LMOPEN DATAID("mydsns") option(output)"
recdline = thislib
"LMPUT DATAID("mydsns") MODE(INVAR) ",
" DATALOC(recdline) DATALEN(80)"
"LMMADD DATAID("mydsns") MEMBER("membr") STATS(NO)"
"LMMLIST DATAID("mydsns") OPTION(FREE)" /* free the list */
"LMCLOSE DATAID("mydsns")" /* close as output, reopen as input*/
"LMFREE DATAID("mydsns")"
"LMINIT DATAID(MYDSNS) DATASET('"thislib"') ENQ(SHR)"
"LMOPEN DATAID("mydsns") option(input)"
end
Call S200_Records_Get
"LMMLIST DATAID("mydsns") OPTION(FREE)" /* free the list */
"LMCLOSE DATAID("mydsns")"
"LMFREE DATAID("mydsns")"
Return
S200_Records_Get:
LM_GET = "LMGET DATAID("mydsns") mode(invar) dataloc(myrec) ",
" datalen(inlen) maxlen(080)"
do forever
LM_GET
if rc = 0 then
do
call S300_Record_Process
end
else
if rc = 8 then
do
/* say "LMGET EOF..." */
leave
end
else
do
say "LMGET bad RC = " rc
leave
end
end
Return
S300_Record_Process:
Return
PARSE SOURCE s1 s2 s3 s4 s5 s6 s7 s8 s9
thislib = s5
membr = "$MYDSN$"
prefix = sysvar('SYSPREF') /* tso profile prefix */
uid = sysvar('SYSUID') /* tso userid */
If prefix = '' then prefix = uid /* use uid if null prefix */
If prefix <> '' & prefix <> uid then /* different prefix than uid */
prefix = prefix || '.' || uid /* use prefix.uid */
call S100_PDS_Get_Member
say " CYaBy..."
exit (0)
S100_PDS_Get_Member:
Address ISPEXEC
"LMINIT DATAID(MYDSNS) DATASET('"thislib"') ENQ(SHR)"
"LMOPEN DATAID("mydsns") option(input)"
"LMMFIND DATAID("mydsns") MEMBER("membr")"
if rc = 8 then /* member not there, so add it... */
do
Say "Member '"thislib"("membr")' is not there; creating... "
"LMMLIST DATAID("mydsns") OPTION(FREE)" /* free the list */
"LMCLOSE DATAID("mydsns")" /* close as input, reopen as output */
"LMFREE DATAID("mydsns")"
"LMINIT DATAID(MYDSNS) DATASET('"thislib"') ENQ(SHRW)"
"LMOPEN DATAID("mydsns") option(output)"
recdline = thislib
"LMPUT DATAID("mydsns") MODE(INVAR) ",
" DATALOC(recdline) DATALEN(80)"
"LMMADD DATAID("mydsns") MEMBER("membr") STATS(NO)"
"LMMLIST DATAID("mydsns") OPTION(FREE)" /* free the list */
"LMCLOSE DATAID("mydsns")" /* close as output, reopen as input*/
"LMFREE DATAID("mydsns")"
"LMINIT DATAID(MYDSNS) DATASET('"thislib"') ENQ(SHR)"
"LMOPEN DATAID("mydsns") option(input)"
end
Call S200_Records_Get
"LMMLIST DATAID("mydsns") OPTION(FREE)" /* free the list */
"LMCLOSE DATAID("mydsns")"
"LMFREE DATAID("mydsns")"
Return
S200_Records_Get:
LM_GET = "LMGET DATAID("mydsns") mode(invar) dataloc(myrec) ",
" datalen(inlen) maxlen(080)"
do forever
LM_GET
if rc = 0 then
do
call S300_Record_Process
end
else
if rc = 8 then
do
/* say "LMGET EOF..." */
leave
end
else
do
say "LMGET bad RC = " rc
leave
end
end
Return
S300_Record_Process:
Return