Example: Unique notify object for each program
Using a single, unique notify object for each job allows use of an externally described commit identification even though there might be multiple users of the same program.
In the following examples, a database file is used as a notify object and it is used only by this program.
The program has two database files (PRDMSTP and PRDLOCP) that must be updated for receipts to inventory. The display file used by the program is named PRDRCTD. A database file, PRDRCTP, is used as the notify object. This notify object is defined to the program as a file and is also used as the definition of a data structure for the notify function.
By using the code examples, you agree to the terms of the Code license and disclaimer information.
DDS for physical file PRDLOCP
SEQNBR *... ... 1 ... ... 2 ... ... 3 ... ... 4 ... ... 5 ... ... 6 ... ... 7 1.00 A R PRDLOCR TEXT('Location record') 2.00 A PRODCT 3 COLHDG('Product' 'Number') 3.00 A LOCATN 6 COLHDG('Location') 4.00 A LOCAMT 5 0 COLHDG('Location' 'Amount') 5.00 A EDTCDE(Z) 6.00 A K PRODCT 7.00 A K LOCATN
DDS for display file PRDRCTD
SEQNBR *... ... 1 ... ... 2 ... ... 3 ... ... 4 ... ... 5 ... ... 6 ... ... 7 .. 1.00 A REF(PRDMSTP) 2.00 A R PROMPT 3.00 A CA03(98 'End of program') 4.00 A SETOFF(71 'RESTART') 5.00 A 1 20'PRODUCT RECEIPTS' 6.00 A 3 2'Quantity' 7.00 A QTY 3 OI +1 8.00 A +6'Product' 9.00 A PRODCT R I +1 10.00 A 61 ERRMSG('No record + 11.00 A found in the + 12.00 A master file' 62) 13.00 A +6'Location' 14.00 A LOCATN R I +1REFFLD(LOCATN PRDLOCP) 15.00 A 62 ERRMSG('No record + 16.00 A found in the + 17.00 A location file' 62) 18.00 A 9 2'Last Transaction' 19.00 A 71 +6'This is restart + 20.00 A information' 21.00 A DSPATR(HI BL) 22.00 A 12 2'Quantity' 23.00 A 12 12'Product' 24.00 A 12 23'Location' 25.00 A 12 35'Description' 26.00 A LSTPRD R 14 15REFFLD(PRODCT) 27.00 A LSTLOC R 14 26REFFLD(LOCATN *SRC) 28.00 A LSTQTY R 14 5REFFLD(QTY *SRC) 29.00 A EDTCDE(Z) 30.00 A LSTDSC R 14 35REFFLD(DESCRP)
DDS for notify object and externally described data structure (PRDRCTP)
SEQNBR *... ... 1 ... ... 2 ... ... 3 ... ... 4 ... ... 5 ... ... 6 ... ... 7 .. 1.00 A LIFO 2.00 A REF(PRDMSTP) 3.00 A R PRDRCTR 4.00 A USER 10 5.00 A PRODCT R 6.00 A DESCRP R 7.00 A QTY 3 0 8.00 A LOCATN R REFFLD(LOCATN PRDLOCP) 9.00 A K USERThe program processes the notify object as follows:
- At the beginning, the program randomly processes the notify object and displays a record if it exists for the specific key:
- If multiple records exist, the last record for this key is used because the PRDRCTP file is in LIFO sequence.
- If no record exists, a transaction was not interrupted so it is not necessary to start again.
- If the program fails before the first successful commit operation, it does not consider that starting again is required.
- The routine to clear the notify object occurs at the end of the program:
- If there were multiple failures, the routine can handle deletion of multiple records in the notify object.
- Although the system places the commit identification in a database file, the commit identification must be specified as a variable in the RPG program.
- Because RPG allows a data structure to be externally described, a data structure is a convenient way of specifying the commit identification. In this example, the data structure uses the same external description that the database file used as the notify object.
The processing for this program prompts the user for a product number, a location, and a quantity:
- Two files must be updated:
- Product master file (PRDMSTP)
- Product location file (PRDLOCP)
- A record in each file must exist before either is updated.
- The program moves the input fields to corresponding last fields after each transaction is successfully entered. These last fields are displayed to the operator on each prompt as feedback for what was last entered.
- If information for starting again exists, it is moved to these last fields and a special message appears on the display.
This process is outlined in the following figure. The user name is passed to the program to provide a unique record in the notify object.
Program flow
The following example is about the RPG source code. The notify object (file PRDRCTP) is used as a normal file at the beginning and end of the program, and is also specified as the notify object in the CL (STRCMTCTL command) before calling the program.
RPG source
SEQNBR *... ... 1 ... ... 2 ... ... 3 ... ... 4 ... ... 5 ... ... 6 ... ... 7 .. 1.00 FPRDMSTP UF E K DISK KCOMIT 2.00 FPRDLOCP UF E K DISK KCOMIT 3.00 FPRDRCTD CF E WORKSTN 4.00 F* 5.00 F* The following file is the specific notify object for this pgm. 6.00 F* It is accessed only in a restart situation and at the 7.00 F* end of the program to delete any records. The records 8.00 F* are written to the notify object by Commitment Control. 9.00 F* 10.00 FPRDRCTP UF E K DISK 11.00 ICMTID E DSPRDRCTP 12.00 C *ENTRY PLIST 13.00 C PARM USER10 10 14.00 C MOVE USER10 USER 15.00 C* 16.00 C* Check for restart information - get last rcd per user 17.00 C* PRDRCTP file access path is in LIFO sequence 18.00 C* 19.00 C USER CHAINPRDRCTR 20 Not found 20.00 C N20 DO Restart 21.00 C EXSR MOVLST Move to last 22.00 C SETON 71 Restart 23.00 C END 24.00 C* 25.00 C* Basic processing loop 26.00 C* 27.00 C L00P TAG 28.00 C EXFMTPROMPT 29.00 C 98 GOTO END End of pgm 30.00 C PRODCT CHAINPRDMSTR 61 Not found 31.00 C 61 GOTO L00P 32.00 C KEY KLIST 33.00 C KFLD PRODCT 34.00 C KFLD LOCATN 35.00 C KEY CHAINPRDLOCR 62 Not found 36.00 C 62 DO 37.00 C EXCPTRLSMST Release lck 38.00 C GOTO L00P 39.00 C END 40.00 C ADD QTY ONHAND Add 41.00 C ADD QTY LOCAMT 42.00 C UPDATPRDMSTR Update 43.00 C UPDATPRDLOCR Update 44.00 C* 45.00 C* Commit and move to previous fields 46.00 C* 47.00 C CMTID COMIT 48.00 C EXSR MOVLST Move to last 49.00 C GOTO L00P 50.00 C* 51.00 C* End of program processing 52.00 C* 53.00 C END TAG 54.00 C SETON LR 55.00 C*56.00 C* Delete any records in the notify object 57.00 C* 58.00 C DLTLP TAG 59.00 C USER CHAINPRDRCTR 20 Not found 60.00 C N20 DO 61.00 C DELETPRDRCTR Delete 62.00 C GOTO DLTLP 63.00 C END 64.00 C* 65.00 C* Move to -Last Used- fields for operator feedback 66.00 C* 67.00 C MOVLST BEGSR 68.00 C MOVE PRODCT LSTPRD 69.00 C MOVE LOCATN LSTLOC 70.00 C MOVE QTY LSTQTY 71.00 C MOVE DESCRP LSTDSC 72.00 C ENDSR 73.00 OPRDMSTR E RLSMST
Parent topic:
Example: Using a notify object to start an application
Related concepts
Example: Using a transaction logging file to start an application
Commit notify object
Example: Single notify object for all programs