Joined: 03 Aug 2006 Posts: 2 Topics: 1 Location: North Carolina
Posted: Thu Aug 03, 2006 8:03 pm Post subject: VSAM Assembler PUT (add) fails after GET (not found)
I have an Assembler program which reads a control file of record keys used to update a key-sequenced VSAM file. When a matching record is found, it must be updated. When a matching record is not found a new record must be added using the key from the control file.
ACB options are MACRF=(DIR,OUT)
RPL options are MACRF=(DIR,UPD)
Update of an existing record (GET/FDBK=0 then PUT) works perfectly, but when I do PUT after record not found (GET/FDBK=16, then PUT) I get a feedback code of 92 (X'5C') which, according to the manual, means "The application issued a PUT for update... without a previous GET for update".
Which sort of makes sense, since the get for update failed because the record wasn't found.
So how do you add a record in this situation?? Should I use a 2nd RPL defined as NUP (meaning no update/new records only)? Or is there some cleaner way?
Joined: 03 Aug 2006 Posts: 2 Topics: 1 Location: North Carolina
Posted: Fri Aug 04, 2006 3:10 pm Post subject:
Looks like the trick is to use MODCB to switch the RPL from UPD to NUP and back again. Here is the essential code I used and now it works fine. Non-essential code was omitted for sake of brevity, so ACB OPEN/CLOSE, ERROR routine, variables, etc, will be needed to make this sample useable.
Code:
* SAMPLE CODE USING MODCB TO ADD RECORD IF RECORD NOT FOUND *
LOOP MVC KEY,KEYVAR SET RECORD KEY
GET RPL=RPL GET RECORD FOR UPDATE
LTR R15,R15 GOT A RECORD?
BZ UPDATE YES: GO UPDATE
SHOWCB RPL=RPL,FIELDS=FDBK,AREA=FDBK,LENGTH=4
CLC FDBK+2(2),=H'16' RECORD NOT FOUND?
BNE ERROR NO: SOME OTHER ERROR
MODCB RPL=RPL,OPTCD=NUP YES: SET RPL TO ADD (NOT UPD)
UPDATE MVC DATA,DATAVAR MOVE VARIABLE DATA TO RECORD
PUT RPL=RPL UPDATE (OR ADD) RECORD
CLC FDBK+2(2),=H'16' "NEW RECORD"?
BNE LOOP NO: CONTINUE
MODCB RPL=RPL,OPTCD=UPD YES: RESET RPL TO UPD (NOT ADD)
B LOOP CONTINUE
ACB ACB DDNAME=VSAM,MACRF=(DIR,OUT)
RPL RPL ACB=ACB,OPTCD=(DIR,UPD),AREA=REC,AREALEN=16,ARG=KEY
REC DS 0CL16
KEY DS CL8
DATA DS CL8
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum