Brief: Indicators were never meant for human consumption. Anyone who tries to interpret a program that uses them, without some kind of supplemental documentation, knows why indicators should be avoided whenever possible. Replacing indicators with meaningful variable names can make a programmer's life much easier. In this article, you'll learn how you can eliminate function key indicators.
Quite possibly the worst part of programming an IBM midrange computer is using indicators. With RPG, COBOL, C or even CL, indicators are still the only way of communicating certain attributes to a display or printer file. What does indicator 01 mean? Is it being used to condition attributes such as highlighting, underlining, reverse image or field protect? Is the indicator assigned to a function key (also known as a command key) and if so, what function key does indicator 01 represent? F1? F24? Roll Up? Interpreting indicator meaning typically requires extra effort. You must often refer to the display or printer file source member to determine the meaning of an indicator.
You can employ a better method that uses no indicators (not even indicators KA through KZ in RPG) to handle function keys in your programs. The method allows for easier reading within your program, defines the Roll keys as well as Print and Help, and explicitly defines the Enter key! It is very easy to learn, set up and use-you can even modify existing programs to use the same technique. In this article, I'll show you how to use the technique in RPG and COBOL.
The Typical Scenario
Sadly, traditional programming methods have retained the use of indicators, even though techniques to program function keys without indicators have existed for years.
Using function keys within an interactive program is an example of communicating through indicators. Typically, as a programmer designs a display file, he defines an indicator to represent a function key. Then, as he designs the program, he includes a statement that checks to see if any of the function key indicators are on every time a screen format is read.
There is nothing wrong with checking to see which function key has been pressed. I just have a problem with function keys identified through indicators. No matter how logically or (heaven forbid!) arbitrarily you assign indicator numbers to represent function keys, your programs are all susceptible to the same two pitfalls.
o First, the Enter key is implied. What if your program finds no activated indicator as it tries to determine which function key was pressed? The program assumes the user pressed Enter. Suppose you define F8 in your display file but forget to specify what happens in your program if the indicator associated with F8 is on. If a user presses F8, the program responds as if the Enter key has been pressed.
o Second, the traditional function key indicator opens the door for a lot of guesswork about exactly which key the indicator represents. The method covered here presents more explicit, intuitive information about function keys. For example, instead of coding an RPG statement that checks the status of *IN25, why not check whether the function key is equal to ROLLUP?
The RPG statement in 1 implies testing to see if the Roll Up key was pressed. More importantly, no indicator is being used because CFKEY and ROLLUP have special meaning to the program. Let's look at how we can accomplish this.
The RPG statement in Figure 1 implies testing to see if the Roll Up key was pressed. More importantly, no indicator is being used because CFKEY and ROLLUP have special meaning to the program. Let's look at how we can accomplish this.
COBOL and RPG can access information about files used within a program, including a display file. The information is supplied by OS/400 in what is known as the I/O feedback area. RPG retrieves the I/O feedback area through the File Information Data Structure or INFDS. COBOL retrieves it through the ACCEPT statement using the mnemonic-name from the SPECIAL-NAMES paragraph. The Attention InDicator (AID) byte of the I/O feedback area indicates which function key was pressed during the last read of the display file.
RPG Coding
In order to use function keys in RPG without the use of indicators, you must:
1. Add a continuation line to your WORKSTN F-spec on the line immediately after the line which declares the display file. Specify the name of the INFDS you will use. 2 illustrates the assignment of the name DSPFDS.
1. Add a continuation line to your WORKSTN F-spec on the line immediately after the line which declares the display file. Specify the name of the INFDS you will use. Figure 2 illustrates the assignment of the name DSPFDS.
2. Define the INFDS within the I-specs of the program and define a subfield for the AID byte (posi-tion 369), as illustrated in 3.
2. Define the INFDS within the I-specs of the program and define a subfield for the AID byte (posi-tion 369), as illustrated in Figure 3.
3. Define constant values to represent each of the 28 function keys, as illustrated by the partial list in 4. Use the table in 5 to determine the hex value for the function keys you need to define. It is much easier to create this portion as a separate member and include it into your RPG program with the /COPY command at compile time.
3. Define constant values to represent each of the 28 function keys, as illustrated by the partial list in Figure 4. Use the table in Figure 5 to determine the hex value for the function keys you need to define. It is much easier to create this portion as a separate member and include it into your RPG program with the /COPY command at compile time.
4. Declare the desired function keys within your display file DDS (CAxx or CFxx), but do not assign an indicator to them. If you are modifying existing display files, remove the indicators that have been assigned to your function keys. I find it easiest to declare that all function keys are valid within the display file and then, within the program, display an error message for function keys that are not used.
6 illustrates how your RPG program might look. Based upon the function key pressed, the program performs a designated subroutine. For example, if Roll Up is pressed, then the NXTPAG subroutine is performed. If Roll Down is pressed, then the PRVPAG subroutine is performed. The Enter key (FENTER) is considered a valid function key, and a subroutine is set up for invalid function keys (BADFKY). Because I defined all function keys in the display file, the program must handle function keys that have no purpose.
Figure 6 illustrates how your RPG program might look. Based upon the function key pressed, the program performs a designated subroutine. For example, if Roll Up is pressed, then the NXTPAG subroutine is performed. If Roll Down is pressed, then the PRVPAG subroutine is performed. The Enter key (FENTER) is considered a valid function key, and a subroutine is set up for invalid function keys (BADFKY). Because I defined all function keys in the display file, the program must handle function keys that have no purpose.
COBOL Coding
Using function keys in a COBOL program without indicators also involves four steps:
1. Immediately after the OBJECT-COMPUTER line in your ENVIRONMENT DIVISION, key in the statement shown in 7 beginning in Area A. The statement relates the IBM I-O-Feedback name to a user-defined mnemonic-name.
1. Immediately after the OBJECT-COMPUTER line in your ENVIRONMENT DIVISION, key in the statement shown in Figure 7 beginning in Area A. The statement relates the IBM I-O-Feedback name to a user-defined mnemonic-name.
2. In the WORKING-STORAGE SECTION, key the first three statements shown in 8 followed by the function key definitions illustrated by the partial list. Use the table in 5 to determine the hex value for the function keys you need to define. Some of the suggested names for function keys shown in 5 are prefaced with the letter F to avoid using COBOL reserved words. You may find it easier to create a separate member within your source file for all of the information within DISPLAY-FILE-INFO and then use the COBOL COPY statement to copy it into your source code at compile time.
2. In the WORKING-STORAGE SECTION, key the first three statements shown in Figure 8 followed by the function key definitions illustrated by the partial list. Use the table in Figure 5 to determine the hex value for the function keys you need to define. Some of the suggested names for function keys shown in Figure 5 are prefaced with the letter F to avoid using COBOL reserved words. You may find it easier to create a separate member within your source file for all of the information within DISPLAY-FILE-INFO and then use the COBOL COPY statement to copy it into your source code at compile time.
3. Every time the display file is read, you must follow the READ statement with the statement shown in 9 (begin the statement in Area B). This statement loads the AID byte into the FUNCTION-KEY variable defined in the WORKING- STORAGE SECTION.
3. Every time the display file is read, you must follow the READ statement with the statement shown in Figure 9 (begin the statement in Area B). This statement loads the AID byte into the FUNCTION-KEY variable defined in the WORKING- STORAGE SECTION.
4. Step 4 is identical to item 4 in the RPG coding.
When you have finished coding the SPECIAL-NAMES, WORKING-STORAGE SECTION and ACCEPT statements into your program, you may begin testing function keys without indicators. 10 contains an example of how you might code your COBOL program to sense the function keys.
When you have finished coding the SPECIAL-NAMES, WORKING-STORAGE SECTION and ACCEPT statements into your program, you may begin testing function keys without indicators. Figure 10 contains an example of how you might code your COBOL program to sense the function keys.
Improve Program Readability
Testing the AID byte instead of using indicators within your program has several advantages. The biggest advantage is that the program becomes self- documenting. The program is easier to read because the unintuitive "mapping" of indicator numbers to function keys is replaced by explicit words that correspond with the function key name. To find out more about reducing indicator usage, see "Run-time Screen Attributes," MC, May 1994.
Wayne Johnson is president of Multiple Computer Directions, Inc. in Conyers, Georgia.
Indicatorless Function Keys
Figure 1 Testing for Rollup Key
*. 1 ...+... 2 ...+... 3 ...+... 4 ...+... 5 ...+... 6 ...+ C CFKEY IFEQ ROLLUP
Indicatorless Function Keys
Figure 2 Defining the File Information Data Structure in RP
*. 1 ...+... 2 ...+... 3 ...+... 4 ...+... 5 ...+... 6 ...+ F KINFDS DSPFDS
Indicatorless Function Keys
Figure 3 Defining the INFDS AID Byte in RPG
*. 1 ...+... 2 ...+... 3 ...+... 4 ...+... 5 ...+... 6 ...+ IDSPFDS DS I 369 369 CFKEY
Indicatorless Function Keys
Figure 4 Defining Constants to Represent Possible AID Byte
*. 1 ...+... 2 ...+... 3 ...+... 4 ...+... 5 ...+... 6 ...+ I*====================================================* I* DEFINE THE AID BYTE CONSTANT VALUES. USE WITHIN A * I* PROGRAM TO CHECK FOR COMMAND FUNCTION KEYS RATHER * I* THAN USING INDICATORS. * I*====================================================* I X'31' C F01 I X'32' C F02 * . * . * .
Indicatorless Function Keys
Figure 5 Hex Code Values Returned by Function Keys Through
UNABLE TO REPRODUCE GRAPHICS
Indicatorless Function Keys
Figure 6 Partial RPG Code to Sense Aid Byte Value
*..1....+....2....+....3....+....4....+....5....+....6....+ C CFKEY DOUEQF03 C EXFMTSCREEN * C CFKEY CASEQFROLLU NXTPAG C CFKEY CASEQFROLLD PRVPAG C CFKEY CASEQF05 REFRSH C CFKEY CASEQF12 CANCEL C CFKEY CASEQFENTER VERIFY C CAS BADFKY C ENDCS C ENDDO
Indicatorless Function Keys
Figure 7 Relate I-O-FEEDBACK to User-defined Mnemonic-name
SPECIAL-NAMES. I-O-FEEDBACK IS I-O-FEEDBACK-AREA.
Indicatorless Function Keys
Figure 8 Defining the AID Byte in COBOL
01 DISPLAY-FILE-INFO. 05 FILLER PIC X(146). 05 FUNCTION-KEY PIC X. 88 F01 VALUE X'31'. 88 F02 VALUE X'32'. 88 F03 VALUE X'33'. . . .
Indicatorless Function Keys
Figure 9 Load AID Byte to Variable in COBOL
ACCEPT DISPLAY-FILE-INFO FROM I-O-FEEDBACK-AREA.
Indicatorless Function Keys
Figure 10 Partial COBOL Code Example to Sense Function Keys
EVALUATE TRUE WHEN F03 STOP RUN WHEN FENTER PERFORM PROCESS-DATA WHEN OTHER PERFORM UNKNOWN-FKEY END-EVALUATE.
LATEST COMMENTS
MC Press Online