Microsoft KB Archive/47038

From BetaArchive Wiki

Explanation of COBOL System-Defined Function Keys, CRT STATUS

PSS ID Number: Q47038 Article last modified on 04-20-1993

3.00 3.00a | 3.00 3.00a MS-DOS | OS/2

The information in this article applies to:
- Microsoft COBOL for MS-DOS and OS/2, versions 3.0 and 3.0a

Summary: This article explains how to use COBOL “system-defined function keys” in Microsoft COBOL 3.0 and 3.0a. Page 15-7 of the “Microsoft COBOL Version 3.0: Language Reference Manual” explains that a value of 2 is returned in CRT STATUS KEY 1 for COBOL system-defined function keys. System-defined function keys are those keys, other than F1 through F12, that are configured to act exactly the same as function keys. This is done through the ADISCF.EXE program. Step-by-step instructions are given below. The value returned in CRT STATUS KEY 1 allows the program to determine exactly which key was pressed, one of the normal function keys, such as F1 through F10, or one of the other keys that has been altered to act as function keys.

More Information: The benefit of system-defined function keys is that many more unique function keys are available to the programmer. The trade-off is that when a key is reconfigured to act as a function key, that key no longer performs its normal function during an ACCEPT. For example, if we configure the DOWN ARROW to be a function key, it no longer moves the cursor to the last field of a SCREEN, but it does terminate the SCREEN, just as any other function key. Note: The definition of a function key in COBOL is a key that terminates an ACCEPT and returns a value in the CRT STATUS (or ESCAPE KEY) data item to indicate which key was pressed. Function keys cannot be used with any other COBOL verbs. The following steps enable the use of COBOL system-defined function keys: 1. From DOS, type ADISCF to start the program. 2. Select F2 = Alter. There are two steps to perform while in the ALTER portion of ADISCF: a. Step 1. Enable all function keys, user- and system-defined, as follows: 1) From the main menu, select F3 = Accept/Display Options. 2) Select F3 = Individual Options. 3) Choose 1 for Function Keys Enable/Disable. 4) Choose 2 for All function keys are enabled. 5) Press ENTER (not ESC) to activate the changes. 6) Press ESC (the ESCape key) twice to return to ALTER menu. b. Step 2: Choose the user-defined function keys, as follows: 1) Select F8 = Key Control 2) Select F2 = Enable/Disable ADIS Keys 3) Use the arrow keys to move the cursor to the key(s) that you want to act as function keys. Press “F” to change the status to function key. Press ENTER (not ESC) when finished selecting. For the code example below to work correctly, the LEFT and RIGHT ARROW keys must be defined as function keys at this point. These are items 4 and 5 in this menu and are labeled “cursor right” and “cursor left”. 4) Press ESC twice to go to the main ADISCF menu. The keys are now defined as function keys. Whenever changes are made in ADISCF, you must save the new configuration and choose the configuration. This is done from the F4 = Save and F6 = Choose options from the ADISCF main menu. For more detailed instructions on Saving and Choosing, search for the following words: ADISCF and ADISCTRL and change and choose and cobdir The article produced by this query also gives suggestions and troubleshooting hints if the changes made in ADISCF do not take effect.

Code Example

The following is a code example that displays the current value of the CRT STATUS keys. It can be used to display the result of the changes made in the instructions above. * Compile line: * COBOL cobkeys.cob; * Link line: * LINK cobkeys.obj; * For the code example below to work correctly, the LEFT and * RIGHT ARROW keys must be defined as function keys. SPECIAL-NAMES. CRT STATUS IS Key-Status. DATA DIVISION. WORKING-STORAGE SECTION. 01 Key-Status. 03 Key-Type PIC X. 03 Key-Code-1 PIC 9(2) COMP-X. 03 Key-Code-2 PIC 9(2) COMP-X. 01 STUFF-TO-ACCEPT. 03 STUFF-1 pic x(10). 03 stuff-2 pic x(10). SCREEN SECTION. 01 BANNERS. 05 LINE 1 COL 1 VALUE " " BLANK SCREEN. 05 LINE 5 COL 10 VALUE “IF THE ARTICLE WAS FOLLOWED CORRECTLY,”. 05 LINE 6 COL 10 VALUE “THEN KEY-TYPE SHOULD BE ‘2’ FOR THE”. 05 LINE 7 COL 10 VALUE “LEFT AND RIGHT ARROW KEYS”. 05 LINE 14 COL 10 VALUE “HIT THE ESC TO EXIT THE PROGRAM” HIGHLIGHT. 01 DATA-SCREEN-1 AUTO-SKIP. 05 PART-1. 10 LINE 2 COLUMN 10 VALUE “ALPHA:”. 10 pic x(10) using stuff-1. 05 PART-2. 10 LINE 3 COLUMN 10 VALUE “NUMERIC:”. 10 pic 9(10) using stuff-1. PROCEDURE DIVISION. MAIN. * Banner messages to inform user of what is happening. DISPLAY BANNERS. *********************************************************** * Main loop. Continue to loop until ESC is pressed. While looping, display the CRT STATUS key that tells what type of function key was pressed. ********************************************************** PERFORM PRINT-KEYS UNTIL KEY-TYPE = 1 AND KEY-CODE-1 = 0. STOP RUN. * Procedures. PRINT-KEYS. DISPLAY DATA-SCREEN-1. * This ACCEPT will be terminated by whatever function keys are * defined. ACCEPT DATA-SCREEN-1. * Display what function key terminated the ACCEPT. PERFORM DISPLAY-KEYS. DISPLAY-KEYS. DISPLAY “KEY-TYPE:” AT 1010 KEY-TYPE. DISPLAY “KEY-CODE-1:” AT 1110 KEY-CODE-1. DISPLAY “KEY-CODE-2:” AT 1210 KEY-CODE-2.

Additional reference words: 3.00 3.00a Copyright Microsoft Corporation 1993.