ILE RPG : Track ENTER key


In RPG, how can we track if user pressed any of function key (F01 to F24) on screen ? Of course, by using CA/CF indicators. But how we can check if user pressed enter key on screen?

To track enter key we need to use a simple trick involving File information data structure(INFDS) and a hexadecimal value.


 *  File information Data structure
D FileInfo        DS
D KeyPressed            369    369

 *  Constant
D EnterKey        C                   CONST(x'F1')

1. We declared a display file SFLXXXXXD with INFDS points to the FileInfo data structure.
2. AS400 updates Position from 369 to 369 in INFDS with Hexadecimal value corresponding to the Key pressed on screen.
3. We declared a constant “EnterKey” with hexadecimal value x’F1′.( x for hexadecimal).

So every time user presses Enter key on screen. AS400 system updates variable KeyPressed (in FileInfo DS) with hexadecimal value of x’F1′. Now, we can compare EnterKey constant with Keypressed variable :

Select ;
    When KeyPressed = EnterKey;
         ExSr ValidateData;

Using this way, you can track almost all keys including function keys. Here is list of Hexadecimal values for different keys.

     D F1              C                   CONST(X'31')
     D F2              C                   CONST(X'32')
     D F3              C                   CONST(X'33')
     D F4              C                   CONST(X'34')
     D F5              C                   CONST(X'35')
     D F6              C                   CONST(X'36')
     D F7              C                   CONST(X'37')
     D F8              C                   CONST(X'38')
     D F9              C                   CONST(X'39')
     D F10             C                   CONST(X'3A')
     D F11             C                   CONST(X'3B')
     D F12             C                   CONST(X'3C')
     D F13             C                   CONST(X'B1')
     D F14             C                   CONST(X'B2')
     D F15             C                   CONST(X'B3')
     D F16             C                   CONST(X'B4')
     D F17             C                   CONST(X'B5')
     D F18             C                   CONST(X'B6')
     D F19             C                   CONST(X'B7')
     D F20             C                   CONST(X'B8')
     D F21             C                   CONST(X'B9')
     D F22             C                   CONST(X'BA')
     D F23             C                   CONST(X'BB')
     D F24             C                   CONST(X'BC')
      * Page Down/Roll Up                              
     D RollUp          C                   CONST(X'F5')
     D PageDown        C                   CONST(X'F5')
      * Page Up/Roll Down                              
     D RollDown        C                   CONST(X'F4')
     D PageUp          C                   CONST(X'F4')
      * Enter                                          
     D Enter           C                   CONST(X'F1')
     D Help            C                   CONST(X'F3')
     D Print           C                   CONST(X'F6')

Any question drop a mail to

Leave a Reply

Your email address will not be published. Required fields are marked *