Running a Program From a Menu-Driven Application
Running a Program From a Menu-Driven Application
Another way to run an ILE program is from a menu-driven application. The workstation user selects an option from a menu, which in turn calls a particular program. Figure 1 illustrates an example of an application menu.
Figure 1. Example of an Application Menu
PAYROLL DEPARTMENT MENU
Select one of the following:
1. Inquire into employee master
2. Change employee master
3. Add new employee
Selection or command
===> _________________________________________________________________________
_______________________________________________________________________________
F3=Exit F4=Prompt F9=Retrieve F12=Cancel
F13=Information Assistant F16=System main menu
The menu shown in Figure 1 is displayed by a menu program in which each option calls a separate ILE program.
Figure 2 shows the DDS for the display file of the above PAYROLL DEPARTMENT MENU. The source member is called PAYROL and has a source type of MNUDDS.
Figure 2. Data Description Specification of an Application Menu
A* Free Form Menu: PAYROL
A*
A DSPSIZ(24 80 *DS3 -
A 27 132 *DS4)
A CHGINPDFT
A INDARA
A PRINT(*LIBL/QSYSPRT)
A R PAYROL
A DSPMOD(*DS3)
A LOCK
A SLNO(01)
A CLRL(*ALL)
A ALWROL
A CF03
A HELP
A HOME
A HLPRTN
A 1 34'PAYROLL DEPARTMENT MENU'
A DSPATR(HI)
A 3 2'Select one of the following:'
A COLOR(BLU)
A 5 7'1.'
A 6 7'2.'
A 7 7'3.'
A 5 11'Inquire into employee master'
A 6 11'Change employee master'
A 7 11'Add new employee'
A* CMDPROMPT Do not delete this DDS spec.
A 019 2'Selection or command'
Figure 3 shows the source for a program to create a message file for the menu.
Figure 3. Source to create the menu
The CRTMNU command requires a display file and a message file.
- Create the display file.
- Create the message file. The text for each message “USRnnnn” is the command to be done when the option “nnnn” is selected. For example, the message “USR0001” has the command “CALL RPGINQ” that is done when option 1 is selected.
- Create the menu.
DCL &SRCLIB TYPE(*CHAR) VALUE('MYLIB')
DCL &SRCFILE TYPE(*CHAR) VALUE('MYSRC')
DCL &MNULIB TYPE(*CHAR) VALUE('MYLIB')
CRTDSPF &SRCLIB/PAYROL SRCFILE(&SRCLIB/&SRCFILE) SRCMBR(PAYROL) /* 1 */
CRTMSGF &MNULIB/PAYROL /* 2 */
ADDMSGD USR0001 MSGF(&MNULIB/PAYROL) +
MSG('CALL RPGINQ') /* Option 1 */
ADDMSGD USR0002 MSGF(&MNULIB/PAYROL) +
MSG('CALL RPGCHG') /* Option 2 */
ADDMSGD USR0003 MSGF(&MNULIB/PAYROL) +
MSG('CALL RPGADD') /* Option 3 */
CRTMNU &MNULIB/PAYROL +
TYPE(*DSPF) +
DSPF(&MNULIB/PAYROL) +
MSGF(&MNULIB/PAYROL) /* 3 */
You run the menu by entering:
GO MYLIB/PAYROL
If the user enters 1, 2, or 3 from the application menu, a call is done to program RPGINQ, RPGCHG, or RPGADD respectively.