Here is a method, in your RPG program, to check which function key was used on a screen, without using any indicators.
The usual method is to code your DDS including keywords like CF03(03) and ROLLUP(15), and have your RPG program check the status of indicators 03 and 15. Another method (at least for F1-F24) is to use the KA-KY indicators. Here is a different technique that requires no indicators at all, and can positively check for the Enter key being pressed, instead of assuming that it was pressed because none of the indicators associated with function keys were on. With this technique, you code your DDS for the display file without response indicators: CF03, ROLLUP, and so on.
A workstation file can have an information data structure associated with it (coded with a K-continuation on the F-spec). This data structure contains a byte in position 369 called the Attention Indicator (AID) Byte. After a screen is read, it tells which function key was pressed, including F1-F24, Roll keys, Clear, Help, Home or Enter key. This is in the RPG/400 Reference manual (Chapter 2), and the Data Management Guide (Appendix A).
Using the AID byte is great because it eliminates the need for any indicators, and the Enter key itself can be checked for. The RPG program logic can be set up in a nice CASE structure (or SELECT/WHEN/OTHER). An additional benefit is being able to check for an invalid function key being pressed. That might happen if your DDS accidentally allows a function key, which your RPG program does not expect (maybe you copied DDS source and erroneously included an extra function key).
See 1, Sample RPG Program. You need to code a K-continuation line on your workstation F-spec: KINFDS DSPDS. INFDS is the keyword for information data structure, and DSPDS is the name I chose for my data structure. Create a data structure with that name, and define subfield AID as one-byte long, at position 369. After you have read a screen, call the external program AID2FKEY, shown in 2. The first parameter is the AID byte and the second parameter is an 8-character field that contains the name of the function key. The possible values returned are: F1, F2, ..., F24, ENTER, CLEAR, HELP, ROLLDOWN, ROLLUP, PRINT, HOME, AUTOENT and INVALID.
See Figure 1, Sample RPG Program. You need to code a K-continuation line on your workstation F-spec: KINFDS DSPDS. INFDS is the keyword for information data structure, and DSPDS is the name I chose for my data structure. Create a data structure with that name, and define subfield AID as one-byte long, at position 369. After you have read a screen, call the external program AID2FKEY, shown in Figure 2. The first parameter is the AID byte and the second parameter is an 8-character field that contains the name of the function key. The possible values returned are: F1, F2, ..., F24, ENTER, CLEAR, HELP, ROLLDOWN, ROLLUP, PRINT, HOME, AUTOENT and INVALID.
I suggest using a nice CASE structure (or SELECT/WHEN/OTHERWISE) which includes all allowable function keys, the Enter key, and a catch-all for any invalid keys. If that doesn't fit in well with your existing program structure, just change from testing indicators to testing the return parameter (for example, FKEY IFEQ 'F3').
Editor's Note: Notice how the binary AID byte is converted to decimal in program AID2FKEY. AID is passed as a character parameter, moved to the low order byte (BYTE2) of the two-byte data structure, BINARY. BIN4 now contains the decimal equivalent of the binary byte AID. The key to the technique is the two-byte binary field (BIN4) defined over the two character fields, BYTE1 and BYTE2.
TechTalk: Handling Function Keys in RPG/400
Figure 1 Sample RPG program
Figure 1: Sample RPG Program ....+....1....+....2....+....3....+....4....+....5....+....6....+....7 FDSPFILE CF E WORKSTN F KINFDS DSPDS * IDSPDS DS I 369 369 AID * C EXFMTRECORD * C CALL 'AID2FKEY' C PARM AID C PARM FKEY 8 * C FKEY CASEQ'ENTER' ENTER C FKEY CASEQ'F3' EXIT C FKEY CASEQ'F4' LIST C FKEY CASEQ'F12' CANCEL C FKEY CASEQ'F24' MOREKY C FKEY CASEQ'HELP' HELP C FKEY CASEQ'ROLLUP' ROLLUP C FKEY CASEQ'ROLLDOWN'ROLLDN C CAS INVALD C END ....+....1....+....2....+....3....+....4....+....5....+....6....+....7
TechTalk: Handling Function Keys in RPG/400
Figure 2 RPG program AID2FKEY
Figure 2: Program AID2FKEY ....+....1....+....2....+....3....+....4....+....5....+....6....+....7 E TABKEY 1 32 4 0 TABDSC 8 * IBINARY DS I B 1 20BIN4 I 1 1 BYTE1 I 2 2 BYTE2 * C *ENTRY PLIST C PARM AID 1 C PARM FKEY 8 * C CLEARBIN4 C MOVE AID BYTE2 * C BIN4 LOKUPTABKEY TABDSC 31 C CLEARFKEY C *IN31 IFEQ '1' C MOVELTABDSC FKEY C ELSE C MOVEL'INVALID' FKEY C END * C RETRN ** Table of Function Key Values 0049F1 0050F2 0051F3 0052F4 0053F5 0054F6 0055F7 0056F8 0057F9 0058F10 0059F11 0060F12 0063AUTOENT 0177F13 0178F14 0179F15 0180F16 0181F17 0182F18 0183F19 0184F20 0185F21 0186F22 0187F23 0188F24 0189CLEAR 0241ENTER 0243HELP 0244ROLLDOWN 0245ROLLUP 0246PRINT 0248HOME ....+....1....+....2....+....3....+....4....+....5....+....6....+....7 To compile: CRTRPGPGM PGM(xxx/AID2FKEY) SRCFILE(xxx/QRPGSRC)
LATEST COMMENTS
MC Press Online