This sample program shown in this topic illustrates the use of externally described data in a program.
If you enter the DDS for these files on your system and create them using the Create Physical File (CRTPF) command, the Create Display File (CRTDSPF) command, and the Create Printer File (CRTPRTF) command, this program allows you to add records to the physical file, display and update the records, and print a report.
The program is written in Report Program Generator (RPG). You can enter the RPG specifications shown in the example into a source file on your system and create the program using the Create RPG Program (CRTRPGPGM) command. For more information about RPG, see the RPG/400® Reference manual on the V5R1 Supplemental Manuals Web site.
The TAG op code indicates a label in the program. The EXFMT op code writes the record PROMPT to the display, then reads it when the user presses the Enter key. The CHAIN op code retrieves a record from CUSMST based on the key field ACTNUM. If no record with that key value is found, indicator 30 is turned on. The program continues to prompt until the key value of an existing record is entered in field ACTNUM (indicator 30 off) or an A is entered in field ADD.
If a new customer is being added (indicator 30 is on), the WRITE op code adds a new record to the physical file. Otherwise, the UPDAT op code updates an existing record. The program continues to prompt for, retrieve, add, and update records in the physical file until F3 is pressed, setting on indicator 21.
A record is read from the physical file and the DETAIL record is written to the printer file until the end of the physical file is reached (indicator 45 is set on). The HEADER record is written on the first page and then written again on each new page (indicator 10 is on). When all the records have been written, the CLOSE op code closes all the files and SETON LR ends the program.