(Author's Note: This week's article is an excerpt from my upcoming book RPG TNT: 101 Dynamite Tips and Techniques for RPG IV Programmers.)
For decades, programmers have used response indicators to signal the Command or Function key pressed by a user. The program with this approach is that it uses an indicator and the indicator gives no indication of which key was actually pressed.
For just as long as there have been interactive programs, there has been the File Information Data Structure, or INFDS. The INFDS is assigned to files in RPG and contains information about the status of the file. For display files, the INFDS is often referred to as the Workstation Data Structure, or WSDS.
Whenever a display file record is returned to the RPG program, the WSDS is updated. Within the WSDS, in position 369. . Each function key (as well as the other entry keys, such as Enter, Help, Home, Print, PageUp, PageDown, etc.) returns a unique scan code that identifies the key used to return control to the program.
No response indicators are assigned to the key in the DDS when this technique is used. Only the function key needs to be specified. Of course, if the response indicator is already there, you may certainly ignore it and everything will work fine. Position 369 of the WSDS is always updated, regardless of the use of response indicators in the DDS. Here's an example:
A CA03 CF12
A CF04
A CF05
A R CUSTMAINT CLRL(*NO)
This is great news because it not only eliminates the use of an indicator or ten, but also allows you to check for the specific key itself.
INFDS position 369 contains the function key scan code:
D WSDS DS
D FKey 1A Overlay(WSDS:369)
The scan codes that are returned to position 369 have been published in my best-selling RPG IV book, The Modern RPG IV Language, for decades. I've reproduced them here in Figure 1.
|
Figure 1: Scan codes are returned to position 369.
In your RPG IV code, the following technique would be used to test for the function key used to return control to the program:
C SELECT
C When FKey = F12
C Callp previous()
C When FKey = F3
C exsr Exit
C When FKey = F5
C Callp Rollback(1)
C endSL
The use of indicators to condition code has been passé for almost 20 years. Continuing to condition your own code on function key response indicators is just as passé. Now you have the tools to stop using response indicators and write responsible code.
Bob Cozzi is a programmer/consultant, writer/author, and software developer of the RPG xTools, a popular add-on subprocedure library for RPG IV. His book The Modern RPG Language has been the most widely used RPG programming book for nearly two decades. He, along with others, speaks at and runs the highly-popular RPG World conference for RPG programmers.
LATEST COMMENTS
MC Press Online