User login

Process a display file in a CL program

OK, We have learned several things on RPG, Now we will explore few CL related concepts. We begin with processing a display file in a CL program. Here, We first learn the basic steps which are required to process a display file then we see a simple example which actually processes the display file.

Steps to process a display file in a CL program.
To process a display file in a CL program we should follow the following steps.

  1. Declare the display file using the DCLF command.
  2. Create a loop such that the program ends when the exit key has been pressed.
  3. ExFmt the required format using the SNDRCVF command.
  4. Process the user input.

Limitations of processing a display file in CL command.
Maximum one display file can be declared (and hence processed) at a time.

Important point to remember
All display file fields become available to the CL program. You just have to add an ampersand '&' before them. Even the indicators become available.

Example to process an AS400 display file in a CL program.
The layout of the DDS is given below.

 
Sum Of Two Numbers                                                             
                                                                                
                                                                                
 Enter two Numbers and Press Enter to get their sum.                            
                                                                                
 Enter First Number : 9999999999-                                               
 Enter Second Number: 9999999999-                                               
                                                                                
                      -----------                                               
                Sum = 66666666666                                               
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
 F1=Exit                                                                        

The DDS source
The source code of the display file has been given below. Only point to remember here is that the function key must be defined in a similar way as given below. Otherwise the CL program won't compile. It will say something like “variable &IN01 is referred to but not declared”. You may add a text after 01 though.


AAN01N02N03T.Name++++++RLen++TDpBLinPosFunctions+++++++++++++++++++++++
*************** Beginning of data *************************************
A                                      DSPSIZ(24 80 *DS3)              
A          R LOG02                                                     
 ** FUNCTION KEY DEFINED                                               
A                                      CF01(01)                        
 ** SCREEN FIELDS AND LABELS                                           
A                                  5  2'Enter two Numbers and Press Ent
A                                      to get their sum.'              
A                                  7  2'Enter First Number :'          
A            $NUM1         10  0B  7 23                                
A                                  8  2'Enter Second Number:'          
A            $NUM2         10  0B  8 23                                
A                                 10 23'-----------'                   
A                                 11 17'Sum ='                         
A            $SUM          11  0O 11 23COLOR(WHT)                      
A                                 23  2'F1=Exit'                       
A                                      COLOR(BLU)                      
A                                  2  2'Sum Of Two Numbers'            
A                                      COLOR(WHT)                      
A                                      DSPATR(UL)                                                                                                      

The CL program's source to process the display file
The source code of the CL program is now given below. This source has been used for example purpose only. I would recommend you not to use the GOTO statements used here. Also, if your display file has more than several function keys defined, go for the select when clause instead of If do endo.


             PGM                                                  
                                                                  
/* Declare display file. We may declare specific record format */ 
             DCLF       FILE(LOGDSPF)                             
                                                                  
/* SNDRCVF is similar to RPG's ExFmt. Rcd Fmt name is optional for single record format display file.*/                          
 DISPLAY:    SNDRCVF    RCDFMT(LOG02)                             
                                                                  
/* Notice that CF01 becomes &IN01, $SUM &$SUM etc. */             
             IF         COND(&IN01 *EQ '1') THEN(DO)              
             GOTO       CMDLBL(EXIT)                              
             ENDDO                                                
             CHGVAR     VAR(&$SUM) VALUE(&$num1 + &$num2)         
             GOTO       CMDLBL(DISPLAY)                           
 EXIT:       ENDPGM                                               
The above program when run, display the screen with two input and one output numeric fields. The program ends when F1 key is pressed, other wise it sums up the two input numbers and displays the sum as the output field.

There are few other CL commands like SNDF, RCVF, ENDRCV and WAIT. I hope to explore these commands in coming days.

Recent comments