HP RPG/XL Programmer's Guide (30318-90001)

4- 70
2 This line begins the description of the record used for all
terminal input. (The lines were generated by SIGEDITOR, then
modified.)
3 This line begins the mainline portion of the program. The
subroutine ONETIM is executed only at the beginning of the first
logic cycle. The other subroutines are executed when the user
presses the associated command key (for example, CMD-2 Change).
4 This line begins the subroutine that adds records to the
D-ACCOUNTS data set. The subroutine first resets (in the RESET
subroutine) all indicators used in the previous cycle. Next,
indicators 41 and 80 are turned ON. Indicator 41 is used to
change the video attribute for the constant "CMD-1 Add" so that
the user knows what the current mode is. Indicator 80 is the
"erase input fields" indicator. It causes all input fields to
be cleared before the form is displayed. (This saves having to
initialize each field yourself before displaying the form.)
The form is displayed by the EXCPT R$DATA operation. Then, the
RDSCRN subroutine reads the form and checks to see if the user
pressed the ENTER key or some other enabled command key.
Control remains in the subroutine until the user presses another
command key. When this happens, control proceeds to the end of
the subroutine. (The mainline portion of the program processes
the command key request during the next logic cycle.)
The RECINP subroutine checks to see if the data record already
exists in D-ACCOUNTS. If it does, the account number field is
cleared, and the form is redisplayed with the error message
"EXISTING ACCOUNT NUMBER" (override is in effect so that the
user can enter the correct account number). If there are no
errors (indicator 40 is OFF), a record is added to the data set
by the EXCPT $ADD operation and control goes back to the
beginning of this step.
5 This line begins the subroutine that updates D-ACCOUNTS data set
records. The RESET subroutine turns OFF indicators that were
turned ON during the previous logic cycle, then indicators 42
and 80 are turned ON. The RSI form is displayed, then read. If
the user pressed another command key (indicator 49 is OFF)
control skips to the end of the subroutine.
The RECINP subroutine reads the record from the D-ACCOUNTS data
set. If the record exists, indicator 40 is turned ON and the
form containing account information is displayed. Control skips
to CNGMSG where changes are read. If the record does not exist,
indicator 80 is turned OFF so that the "Erase input fields"
attribute will not be in effect. The error message "INVALID
ACCOUNT NUMBER" is displayed and control skips back to CNGMSG to
accept
the new account information.
After the new information is read, the record in D-ACCOUNTS is
updated by the EXCPT $UPD operation. Control remains in the
subroutine until the user changes modes (presses a different
command key).
6 This line begins the subroutine that locates records in the
D-ACCOUNTS data set and prepares error messages for display.
The CHAIN operation reads D-ACCOUNTS using ACTNO as its key
field. If the record is not found, indicator 60 is turned ON.
If add mode is in effect and the record is found, or if other
modes are in effect and the record is not found, an error
results. The index of the appropriate error message in MSG is
placed in the variable M# and indicator 82 is turned ON.