Microsoft KB Archive/45447

How to Use CALL X“D9” to Check Keyboard Buffer in COBOL 3.0

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

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

Summary: Below is an example of how to use the Microsoft COBOL Versions 3.0 and 3.0a Special Subprogram CALL X“D9”, which checks for keys in the keyboard buffer. The routine takes one PIC 99 COMP-X parameter and returns either zero or a nonzero number. If the parameter is zero, there are no keys in the keyboard buffer. A nonzero number indicates the presence of a key waiting to be read. The CALL X“D9” Special Subprogram is discussed on Page 8-23 of the “Microsoft COBOL Compiler Version 3.0: Operating Guide” and is only supported in COBOL Versions 3.0 and 3.0a.

More Information: The follow program example displays the last key pressed and displays a scrolling alphabet at the bottom of the screen while waiting for input: $SET ANS85 DATA DIVISION. WORKING-STORAGE SECTION. 01 D9-PARAMETER PIC 99 COMP-X. 01 INPUT-KEY PIC X VALUE &quot; “. * scrolling alphabet info 01 ALPHA PIC X(26) VALUE”ABCDEFGHIJKLMNOPQRSTUVWXYZ“. 01 LETTER-ARRAY REDEFINES ALPHA. 05 A-LETTER PIC X OCCURS 26 TIMES. 01 1-SPACE PIC X VALUE” “. 01 2-SPACE PIC XX VALUE” “. 01 COL-UMN PIC 99 VALUE 20. 01 COUNTER PIC 99 VALUE 1. 01 MOVER PIC S9 VALUE 1. 01 TEMP-LETTER PIC X VALUE” “. SCREEN SECTION. 01 BLANK-SCREEN. 03 BLANK SCREEN. 01 ACCEPT-SCREEN. * The autoskip option is used to fill the input * field and then terminate the accept 03 LINE 10 COLUMN 47 PIC X USING INPUT-KEY AUTO-SKIP. 01 ALPHA-MOVE. 03 LINE 23 COLUMN COL-UMN PIC X FROM TEMP-LETTER. 01 ERASE-LETTER. 03 LINE 23 COLUMN COL-UMN PIC X FROM 1-SPACE. PROCEDURE DIVISION. DISPLAY BLANK-SCREEN. DISPLAY”PRESS ANY KEY(Q TO QUIT):&quot; AT 1020. DISPLAY “LAST KEY PRESSED WAS:” AT 1120. DISPLAY A-LETTER (COUNTER) AT 2320. PERFORM UNTIL INPUT-KEY = “Q” * making CALL to check for keys. CALL X“D9” USING D9-PARAMETER MOVE SPACES TO INPUT-KEY * check for a key in the buffer IF D9-PARAMETER NOT = 0 THEN * this section is performed only if there are * waiting keys. DISPLAY 2-SPACE AT 1144 DISPLAY ACCEPT-SCREEN ACCEPT ACCEPT-SCREEN DISPLAY 2-SPACE AT 1047 DISPLAY INPUT-KEY AT 1144 END-IF * this section displays the scrolling alphabet. * The next line stalls for displaying keys. * It may need to be adjusted for the speed of your * machine. PERFORM STALL-PROCEDURE 5000 TIMES DISPLAY ERASE-LETTER COMPUTE COUNTER = COUNTER + MOVER COMPUTE COL-UMN = 20 + COUNTER MOVE A-LETTER (COUNTER) TO TEMP-LETTER DISPLAY ALPHA-MOVE IF (COUNTER = 26) OR (COUNTER = 1) THEN COMPUTE MOVER = MOVER * -1 END-IF END-PERFORM. STOP RUN. STALL-PROCEDURE. * this is a dummy statement to stall screen update MOVE SPACES TO 1-SPACE.

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