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

Better tests for function keys in RPG

Use INFDS in the WORKSTN device to test for the ENTER key.

You Can View User Feedback To This Tip

Traditional methods of testing for function keys in RPG can be bothersome. And how can you test to see if the user pressed ENTER without eliminating ALL other possible function keys? Use the INFDS for the WORKSTN device.

As an RPG programmer, I am always dismayed by the existence of statements that test for function keys using the *INKC format. Sometimes I find myself counting the keys on the keyboard to determine which key is being tested. Since the DDS uses the numeric equivalent (CA03), there is oftentimes no easy way to match them. At least this is true when you go above, let's say, CF10. I also found it disturbing that the only way I could test for the ENTER key was to eliminate all of the other function keys that the user may have pressed. A number of years ago I discovered something in the INFDS for the WORKSTN device that has proven helpful. This is how I have used it.

I created a program that I call SETKEY. I then call this during the initial calcs of a program that uses the WORKSTN device.

Click here to view the program.

USER FEEDBACK TO THIS TIP

  • If you are on V4R4 and up and use RPG4 There is no need to write a program. The idea is base on INZ(*EXTDFT)

    From the IBM site:
    Title: ILE RPG for AS/400 Reference
    Document Number: SC09-2508-02
    Build Date: 03/23/99 17:38:15 Build Version: 1.3.0

    INZ(*EXTDFT) allows you to use the default values in the DDS for initializing externally described data structure subfields.

    Fdem011 cf e workstn infds(infd01)

     * File Information Data Structure                                    
    Dinfd01           ds                                                  
    D FunKey                         1    overlay(infd01:369)  
     * Function keys values to compare with field FunKey              
    D keyaid        e ds                  extname(gedds18) inz(*extdft)
     *                                                                    
    C                   select                   
    C                   when      FunKey = Enter
     * Some code
    C                   when      FunKey = fk03  
     * Some code
    C                   when      FunKey = fk12  
     * Some code
    C                   endsl     
     
     
     The source for file GEDDS18
    
                     R GEDDS18R
     
                       FK01           1          COLHDG('F01' 'key')
                                                 DFT(X'31')
                       FK02           1          COLHDG('F02' 'key')
                                                 DFT(X'32')
                       FK03           1          COLHDG('F03' 'key')
                                                 DFT(X'33')
                       FK04           1          COLHDG('F04' 'key')
                                                 DFT(X'34')
                       FK05           1          COLHDG('F05' 'key')
                                                 DFT(X'35')
                       FK06           1          COLHDG('F06' 'key')
                                                 DFT(X'36')
                       FK07           1          COLHDG('F07' 'key')
                                                 DFT(X'37')
                       FK08           1          COLHDG('F08' 'key')
                                                 DFT(X'38')
                       FK09           1          COLHDG('F09' 'key')
                                                 DFT(X'39')
                       FK10           1          COLHDG('F10' 'key')
                                                 DFT(X'3A')
                       FK11           1          COLHDG('F11' 'key')
                                                 DFT(X'3B')
                       FK12           1          COLHDG('F12' 'key')
                                                 DFT(X'3C')
     
                       FK13           1          COLHDG('F13' 'key')
                                                 DFT(X'B1')
                       FK14           1          COLHDG('F14' 'key')
                                                 DFT(X'B2')
                       FK15           1          COLHDG('F15' 'key')
                                                 DFT(X'B3')
                       FK16           1          COLHDG('F16' 'key')
                                                 DFT(X'B4')
                       FK17           1          COLHDG('F17' 'key')
                                                 DFT(X'B5')
                       FK18           1          COLHDG('F18' 'key')
                                                 DFT(X'B6')
                       FK19           1          COLHDG('F19' 'key')
                                                 DFT(X'B7')
                       FK20           1          COLHDG('F20' 'key')
                                                 DFT(X'B8')
                       FK21           1          COLHDG('F21' 'key')
                                                 DFT(X'B9')
                       FK22           1          COLHDG('F22' 'key')
                                                 DFT(X'BA')
                       FK23           1          COLHDG('F23' 'key')
                                                 DFT(X'BB')
                       FK24           1          COLHDG('F24' 'key')
                                                 DFT(X'BC')
     
                       CLEAR          1          COLHDG('Clear' 'key')
                                                 DFT(X'BD')
     
                       ENTER          1          COLHDG('Enter' 'key')
                                                 DFT(X'F1')
                       HELP           1          COLHDG('Help'  'key')
                                                 DFT(X'F3')
                       PAGEUP         1          COLHDG('Page'  'up')
                                                 DFT(X'F4')
                       PAGEDN         1          COLHDG('Page'  'down')
                                                 DFT(X'F5')
                       PRINT          1          COLHDG('Print' 'key')
                                                 DFT(X'F6')
                       HOME           1          COLHDG('Home'  'key')
                                                 DFT(X'F8')
     
    
    — Eitan Rosenberg
  • I don't really see the trouble with checking if the user presses the ENTER key or function key as in the DSPF, only the function keys you have defined will be allowed by the display file. In other words, your program will just have to check for the function keys specified in your display file. You do not have to count(ie *INKC is Function F3), you can assign 03 under the Response column of the Indicator keywords screen for your display file. Function Resp CA03 03 In your program you just use *IN03 instead. —Alex Lee
  • ==================================
    MORE INFORMATION ON THIS TOPIC
    ==================================

    The Best Web Links: tips, tutorials and more.

    Ask your programming questions--or help out your peers by answering them--in our live discussion forums.

    Ask the Experts yourself: Our application development gurus are waiting to answer your programming questions.


Dig Deeper on iSeries CL programming

Start the conversation

Send me notifications when other members comment.

Please create a username to comment.

-ADS BY GOOGLE

SearchDataCenter

Close