CL Programming

Writing a CL Program to Control a Menu

The following example shows how a CL procedure can be written to display and control a menu. See the Application Display Programming Link to PDF book for another method of creating and controlling menus.

This example shows a CL procedure, ORD040C, that controls the displaying of the order department general menu and determines which HLL procedure to call based on the option selected from the menu. The procedure shows the menu at the display station.

The order department general menu looks like this:

+--------------------------------------------------------------------------------+
| Order Dept General Menu                                                        |
|                                                                                |
|  1 Inquire into customer file                                                  |
|  2 Inquire into item file                                                      |
|  3 Customer name search                                                        |
|  4 Inquire into orders for a customer                                          |
|  5 Inquire into an existing order                                              |
|  6 Order entry                                                                 |
| 98 End of menu                                                                 |
|                                                                                |
|Option:                                                                         |
|                                                                                |
|                                                                                |
|                                                                                |
|                                                                                |
|                                                                                |
|                                                                                |
|                                                                                |
|                                                                                |
|                                                                                |
|                                                                                |
|                                                                                |
|                                                                                |
|                                                                                |
+--------------------------------------------------------------------------------+

The DDS for the display file ORD040C looks like this:


|...+....1....+....2....+....3....+....4....+....5....+....6....+....7....+....8
     A* MENU ORDO4OCD ORDER DEPT GENERAL MENU
     A
     A          R MENU                      TEXT('General Menu')
     A                                  1  2'Order Dept General Menu'
     A                                  3  3'1 Inquire into customer file'
     A                                  4  3'2 Inquire into item file'
     A                                  5  3'3 Customer name search'
     A                                  6  3'4 Inquire into orders for a custom+
     A                                      er'
     A                                  7  3'5 Inquire into existing order'
     A                                  8  3'6 Order Entry'
     A                                  9  2'98 End of menu'
     A                                 11  2'Option'
     A            RESP           2Y001 11 10VALUES(1 2 3 4 5 6 98)
     A                                      DSPATR(MDT)
     A
     A

The source procedure for ORD040C looks like this:

       PGM /* ORD040C Order Dept General Menu */
       DCLF FILE(ORD040CD)
START: SNDRCVF RCDFMT(MENU)
       IF (&RESP=1) THEN(CALLPRC CUS210)
       /* Customer inquiry */
       ELSE +
         IF (&RESP=2) THEN(CALLPRC ITM210)
         /*Item inquiry*/
         ELSE +
           IF (&RESP=3) THEN(CALLPRC CUS220)
           /* Cust name search */
           ELSE +
             IF (&RESP=4) THEN(CALLPRC ORD215)
             /* Orders by cust */
             ELSE +
               IF (&RESP=5) THEN(CALLPRC ORD220)
               /* Existing order */
               ELSE +
                 IF (&RESP=6) THEN(CALLPRC ORD410C)
                 /* Order entry */
                 ELSE +
                   IF (&RESP=98) THEN(RETURN)
                   /* End of Menu */
       GOTO START
       ENDPGM

The DCLF command indicates which file contains the field attributes the system needs to format the order department general menu when the SNDRCVF command is processed. The system automatically declares a variable for each field in the record format in the specified file if that record format is used in an SNDF, RCVF, or SNDRCVF command. The variable name for each field automatically declared is an ampersand (&) followed by the field name. For example, the variable name of the response field RESP in ORD040C is &RESP.

Other notes on the operation of this menu:

The SNDRCVF command is used to send the menu to the display and to receive the option selected from the display.
If the option selected from the menu is 98, ORD040C returns to the procedure that called it.
The ELSE statements are necessary to process the responses as mutually exclusive alternatives.
Note:
This menu is run using the CALL command. See the Application Display Programming Link to PDF book for a discussion of those menus run using the GO command.


[ Top of Page | Previous Page | Next Page | Table of Contents | Index ]