Write a CL program to control a menu

This example shows how a CL procedure can be written to display and control a menu.

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)                                           
       SELECT                                                         
         WHEN (&RESP=1) THEN(CALLPRC CUS210)  /* Customer inquiry */  
         WHEN (&RESP=2) THEN(CALLPRC ITM210)  /* Item inquiry     */  
         WHEN (&RESP=3) THEN(CALLPRC CUS220)  /* Cust name search */  
         WHEN (&RESP=4) THEN(CALLPRC ORD215)  /* Orders by cust   */  
         WHEN (&RESP=5) THEN(CALLPRC ORD220)  /* Existing order   */  
         WHEN (&RESP=6) THEN(CALLPRC ORD410C) /* Order entry      */  
         WHEN (&RESP=98) THEN(RETURN)         /* End of Menu      */  
       ENDSELECT                                                      
       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 Send/Receive File (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 Send File (SNDF), Receive File (RCVF), or Send/Receive File (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:

Note: This menu is run using the Call (CALL) command. See the Application Display Programming book for a discussion of those menus run using the Go (GO) command.
Related information
Send File (SNDF) command
Receive File (RCVF) command
Send/Receive File (SNDRCVF) command
Application Display Programming