Sample RPG Program
The program in Figure 4-1 uses two forms, FORM21 and FORM22, in the forms
file SAMPLIB. The program adds, deletes, and updates records in a KSAM
file.
___________________________________________________________________________________
| |
| 1 2 3 4 5 6 7 |
| 678901234567890123456789012345678901234567890123456789012345678901234|
| |
| |
| HDUMPFILE JF X B B N P1 1 |
| |
| 1 FWORKSTN UP V 90 WORKSTNR B |
| F KFORMS SAMPLIB |
| FCUSTMASTUC F 128R 9AI 1 DISK A |
| F KKEYFL KCUSTMST |
| F* |
| F* SAMPLE RSI PROGRAM USING THE WORK STATION AS A PRIMARY FILE |
| F* |
| |
| 2 IWORKSTN NS 01 1 C1 |
| I* FORM21 |
| I 1 1 FLD1 |
| I 2 100SSN |
| I NS 02 1 C2 |
| I* FORM22 |
| I 1 1 FLD1 |
| I 2 27 NAME |
| I 28 63 ADDR |
| I 64 720ZIP |
| I 73 82 PHONE# |
| I NS |
| 3 ICUSTMASTNS |
| I 1 90SSN |
| I 10 35 NAME |
| I 36 71 ADDR |
| I 72 800ZIP |
| I 81 90 PHONE# |
| |
| C* CLEAN UP |
| 4 C 01 SETOF 808182 |
| C 01 SETOF 656070 |
| C* DETERMINE ACTION REQUESTED |
| 5 C KA SETON 80 ADD RECORD |
| C KB SETON 81 DEL RECORD |
| C KC SETON 82 UPD RECORD |
| C KG SETON LR END JOB |
| C KG GOTO EOF |
| 6 C N01 GOTO EOF |
| C* READ RECORD FROM CUSTOMER MASTER FILE USING SSN AS A KEY |
| C SETOF 42 |
| C SSN CHAINCUSTMAST 42 NO HIT |
___________________________________________________________________________________
Figure 5-1. RPG Program (continued)
___________________________________________________________________________________
| |
| 1 2 3 4 5 6 7 |
| 678901234567890123456789012345678901234567890123456789012345678901234|
| |
| C* SET INDICATORS FOR ERRORS |
| 7 C 80N42 SETON 6070 |
| C N80 42 SETON 6065 |
| C EOF TAG |
| 8 OWORKSTN D 1P |
| O OR 02 |
| O OR 01 60 |
| O OR 01 81 |
| O K6 "FORM21" |
| O 70 6 "0001 1" |
| O 65 6 "0002 1" |
| O** |
| 9 O D 01 80 42 |
| O OR 01 82N42 |
| O K6 "FORM22" |
| O SSN 9 |
| O NAME 35 |
| O ADDR 71 |
| O ZIP 80 |
| O PHONE# 90 |
| O* UPDATE DISK RECORD |
| 10 OCUSTMASTD 02 82 |
| O SSN B 9 |
| O NAME B 35 |
| O ADDR B 71 |
| O ZIP B 80 |
| O PHONE# B 90 |
| O* ADD DISK RECORD |
| O DADD 02 80 |
| O SSN B 9 |
| O NAME B 35 |
| O ADDR B 71 |
| O ZIP B 80 |
| O PHONE# B 90 |
| O* DELETE DISK RECORD |
| O DDEL 01 81N42 |
| O SSN B 9 |
| O NAME B 35 |
| O ADDR B 71 |
| O ZIP B 80 |
| O PHONE# B 90 |
| O* END OF SOURCE STATEMENTS |
___________________________________________________________________________________
Figure 5-1. RPG Program (continued)
FORM21 (shown in Figure 4-2) allows the user to enter a social security
number, choose to add a new record, delete an existing record, or update
an existing record.
____________________________________________________________
| |
| CUSTOMER INFORMATION FORM |
| |
| Please enter Social Security Number|
| |
| 306-46-7778 |
| |
| |
| RECORD ALREADY EXISTS |
| |
| |
| Press CMD 1 TO ADD NEW RECORD |
| CMD 2 TO DELETE EXISTING RECORD |
| CMD 3 TO UPDATE EXISTING RECORD |
| CMD 7 TO END JOB |
| |
| |
| |
| |
| |
| |
____________________________________________________________
Figure 5-2. FORM21
If you choose to add a new record, the system searches the KSAM file for
a record with the specified social security number. If the record
already exists, an error message is displayed in a message field, as
shown in Figure 4-2. If there is no associated record, FORM22 appears,
and you can enter the record. The social security number appears on
FORM22 automatically, as shown in Figure 4-3. When you press the ENTER
key, the new record is added to the KSAM file.
____________________________________________________________________________________
| |
| SOC. SEC. NO. 306-46-7778 |
| |
| |
| NAME MARY Q. QUAIL |
| |
| ADDRESS MORSE GROVE, FLA |
| |
| ZIP CODE 339080000 PHONE NO. 813-672-1212 |
| |
| |
| PRESS :ENTER: |
| |
| |
| |
| |
| |
| COMMAND *PRINT f3 f4 f5 f6 f7 f8|
| SCREEN |
| |
____________________________________________________________________________________
Figure 5-3. FORM22
When a record is deleted, the system searches the KSAM file for that
record. If found, the record is marked for deletion; if not found, a
message is displayed.
When a record is updated, the record is displayed on FORM22 so
modifications can be made. If the requested record cannot be found, a
message is displayed.