Problem solve Get help with specific problems with your technologies, process and projects.

One function key for multiple look-ups member Bill Cressy shows you how you can use only one "F-Key" to perform all look-up functions on a screen.

When building application entry screens, a user often has to enter codes or values that can be "looked up" from files and tables. You can buy a commercial utility to do that, but sometimes you just have to code your own look-up functions.

More Information

In the past, I have seen applications in which each field that required a look-up function had an "F-Key" that performed that specific look-up for the field. A screen may have four or five "F-Keys" performing look-up functions. Rather than do that, I'm going to show you how to use only one "F-Key" to perform all look-up functions on a screen.

When building the display file, you will need to add several lines of code that will contain fields whose values will be returned to the program when your defined "F-Key" is pressed. Below is the code sample for the DDS file.

     A          R EXAMPLE01                                                                                 
     A                                      CA03                                                            
     A                                      CF04                                                            
     A                                      RTNCSRLOC(&REC &FLD &POS)                                       
     A            REC           10A  H                                                                      
     A            FLD           10A  H                                                                      
     A            POS            4S 0H                                                                      
     A                                  1  2'EXAMPLE01'                                                    
     A                                  1 72DATE                                                            
     A                                      EDTCDE(Y)                                                       
     A                                  4  2'Enter the One of the Following:'                               
     A                                  5  2'Field One      :'                                      
     A            field1        10A  B  5 20                                                                
     A                                  5  2'Field Two      :'                                      
     A            field2         3A  B  6 20                                               
     A                                  5  2'Field Three    :'                                      
     A            field3         3A  B  7 20                                                                
     A                                  5  2'Field Four     :'                                      
     A            field4         7S 0B  8 20                                               
     A                                 24  2'F3=Exit'                                                           
     A                                 24 11'F4=Look-Up'
     A                                 24 52'ENTER=Validate Info'                                         

Now that the display file has been defined, we will look at the RPG code to process the "F4" request. Be gentle and considerate. I am an "old" RPG programmer, and the code sample below is pretty antique. You may use subprocedures, subroutines or just code within the select statement. The purpose of the examples is to stimulate your thought process to make a simple programming technique your own.

     C     CONT          DOWEQ     'Y'                                                                      
     C                   EXFMT     EXAMPLE01                                                               
     C                   MOVEA     '000000000'   *IN(30)                                                    
     C                   SELECT
      *  F3-EXIT REQUESTED                                                                                  
     C     *INKC         WHENEQ    *ON                                                                      
     C                   MOVEL     'N'           CONT                                    
      *  F4-Prompt for Look-Up                                                            
     C     *INKD         WHENEQ    *ON                                                                      
     C                   SELECT
     C     FLD           WHENEQ    'field1    '                                                    
     C                   CALL      'GETCUST'                                                                
     C                   PARM                    GetCustPrm                                                 
     C     FLD           WHENEQ    'field2    '                                                    
     C                   CALLP     'GETPRD#'                                                                
     C                   PARM                    GetPrdPrm                                                 
     C     FLD           WHENEQ    'field1    '                                                    
     C                   EXSR      'SomeSub1'                                                                
     C                   ENDSL
     C                   ENDSL
     C                   ENDDO

Other processing will be done here -- perform your validation, file chains to retrieve additional values and anything else that is required.

There are many other tricks that can be done with the RTNCSRLOC function from within display files. This was only one simple example. Download the IBM Redbook regarding DDS files, and it will teach you what you need to know about becoming more proficient with display files.

About the author: Bill Cressy is the Manager of Information Technology for Prince Agri Products Inc. He has been programming on S/38, AS/400 and iSeries machines since 1986.

Dig Deeper on iSeries CL programming

Start the conversation

Send me notifications when other members comment.

Please create a username to comment.