Example: Code for a standard commit processing program
The standard commit (STDCMT) processing program performs the functions required to communicate with a single notify object used by all applications.
While the commitment control function automatically writes an entry to the notify object, a user-written standard program must process the notify object. The standard program simplifies and standardizes the approach.
The program is written to verify the parameters that were passed and perform the appropriate action as follows:
- O=Open
- The calling program requests the notify object file be kept open on return. Because the notify object is opened implicitly by the RPG program, the program must not close it. Indicator 98 is set so that the program returns with LR off to keep the program's work areas and leaves the notify object open so it can be called again without excess overhead.
- C=Close
- The calling program has determined that it no longer needs the notify object and requests a close. Indicator 98 is set off to allow a full close of the notify object.
- R=Read
- The calling program requests that a record with matching key fields be read and passed back. The program uses the passed key fields to attempt to retrieve a record from NFYOBJP. If duplicate records exist for the same key, the last record is returned. The return code is set accordingly and, if the record existed, it is passed back in the data structure CMTID.
- W=Write
- The calling program requests a record to be written to the notify object to allow the calling program to start again the next time it is called. The program writes the contents of the passed data as a record in NFYOBJP.
- D=Delete
- The calling program requests that records for this matching key be deleted. This function is typically performed at the successful completion of the calling program to remove any information about starting again. The program attempts to delete any records for passed key fields. If no records exist, a different return code is passed back.
- S=Search
- The calling program requests a search for a record for a particular user regardless of which program wrote it. This function is used in the program for sign-on to indicate that starting again is required. The program uses only the user name as the key to see if records exist. The return code is set appropriately, and the contents of the last record for this key (if it exists) are read and passed back.
The following example shows the standard commit processing program, STDCMT.
Standard commit processing program
By using the code example, you agree to the terms of the Code license and disclaimer information.
SEQNBR *... ... 1 ... ... 2 ... ... 3 ... ... 4 ... ... 5 ... ... 6 ... ... 7 .. 1.00 FNFYOBJP UF E K DISK A 2.00 ICMTID DS 3.00 I 1 10 UNQUSR 4.00 I 11 20 UNQPGM 5.00 I 21 220 BIGFLD 6.00 C *ENTRY PLIST 7.00 C PARM RQSCOD 1 8.00 C PARM RTNCOD 1 9.00 C PARM CMTID 220 10.00 C UNQUSR CABEQ*BLANKS BADEND H1 Invalid 11.00 C UNQPGM CABEQ*BLANKS BADEND H2 Invalid 12.00 C* 13.00 C* 'O' for Open 14.00 C* 15.00 C RQSCOD IFEQ 'O' Open 16.00 C SETON 98 End LR 17.00 C GOTO END 18.00 C END 19.00 C* 20.00 C* 'C' for Close 21.00 C* 22.00 C RQSCOD IFEQ 'C' Close 23.00 C SETOF 98 24.00 C GOTO END 25.00 C END 26.00 C* 27.00 C* 'R' for Read - Get last record for the key 28.00 C* 29.00 C RQSCOD IFEQ 'R' Read 30.00 C KEY KLIST 31.00 C KFLD UNQUSR 32.00 C KFLD UNQPGM 33.00 C KEY CHAINNFYOBJR 51 Not found 34.00 C 51 MOVE '0' RTNCOD 35.00 C 51 GOTO END 36.00 C MOVE '1' RTNCOD Found 37.00 C LOOPl TAG 38.00 C KEY READENFYOBJR 20 EOF 39.00 C 20 GOTO END 40.00 C GOTO LOOP1 41.00 C END 42.00 C* 43.00 C* 'W' FOR Write 44.00 C* 45.00 C RQSCOD IFEQ 'W' Write 46.00 C WRITENFYOBJR 47.00 C GOTO END 48.00 C END 49.00 C* 50.00 C* 'D' for Delete - Delete all records for the key 51.00 C* 52.00 C RQSCOD IFEQ 'D' Delete 53.00 C KEY CHAINNFYOBJR 51 Not found 54.00 C 51 MOVE '0' RTNCOD 55.00 C 51 GOTO END 56.00 C MOVE '1' RTNCOD Found 57.00 C LOOP2 TAG 58.00 C DELETNFYOBJR 59.00 C KEY READENFYOBJR 20 EOF 60.00 C N20 GOTO LOOP2 61.00 C GOTO END 62.00 C END 63.00 C* 64.00 C* 'S' for Search for the last record for this user 65.00 C* (Ignore the -Program- portion of the key) 66.00 C* 67.00 C RQSCOD IFEQ 'S' Search 68.00 C UNQUSR SETLLNFYOBJR 20 If equal 69.00 C N20 MOVE '0' RTNCOD 70.00 C N20 GOTO END 71.00 C MOVE '1' RTNCOD Found 72.00 C LOOP3 TAG 73.00 C UNQUSR READENFYOBJR 20 EOF 74.00 C N20 GOTO LOOP3 75.00 C GOTO END 76.00 C END 77.00 C* 78.00 C* Invalid request code processing 79.00 C* 80.00 C SETON H2 Bad RQS code 81.00 C GOTO BADEND 82.00 C* 83.00 C* End of program processing 84.00 C* 85.00 C END TAG 86.00 C N98 SETON LR 87.00 C RETRN 88.00 C* BADEND tag is used then fall thru to RPG cycle error return 89.00 C BADEND TAG
Parent topic:
Example: Using a standard processing program to start an application
Related concepts
Example: Using a standard processing program to decide whether to restart the application