Menus are important. Imagine, for a minute, what the AS/400 would be like if, after signing on, you got nothing but a blank screen or a C:> prompt. Sure, once you get the hang of it and learn what commands are available, you can get around without menus. But the overwhelming majority of AS/400 users dont have enough room left in their skulls to memorize the dozens upon dozens of commands they would need to use every day.
But IBM is not the only one that can create menus. You can design and create them, too, and you have a choice of several ways to go about it:
Create a display file and a program to drive it. These menus have the advantage of letting you have absolute control over design, although that may lead to lack of standardization.
Create a menu through SDA. SDA-created menus are limited to a single screen, but at least, the design of the menu panel is of an enforced standard.
Create a menu using UIM (User Interface Manager). UIM menus are, by far, the most versatile and function-rich. You can define what each function key does and automatically provide for F4=Prompt and F9=Retrieve (without going into their sordid details). UIM menus can also roll. In fact, UIM menus can have up to 999 options. The downside of these menus is UIMs incredibly cumbersome syntax.
Introducing CRTUIMMNU
As I implied above, UIM menus are the way to create AS/400 menus. Unfortunately, you have to write a couple dozen lines of cryptic UIM code before you even get to describe the first menu option, and describing each option is complicated enough.
In this article, I present the Create UIM Menu (CRTUIMMNU) command, which, as its name implies, creates a menu from a much simplified version of the source code using a syntax that even a chimpanzee can understand. For instance, suppose you want to create a menu named PROGRAMMER and you want it to have the following options:
Display Messages (DSPMSG)
Work with Submitted Jobs (WRKSBMJOB)
Work with Spooled Files (WRKSPLF)
UIM requires dozens of lines of incredible gibberish to build the menu. CRTUIMMNU builds the same menu from the source member in Figure 1. Just run the following command:
CRTUIMMNU MENU(QGPL/PROGRAMMER) +
SRCFILE(library/file)
Thats it! CRTUIMMNU creates menu PROGRAMMER in library QGPL, picking up the source code from the file of your choice. It assumes that the source member name will be the same as the menu name unless you override it.
Analyzing the Source
Take a moment to learn the simple syntax that Ive invented. First, you do not have to write any preamble; CRTUIMMNU takes the menu title, its top instruction line (Select one of the following), and the copyright text from the command itself. You cant see any of it in the example, because there are default values for all those options. You need only write the specs for each menu option.
Each menu option requires three lines. The first line, prefixed with a pound symbol (#), provides the option number to be assigned. You can assign option numbers or have CRTUIMMNU assign them for you. The second line starts with a greater-than symbol (>), indicating which command is to be executed when the user selects the option. You can specify up to 60 characters in this command string. The third and last line, prefixed with an asterisk (*), provides the description of the option as it should appear on the menu panel. My choice of #, >, and * has a mnemonic justification. After all, # means number. The > symbol is part of DOSs C:> prompt and also the rightmost character of the arrow that appears to the left of the command line on OS/400 menus, so > suggests command. And * is the symbol that RPG uses for comments, so its used here to comment (describe) each menu option.
Note that the last option has a question mark (?) before the command name. The question mark is the standard means by which OS/400 invokes the command prompter. If the user selects option 3, the Work with Spooled Files (WRKSPLF) command wont be executed but will be prompted just as if the user had typed WRKSPLF at the command line and pressed F4.
You dont have to provide option numbers. CRTUIMMNU assigns those automatically, beginning with 1 and continues to increment by 1 for each additional option. Also, if you leave source lines that are almost empty (they contain only the > and * prefixes), there will be a gap in the menu and the option numbers will skip the number that would have been assigned.
If you want to assign option numbers, type a three-digit number (from 001 to 999) immediately after the # on the first of each three-line group. (Make sure you type all three digits!) If the option that follows has no number assigned, CRTUIMMNU continues automatically incrementing 1.
You can also group menu options. For example, the first two options of a menu may perform related tasks. In that case, the menu would look better if it had some kind of subtitle before those two options and the options were separated from the options that follow. To group options, write an additional line before the group and another line after the group. The line before the group must begin with a B (begin group) and contain additional text immediately after that (which is then used as the subtitle for the group). The line after the group must begin with an E and contain nothing else.
Consider the example in Figure 2, which produces a menu containing the following segment:
Message Management
41. Display messages
42. Send a message
If you wish to display another menu when the user selects an option (this process is called chaining menus), code the GO command. For example, if you want to add an option to display the AS/400 main menu, you can add the following three lines to the source member:
>GO MAIN *NO
*AS/400 main menu
The *NO that follows the menu name means that the menu being created should not be considered a return point. Consequently, if the user presses F3 from the MAIN menu, OS/400 goes all the way back to the point before the menu appeared. Similarly, you can execute programs from within menus by coding the CALL command.
A Brief Description of CRTUIMMNU
Take a look at CRTUIMMNUs parameters in full detail:
MENU (Name of menu). Enter the name of the menu you want to create, qualified with a library name. This parameter is required.
SRCFILE (Name of source file). Enter the name of the source file containing the member in which youve written the source code. You can qualify the name with a library. If you dont, the library name defaults to *MENULIB, which means that the source file is assumed to be in the same library indicated in the MENU parameter.
SRCMBR (Source member). Enter the name of the source member containing the source code. If you dont, it defaults to *MENU, which means that the source member is expected to have the same name as the menu being created.
TEXT (Text description). Enter up to 50 characters to describe the menu. This description is stored in the menu object itself, as are text descriptions of any other object types. If not given, it defaults to the text description of the source member (*SRCMBRTXT).
TITLE (Menu title). Enter up to 50 characters that should appear as the title of the menu (centered on line 1, in high intensity). If not given, it defaults to the text description of the source member.
TOPINST (Top instructions). Type up to 50 characters of instructions to appear in blue on line 3 of the menu. The default value, *STD, will display Select one of the following: on that line.
CMDLINE (Command line). Select *LONG, *SHORT, or *NONE. *LONG is the default and includes a command line that extends two physical screen lines. *SHORT is just one line long. *NONE shows the menu without a command line, giving you a four- position input field for an option number.
COPYRIGHT (Copyright notice). Type up to 50 characters to appear on line 24 of the menu the first time the menu is invoked. If you prefer not to have any copyright notice, the default is *NONE.
PRDLIB (Product library). Type the name of a library that will automatically be placed in the library list as the product library when the user invokes the menu. When the user leaves the menu, OS/400 automatically restores the product library to what it was before the menu appeared. By default (*NOCHG), there will be no change in the product library.
CURLIB (Current library). This is the same as for the PRDLIB parameter but applies to the current library instead of the product library.
CRTUIMMNU takes the source code you have written and writes the real UIM source in a temporary source file created in QTEMP. Then, it runs the standard Create Menu (CRTMNU) command using that source in QTEMP. Figure 3 contains simplified
menu source code containing the features Ive described. Figure 4 shows the UIM source code generated in the temporary file.
CRTUIMMNU, therefore, is a preprocessor for menu source code. It doesnt have much intelligence, but it gets the job done. If you fail to write the source code as indicated above, CRTUIMMNU will tell you on which line it found the error but wont tell you what it is. For instance, if you write an > line but follow it with another > line (instead of the correct * line), CRTUIMMNU triggers a terse *ESCAPE message that identifies, by sequence number, the source line in which it discovered the error.
Bonus: CRTOBJMNU
If you think CRTUIMMNU is kewl, Create Objects Menu (CRTOBJMNU) takes CRTUIMMNUs automation one step beyond. CRTOBJMNU creates a single menu for a group of (or all) commands or programs in a library. For example, suppose you have a utilities library named UTILITY and you want to create a menu of all commands that begin with the letters PRT. You dont need to write a single line of source code. Just run the following command:
CRTOBJMNU OBJ(UTILITY/PRT*) +
OBJTYPE(*CMD) +
MENU(UTILITY/PRINT)
That command creates a menu in which theres one option per command, found in UTILITY, that begins with the letters PRT. The menu it creates is named PRINT and is placed in UTILITY. When you subsequently enter the menu (GO PRINT), youll see that, automatically, all PRT* commands are there listed in alphabetic sequence, in a neat listing showing option numbers, the command name, and the command text description (taken from the *CMD object itself).
No More Drudgery
You can download the source code from Midrange Computings Web site at www.midrangecomputing.com/mc/99/08. To install the two utilities presented in this article, you must first install the Forward Program Messages (FWDPGMMSG) utility command if necessary. (See How to Forward Messages in CL, MC, January 1998). Then, use the code in Figure 5 to create the objects.
CRTUIMMNU and CRTOBJMNU remove the drudgery of maintaining menus. I think youll like these menu utilities. Ive been using them myself for a few months and would not consider going back to the old ways.
Reference
How to Forward Messages in CL, Ernie Malaga, MC, January 1999
#
>DSPMSG
*Display Messages (DSPMSG)
#
>WRKSBMJOB
*Work with Submitted Jobs (WRKSBMJOB)
#
>?WRKSPLF
*Work with Spooled Files (WRKSPLF)
Figure 1: CRTUIMMNU generates a UIM menu from this simple source code.
BMessage Management
#041
>DSPMSG
*Display messages
#
>?SNDMSG
*Send a message
E
Figure 2: Menu options may be organized into groups.
BPrograms
#
>CALL CASH430CL
*Enter cash receipts
#
>CALL BILL202CL
*Enter miscellaneous charges
#
>CALL ARINQ33CL
*Accounts receivable inquiry
E
BMessage commands
#011
>DSPMSG
*Display your messages
#
>?SNDMSG
*Send a message
E
BReports
#051
>WRKSPLF
*Work with your spool files
#
>WRKOUTQ PRT01
*Work with outq PRT01
E
BMiscellaneous
#090
>SIGNOFF
*Signoff
E
Figure 3: This simplified source code generates a complex UIM menu complete with groups of options.
:PNLGRP.
:VAR NAME=ZMENU.
:KEYL NAME=MENUKEYS HELP=X.
:KEYI KEY=F1 HELP=X ACTION=HELP.
:KEYI KEY=F3 HELP=X ACTION='EXIT SET' VARUPD=NO.
F3=Exit
:KEYI KEY=F4 HELP=X ACTION=PROMPT.
F4=Prompt
:KEYI KEY=F9 HELP=X ACTION=RETRIEVE.
F9=Retrieve
:KEYI KEY=F12 HELP=X ACTION='CANCEL SET' VARUPD=NO.
F12=Cancel
:KEYI KEY=ENTER HELP=X ACTION=ENTER.
:KEYI KEY=HELP HELP=X ACTION=HELP.
:KEYI KEY=PAGEDOWN HELP=X ACTION=PAGEDOWN.
:KEYI KEY=PAGEUP HELP=X ACTION=PAGEUP.
:KEYI KEY=PRINT HELP=X ACTION=PRINT.
:EKEYL.
:PANEL NAME=MYMENU
HELP=X KEYL=MENUKEYS
ENTER='MSG CPD9817 QCPFMSG'
PANELID=ZMENU TOPSEP=SYSNAM.
Test CRTUIMMNU Command
:MENU DEPTH='*' SCROLL=YES BOTSEP=SPACE.
:TOPINST.Select one of the following:
:MENUGRP.
Programs
:MENUI OPTION=001
ACTION='CMD CALL CASH430CL'
HELP=X.
Enter cash receipts
:MENUI OPTION=002
ACTION='CMD CALL BILL202CL'
HELP=X.
Enter miscellaneous charges
:MENUI OPTION=003
ACTION='CMD CALL ARINQ33CL'
HELP=X.
Accounts receivable inquiry
:EMENUGRP.
:MENUGRP.
Message commands
:MENUI OPTION=011
ACTION='CMD DSPMSG'
HELP=X.
Display your messages
:MENUI OPTION=012
ACTION='CMD ?SNDMSG'
HELP=X.
Send a message
:EMENUGRP.
:MENUGRP.
Reports
:MENUI OPTION=051
ACTION='CMD WRKSPLF'
HELP=X.
Work with your spool files
:MENUI OPTION=052
ACTION='CMD WRKOUTQ PRT01'
HELP=X.
Work with outq PRT01
:EMENUGRP.
:MENUGRP.
Miscellaneous
:MENUI OPTION=090
ACTION='CMD SIGNOFF'
HELP=X.
Signoff
:EMENUGRP.
:EMENU.
:CMDLINE SIZE=LONG.
Selection or command
:EPANEL.
:HELP NAME=X.
No help available.
:EHELP.
:EPNLGRP.
Figure 4: The simplified code in Figure 3 generates this UIM source.
CRTCMD CMD(xxx/CRTUIMMNU) PGM(xxx/CRTUIMMNUC) SRCFILE(xxx/QCMDSRC)
CRTCMD CMD(xxx/CRTOBJMNU) PGM(xxx/CRTOBJMNUC) SRCFILE(xxx/QCMDSRC)
CRTCLPGM PGM(xxx/CRTUIMMNUC) SRCFILE(xxx/QCLSRC)
CRTCLPGM PGM(xxx/CRTOBJMNUC) SRCFILE(xxx/QCLSRC)
CRTBNDRPG PGM(xxx/CRTUIMMNUR) SRCFILE(xxx/QRPGLESRC) +
DFTACTGRP(*NO) ACTGRP(*CALLER)
CRTBNDRPG PGM(xxx/CRTOBJMNUR) SRCFILE(xxx/QRPGLESRC) +
DFTACTGRP(*NO) ACTGRP(*CALLER)
Figure 5: These commands create objects for the CRTUIMMNU and CRTOBJMNU utilities.
LATEST COMMENTS
MC Press Online