DSPF Function Keys and the Hex AID Byte from the INFDS

IBM i

Jul 06

THE AID BYTE IS A SINGLE CHARACTER FIELD THAT CONTAINS A HEX CODE THAT WILL TELL YOU EXACTLY WHAT THE USER PRESSED ON THE SCREEN – IE: ENTER OR PF3 OR PF12 OR ‘WHATEVER’

The File Information Data Structure is has all kinds of very cool information stored in it. It makes any programmers life easier if coding a *DSPF style program. Even a basic understanding of some core *INFDS values (File Information Data Structure) will help any RPG Programmer.

One nice little feature of the *INFDS is the AID byte. This byte occupies the 369th position of the INFDS and is 1 character in length. It stores the hexadecimal value of the most recent key pressed – any key that feeds input back to the program.

So how do we use this AID byte in our RPG Program?

Declare the INFDS and define the AID byte with a variable name (say ‘FKEY’). Declare all the hexadecimal values of the function keys and the field-exit keys as standalone fields in the D-spec initializing with the hex value. Then in our program, we can check for the function key that was pressed, simply check ‘If Fkey = F10’ where Fkey is the AID Byte variable and F10 is the variable that stores the hexadecimal value of the F10 function key.

Sample code that can be used as a copybook:

D DSPFINFDS      DS
D Dspflags              367    368
D Fkey                           1
D Cursrloc                       2
D Datalen                        9B 0
D Sfrelrec                       4B 0
D Sfminrrn                       4B 0
D Sfnbrrec                       4B 0
D Wincsrlc                       2
D Majorcod              401    402
D Minorcod                       2
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’)
D  Clear          C                   CONST(X’BD’)
D  Enter          C                   CONST(X’F1′)
D  Help           C                   CONST(X’F3′)
D  Rolldown       C                   CONST(X’F4′)
D  Rollup         C                   CONST(X’F5′)
D  Print          C                   CONST(X’F6′)
D  Recd_Bksp      C                   CONST(X’F8′)
D  Auto_Enter     C                   CONST(X’3F’)

Or, we can modernize this code and show it in RPGLE /FREE 🙂  It would look like this:

 dcl-ds DSPFINFDS; 
 Dspflags char(2) pos(367);  
 Fkey char(1); 
 Cursrloc char(2); 
 Datalen bindec(9); 
 Sfrelrec bindec(4); 
 Sfminrrn bindec(4); 
 Sfnbrrec bindec(4); 
 Wincsrlc char(2); 
 Majorcod char(2) pos(401); 
 Minorcod char(2); 
 end-ds; 
 
 dcl-c F1 x'31'; 
 dcl-c F2 x'32'; 
 dcl-c F3 x'33'; 
 dcl-c F4 x'34'; 
 dcl-c F5 x'35'; 
 dcl-c F6 x'36'; 
 dcl-c F7 x'37'; 
 dcl-c F8 x'38'; 
 dcl-c F9 x'39'; 
 dcl-c F10 x'3A'; 
 dcl-c F11 x'3B'; 
 dcl-c F12 x'3C'; 
 dcl-c F13 x'B1'; 
 dcl-c F14 x'B2'; 
 dcl-c F15 x'B3'; 
 dcl-c F16 x'B4'; 
 dcl-c F17 x'B5'; 
 dcl-c F18 x'B6'; 
 dcl-c F19 x'B7'; 
 dcl-c F20 x'B8'; 
 dcl-c F21 x'B9'; 
 dcl-c F22 x'BA'; 
 dcl-c F23 x'BB'; 
 dcl-c F24 x'BC'; 
 dcl-c Clear x'BD'; 
 dcl-c Enter x'F1'; 
 dcl-c Help x'F3'; 
 dcl-c Rolldown x'F4'; 
 dcl-c Rollup x'F5'; 
 dcl-c Print x'F6'; 
 dcl-c Recd_Bksp x'F8'; 
 dcl-c Auto_Enter x'3F'; 

/me loves being /free

 

Follow

About the Author

IBM i Software Developer, Digital Dad, AS400 Anarchist, RPG Modernizer, Alpha Nerd and Passionate Eater of Cheese and Biscuits. Nick Litten Dot Com is a mixture of blog posts that can be sometimes serious, frequently playful and probably down-right pointless all in the space of a day. Enjoy your stay, feel free to comment and in the words of the most interesting man in the world: Stay thirsty my friend.