Microsoft KB Archive/45448

From BetaArchive Wiki

COBOL 3.00 Can Make Data Keys Terminate ACCEPT and Be Trapped

PSS ID Number: Q45448 Article last modified on 06-07-1989

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

Summary: Microsoft COBOL can make data keys terminate an ACCEPT by using the CALL X“AF” routine. After the ACCEPT, you can determine (trap) which data key terminated the ACCEPT. “Data keys” that can be used with CALL X“AF” include all keys that return an alphanumeric character or symbol and can be typed into a quoted constant in your COBOL program. For example, you can trap the data characters on gray keys and the MINUS, ASTERISK, and BACKSLASH keys on the numeric keypad. When you set up trapping for a data key symbol that occurs on both the normal keyboard and on a gray numeric keypad key (such as the PLUS “+”, MINUS “-”, and ASTERISK "*" keys), then both keys are trapped. This information applies to Microsoft COBOL Versions 3.00 and 3.00a for MS-DOS and MS OS/2.

More Information: The CALL X“AF” technique above does not let you trap arrow keys. The following program demonstrates how to CALL X“AF” and make the keys A, B, C, and PLUS (+) act as terminator keys: $SET ANS85 ENVIRONMENT DIVISION. SPECIAL-NAMES. CRT STATUS IS KEY-STAT. DATA DIVISION. WORKING-STORAGE SECTION. 01 SET-BIT-PAIRS PIC 9(2) COMP-X VALUE 1. 01 DATA-KEY-CONTROL. 03 DATA-KEY-SETTING PIC 9(2) COMP-X. 03 FILLER PIC X VALUE “3”. 03 FIRST-DATA-KEY PIC X. 03 NUMBER-OF-DATA-KEYS PIC 9(2) COMP-X. 01 KEY-STAT. 03 KEY-TYPE PIC 9. 03 KEY-CODE-1 PIC 99 COMP-X. 03 KEY-CODE-2 PIC 99 COMP-X. 01 DATA-ITEM PIC X. 01 SCAN-CODE-A PIC 99 VALUE 65. 01 SCAN-CODE-B PIC 99 VALUE 66. 01 SCAN-CODE-C PIC 99 VALUE 67. 01 SCAN-CODE-PLUS PIC 99 VALUE 43. SCREEN SECTION. 01 CLEAR-SCREEN. 03 BLANK SCREEN. PROCEDURE DIVISION. DISPLAY CLEAR-SCREEN. * define the action of the affected keys. * 0 = key is disabled. * 1 = key will act as a function key. * it will terminate accepts. * 2 = (default)key acts as normal. MOVE 1 TO DATA-KEY-SETTING. determine the first key to be affected MOVE “+” TO FIRST-DATA-KEY. * determine the number of keys to be affected. * it is the number of sequential scan codes that * will be changed by the CALL X“AF” routine. MOVE 1 TO NUMBER-OF-DATA-KEYS. * make call to turn on + key. CALL X“AF” USING SET-BIT-PAIRS DATA-KEY-CONTROL. MOVE “A” TO FIRST-DATA-KEY. MOVE 3 TO NUMBER-OF-DATA-KEYS. * make call to turn on A,B, and C. CALL X“AF” USING SET-BIT-PAIRS DATA-KEY-CONTROL. ACCEPT DATA-ITEM AT 0101. * key-type indicates what type of key was * the terminator key. * key-type key-code-1 meaning * 0 0 The operator pressed a * terminator key. * 0 1 Auto-skip out of the last field. * 1 0-127 The function key number * 2 0-26 The function key number * 3 any Data key terminated accept. IF KEY-TYPE = “3” EVALUATE KEY-CODE-1 WHEN SCAN-CODE-A DISPLAY “A WAS THE TERMINATOR” WHEN SCAN-CODE-B DISPLAY “B WAS THE TERMINATOR” WHEN SCAN-CODE-C DISPLAY “C WAS THE TERMINATOR” WHEN SCAN-CODE-PLUS DISPLAY “+ WAS THE TERMINATOR” END-EVALUATE END-IF. STOP-RUN.

Copyright Microsoft Corporation 1989.