Now you can build menus just like the AS/400's own rolling menus.
by Art Tostaine, Jr.
Programmers migrating from the System/36 to the AS/400 are pleased to see the OS/400 "Rolling Menus" that are used almost everywhere you look. The beauty of these menus is that you can store a great number of options on each menu in an uncluttered, neatly organized manner. I decided that in order to make my applications have that truly native look, I would have to change my System/36-style menu design to this new appearance. Hence, I designed a set of programs that would allow me to quickly set up menus with up to ten pages of menu options. Once these programs are in your system, you only need to add, change, or delete records from a menu option database file in order to set up or modify a rolling menu!
When I first decided to use the rolling menu, I quickly went to SDA and took option #1 (Design Menus) to design my first one. Surprisingly, or maybe not surprisingly, IBM decided not to provide a tool for creating rolling menus such as theirs. I thought that maybe I was missing something, so I called the Midrange Computing BBS and asked everyone, "How do I get AS/400 Rolling Menus?". The answer I received was, "Write a program." So I did.
The system I call MENUS is the result. It consists of the six objects, physical file MENUSPF (1), display file MENUSDF (2), RPG/400 program MENUSR1 (3), CL programs MENUCL and MENUECL (4 and 5), and the command MENU (6).
The system I call MENUS is the result. It consists of the six objects, physical file MENUSPF (Figure 1), display file MENUSDF (Figure 2), RPG/400 program MENUSR1 (Figure 3), CL programs MENUCL and MENUECL (Figures 4 and 5), and the command MENU (Figure 6).
Setting Up the Programs
The first thing you'll need to do is create the physical file MENUSPF. Use option 14 of PDM, or the CRTPF command to create the file after you've keyed in the DDS member. This is the file that will contain the menu information such as title, option numbers, option descriptions, and commands.
Second, key and compile the display file MENUSDF. It consists of a subfile (SCN01B), SFL control record (SCN01A), and command entry line (SCN01C). This screen is formatted in such a way that it will be difficult for the user to distinguish between this menu and an OS/400 menu.
Third, key and compile the RPG/400 program, MENUSR1, and the two CL programs, MENUCL and MENUECL. The RPG/400 program provides for menu to menu chaining (using (F12=Previous), retrieval of previous commands entered (F9=Retrieve), and the Refresh option (F5). The program also allows F4=Prompt by forcing a '?' to the left of the command entered. The MENUCL CL program works with the MENU command to call our system. The MENUECL CL program is called by MENUSR1 to run any command typed in on the command line. The main reason behind not using QCMDEXEC instead was to provide for some error control over what the user enters. More sophisticated error control could be implemented by using QCMDCHK first to verify the command.
Fourth, key and compile the command MENU using MENUCL as the "Program to process command." This is the command which prompts for the name of the first menu to display.
Setting Up the Menu Option File
You will set up your menu names, option numbers, command to be run, and other associated fields in the physical file MENUSPF. You can write an update program to update this file or just use the UPDDTA command. Each record is associated with the option number of a particular menu.
The two key fields of the file are MNNAME (menu name) and MNOPT# (option number). These fields identify what option number of what menu the record represents.
The MNTITL (menu title) field is a 32 character heading for the menu, which displays on screen line one. When keying the title you should center it within the field. You only need to complete this field for the first menu option record of each menu.
MNDESC (option description) is a fifty character field that contains the description of the menu option that the user will see.
MNPGM (program name) is the name of the program to call when the record's menu option is selected. If empty, the program assumes that you want it to run the command in the next field, MNCMD. This system does not provide for the passing of parameters to programs, but you could easily modify it to do so.
MNCMD (command name) is the name of the command to call when the record's menu option is selected. If empty, the program assumes that you want it to run the program in MNPGM. Here you can type the entire command and any parameters, such as WRKSPLF SELECT(*ALL). Any rules that apply to the command also apply to placing the command in the menu system. You can force a command to be prompted when the user selects the option by placing a question mark before the command name.
Use MNNEW (new menu name) to provide menu chaining. Any menu name in this field must be a valid menu name found in this file. When a user selects the option for this record, the system displays the menu indicated in this field. The previous menu name is saved so that the F12=Previous key will return to the previous menu. The program allows you to chain through 99 menus.
A Sample Menu
7 shows a sample PMENUS file. It contains records for the menus MAIN and APMENU. You can use UPDDTA MENUSPF to create the file. Run the sample by entering MENU MAIN. The MAIN menu will be displayed with it's seven options. If MAIN had more than 11 options, a plus sign would display on the bottom right corner to indicate more options. The roll keys will page through up to 99 selections.
Figure 7 shows a sample PMENUS file. It contains records for the menus MAIN and APMENU. You can use UPDDTA MENUSPF to create the file. Run the sample by entering MENU MAIN. The MAIN menu will be displayed with it's seven options. If MAIN had more than 11 options, a plus sign would display on the bottom right corner to indicate more options. The roll keys will page through up to 99 selections.
Option 7 chains you to the menu, APMENU. From there, F12 will return you to MAIN. Play around with this sample and you'll find that it functions just like IBM's menus.
Creating OS/400-Style Rolling Menus
Figure 1 Physical file MENUSPF
A R MENUS TEXT('Menu Source') A MNNAME 10 COLHDG('Menu' 'Name') A MNOPT# 2S 0 COLHDG('Option#') A MNTITL 32 COLHDG('Menu' 'Title') A MNDESC 50 COLHDG('Description') A MNPGM 10 COLHDG('Program' 'Name') A MNCMD 154 COLHDG('Command' 'Name') A MNNEW 10 COLHDG('New' 'Menu') A K MNNAME A K MNOPT#
Creating OS/400-Style Rolling Menus
Figure 2 Display file MENUSDF
A REF(MENUSPF) A PRINT A R SCN01B SFL A MNOPT# R O 5 6EDTWRD(' 0.') A MNDESC R O 5 10 A MNPGM R H A R SCN01A SFLCTL(SCN01B) A CF03(03 'EXIT') A CF04(04 'PROMPT') A CF05(05 'REFRESH') A CF09(09 'RETRIEVE') A CF12(12 'PREVIOUS') A OVERLAY A 21 SFLDSP A 21 SFLDSPCTL A N21 SFLCLR A N29 SFLEND A SFLSIZ(0099) A SFLPAG(0011) A DSPREC 4S 0H SFLRCDNBR A MNNAME R O 1 2 A MNTITL R O 1 24DSPATR(RI) A 3 2'Select one of the following:' A 1 64'Date:' A 1 70DATE EDTCDE(Y) A 2 64'Time:' A 2 70TIME A R SCN01C A 16 6'90. Sign off' A 19 2'Selection or command' A 20 2'===>' A CMD 154A B 20 7DSPATR(HI UL) A 22 2'F3=Exit F4=Prompt F9=Retreive- A F12=Previous' A 23 2'F5=Refresh' A R FMSGSFL SFL A SFLMSGRCD(24) A MSGKEY SFLMSGKEY A PGMQ SFLPGMQ A R FMSGCTL SFLCTL(FMSGSFL) A BLINK OVERLAY A 21 SFLDSP SFLDSPCTL SFLINZ SFLEND A SFLSIZ(0002) SFLPAG(0001) A PGMQ SFLPGMQ
Creating OS/400-Style Rolling Menus
Figure 3 RPG program MENUSR1
FMENUSDF CF E WORKSTN F RRN KSFILE SCN01B F KINFDS DFINF FMENUSPF IF E K DISK E CM 100100 PREVIOUS CMD'S E CW 100 1 WORK ARRAY E MEN 100 10 PREVIOUS MENUS IDFINF DS I B 378 3790FROP# IDATA01 DS I 1 2 OPT I 1 1 OPT1 I 2 2 OPT2 C Z-ADD1 X 20 RETRIEVE IDX C Z-ADD1 X1 20 RETRIEVE IDX C Z-ADD1 Y 20 MENU INDEX C MOVEL'*' PGMQ PGM QUEUE C *ENTRY PLIST C PARM MNNAME 10 FIRST MENU C MENU KLIST C KFLD MNNAME C KFLD MNOPT# C EXSR FILSBF SETUPSUBFIL C SETON 21 DSPCTL C WRITESCN01C FUNCT KEYS C EXFMTSCN01A SHOWSCREEN * C *IN03 DOWEQ'0' C READ SCN01C 99READ COMMAND C Z-ADDFROP# DSPRSV 40 C *INKI IFEQ '1' C X1 IFGT 1 NOT 1ST REC C SUB 1 X1 C END C MOVELCM,X1 CMD C ELSE C *INKE IFEQ '1' F5=REFRESH C EXSR FILSBF C ELSE C *INKL IFEQ '1' F12=PREVIOUS C Y IFGT 1 NOT 1ST MENU C SUB 1 Y C MOVELMEN,Y MNNAME C EXSR FILSBF C END C ELSE C MOVELCMD WRK5 5 C MOVELCMD OPT C OPT1 IFGT '0' C OPT2 ANDEQ' ' C MOVELOPT1 OPT2 RIGHT ADJUST C MOVEL'0' OPT1 C END C TESTN OPT 50 C *IN50 IFEQ '1' NUMERIC=Y C WRK5 OREQ 'MENU ' C WRK5 IFEQ 'MENU ' C MOVEACMD CW C MOVE *BLANKS CMD C MOVEACW,6 MNNAME C MOVE '01' OPT C END C EXSR MENU# GET OPT# REC C MOVEL*BLANKS CMD COMMAND LN C ELSE C CMD IFGT *BLANKS C MOVELCMD CM,X C ADD 1 X C Z-ADDX X1 20 C END C Z-ADD154 LENGTH 155 LEN COMMAND C *INKD IFEQ '1' PROMPT C MOVE CMD CMD1 155 LEN=155 C MOVEL'?' CMD1 C MOVEL*BLANKS CMD C MOVELCMD1 CMD C END C CALL 'MENUECL' EXECUTE C PARM CMD C PARM LENGTH C MOVEL*BLANKS CMD COMMAND LN C END C END C END C END C *IN03 IFEQ '0' C SETON 21 SFLDSPCTL C Z-ADDDSPRSV DSPREC C WRITESCN01C C EXFMTSCN01A C MOVE *BLANKS CMD C MOVEL'RMVMSG' CMD C CALL 'MENUECL' C PARM CMD C PARM LENGTH C END C END * C SETON LR C****************************************************** C MENU# BEGSR * C****************************************************** C Z-ADD1 DSPREC C MOVELOPT MNOPT# C MNOPT# IFEQ 90 SIGNOFF CMD C SETON 03 C Z-ADD7 LENGTH C MOVEL*BLANKS CMD C MOVEL'SIGNOFF' CMD C CALL 'MENUECL' EXECUTE C PARM CMD C PARM LENGTH C ELSE C MENU CHAINMENUS 99 C WRK5 IFEQ 'MENU ' C MOVELMNNAME MNNEW C END C MNNEW IFNE *BLANKS C MOVELMNNAME MEN,Y C ADD 1 Y C MOVELMNNEW MNNAME C Z-ADD1 DSPRSV C EXSR FILSBF C ELSE C MNCMD IFNE *BLANKS COMMAND C Z-ADD80 LENGTH 155 C CALL 'MENUECL' C PARM MNCMD C PARM LENGTH C ELSE C MNPGM IFNE *BLANKS C CALL MNPGM C END C END C END C END C MOVELSVTITL MNTITL C MOVELSVNAME MNNAME C ENDSR C****************************************************** C FILSBF BEGSR * C****************************************************** C Z-ADD0 RRN 30 C Z-ADD1 DSPREC C SETOF 21 SFLCLR C WRITESCN01A C *LIKE DEFN MNTITL SVTITL SAVETITLE C *LIKE DEFN MNNAME SVNAME SAVENAME C MNNAME SETLLMENUS C Z-ADD0 RRN C RRN DOWLT100 C *IN99 ANDEQ'0' C ADD 1 RRN C MNNAME READEMENUS 99 C *IN99 IFEQ '1' C RRN ANDEQ1 C MOVE '1' *IN03 ENDPROGRAM C ELSE C RRN IFEQ 1 C MOVELMNTITL SVTITL C MOVELMNNAME SVNAME C END C END C *IN99 IFEQ '0' C WRITESCN01B WRITE SUBFL C END C END C MOVELSVTITL MNTITL RESTORETITL C MOVELSVNAME MNNAME RESTORENAME C ENDSR
Creating OS/400-Style Rolling Menus
Figure 4 CL program MENUCL
MENUCL: + PGM PARM(&MENUNM) DCL VAR(&MENUNM) TYPE(*CHAR) LEN(10) CALL PGM(MENUSR1) PARM(&MENUNM) ENDPGM
Creating OS/400-Style Rolling Menus
Figure 5 CL program MENUECL
MENUECL: + PGM PARM(&CMD &LEN) DCL VAR(&CMD) TYPE(*CHAR) LEN(154) DCL VAR(&LEN) TYPE(*DEC) LEN(15 5) DCL VAR(&MSGID) TYPE(*CHAR) LEN(7) DCL VAR(&MSGDTA) TYPE(*CHAR) LEN(100) MONMSG MSGID(CPF0000) EXEC(GOTO CMDLBL(ERROR)) IF COND(&CMD *EQ 'RMVMSG') THEN(DO) RMVMSG PGMQ(*PRV) CLEAR(*ALL) GOTO CMDLBL(ENDPGM) ENDDO CALL PGM(QCMDEXC) PARM(&CMD &LEN) GOTO CMDLBL(ENDPGM) ERROR: + RCVMSG MSGDTA(&MSGDTA) MSGID(&MSGID) SNDPGMMSG MSGID(&MSGID) MSGF(QCPFMSG) MSGDTA(&MSGDTA) ENDPGM: + ENDPGM
Creating OS/400-Style Rolling Menus
Figure 6 Command MENU
CMD PROMPT('Display User-Menus') PARM KWD(MENUNM) TYPE(*CHAR) LEN(10) RSTD(*NO) + MIN(1) PROMPT('Menu Name')
Creating OS/400-Style Rolling Menus
Figure 7 A sample menu file
Figure 7: A Sample Menu File Menu Name Option# Menu Title Description Program Command Name MAIN 01 SAMPLE Print A/R Report AR100 MAIN 02 StartDaily Save SAVECL MAIN 03 Print A/R-Select ?AR100CL MAIN 04 Work Spool File WRKSPF MAIN 05 Work Spool-Select ?WRKSPLF MAIN 06 Go to A/P Menu APMAIN
LATEST COMMENTS
MC Press Online