Microsoft KB Archive/51596

How to Use CALL X“B7” Routine in COBOL 3.00

PSS ID Number: Q51596 Article last modified on 12-19-1989

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

Summary: The CALL X“B7” routine in COBOL Versions 3.00 and 3.00a provides an easy way to perform a wide variety of functions that are normally handled by the DISPLAY and ACCEPT statements and also by the SCREEN SECTION. This information applies to Microsoft COBOL Compiler Versions 3.00 and 3.00a under both MS-DOS and MS OS/2.

More Information: With the CALL X“B7” function, you have access to the following operations: 1. Reading and writing characters from and to the screen 2. Getting and setting screen attributes 3. Clearing the screen 4. Clearing screen attributes The main advantage to using CALL X“B7” over ACCEPT or DISPLAY is that it does not require any of the ADIS routines to be linked or ADIS.EXE to be present. This leads to a smaller .EXE and quicker compilation of your programs. The second advantage is that all of your screen input and output functions can be done through one standard statement rather than a complex combination of ACCEPTS, DISPLAYS, and SCREEN SECTION entries. The syntax for the CALL X“B7” routine is as follows CALL X“B7” USING Function Parameter Buffer. where “Function” is a PIC 99 COMP-X data item with the value 0 = read character(s) from the screen 1 = write character(s) to the screen 2 = read attributes from the screen 3 = write attributes to the screen 4 = clear characters from the screen 5 = clear attributes from the screen Note: Function 5 can be unpredictable and has been known to hang the machine if clearing an area where nothing but the default attributes are set. “Parameter” is a group item containing three data items: 1. A PIC 9(4) COMP-X field showing the length of the data to be read or written. 2. A PIC 9(4) COMP-X field giving the start position on the screen. The top left position is 1, 81 is the start of the next line, and 2000 is the lower-right corner (25 rows by 80 columns.) 3. A PIC 9(4) COMP-X field showing the start position in the data buffer (usually a 1). “Buffer” is the COBOL data area. It is a PIC X(n) field and can be as large or small as you require. The size should be as large or larger than the first COMP-X field in the “Parameter” group item.

Code Example
The following program, named SCREENIO, gives examples of how to read and write characters from the screen, and also how to get and set screen colors, using CALL X“B7”. The 78-level constants used in the program to define a screen color use a two-digit hex number. The first digit of the number stands for the background, while the second digit stands for the foreground. The colors can range from 0 to F (or 0 to 15 decimal), but if the background digit is greater than 7, the text will blink on and off. (This only applies to color monitors.) For a list of the default colors in COBOL 3.00 or 3.00a, refer to Page F-6 of the “Microsoft COBOL Compiler 3.0: Language Reference Manual.” Note: In the following program, instead of doing a CALL X“B7”, simply define the value X“B7” as a 78-level constant called SCR-IO and then do a CALL SCR-IO. Therefore, CALL SCR-IO… is the same as CALL X“B7”… $SET ANS85 IDENTIFICATION DIVISION. PROGRAM-ID. SCREENIO. ENVIRONMENT DIVISION. DATA DIVISION. WORKING-STORAGE SECTION. 78 CLEAR-SCREEN VALUE X“E4”. 78 SCR-IO VALUE X“B7”. * will do the call x“B7” with the syntax: * CALL SCR-IO USING FUNC1 PARAM1 BUFFER#. 77 FUNC1 PIC 99 COMP-X. * func1 is the I-O function you want to perform: * 0 = read characters from screen * 1 = write characters to screen * 2 = read screen attributes * 3 = write screen attributes * 4 = clear characters from the screen * 5 = clear attributes from the screen 01 PARAM1. 05 LENGTH-DATA PIC 9(4) COMP-X. 05 SCREEN-POS PIC 9(4) COMP-X. 05 BUFFER-START PIC 9(4) COMP-X. * length-data is the length of the data to be * written or read. * screen-pos is the starting position on the screen * 1 = row 1, col 1; 81 = row 2, col 1; * 1841 = row 24, col 1; 2000 = row 25, col 80. * buffer-start is the starting position in the data * buffer. 77 BUFFER1 PIC X(80). * buffer1 = one line of text 77 BUFFER2 PIC X(2000). * buffer2 = one screen (25''80) of text 77 BUFFER3 PIC X(10). '' buffer3 = ten characters of text 77 BUFFER4 PIC X(1). * buffer4 = one character. * The following constants can be used for setting * different screen colors and attributes. * The first hex digit is the background color and the * second is foreground. If the background number is * higher than 7, then it specifies blinking text. 78 BLACK-CYAN VALUE X“03”. 78 BLACK-YELLOW VALUE X“0E”. 78 BLINK-BLU-CYAN VALUE X“93”. 78 BLU-CYAN VALUE X“13”. 78 BLU-WHITE VALUE X“1F”. 78 BLU-YELLOW VALUE X“1E”. 78 CYAN-BLACK VALUE X“30”. 78 RED-WHITE VALUE X“4F”. 78 GRN-WHITE VALUE X“2F”. 78 BLINK-WHITE-BLU VALUE X“F1”. 78 BLACK-WHITE VALUE X“07”. 78 BLINK-BLU-RED VALUE X“94”. ''==================================================== PROCEDURE DIVISION. ''==================================================== MAIN-PARA. CALL CLEAR-SCREEN. MOVE 1 TO BUFFER-START. * first, set the whole screen to black on cyan. MOVE 2000 TO LENGTH-DATA. MOVE 1 TO SCREEN-POS. MOVE ALL CYAN-BLACK TO BUFFER2. MOVE 3 TO FUNC1. CALL SCR-IO USING FUNC1 PARAM1 BUFFER2. * make eleventh line red on blue with blinking text. MOVE 80 TO LENGTH-DATA. MOVE 801 TO SCREEN-POS. MOVE ALL BLINK-BLU-RED TO BUFFER1. MOVE 3 TO FUNC1. CALL SCR-IO USING FUNC1 PARAM1 BUFFER1. * print ‘hello’ in the middle of the eleventh line. MOVE 10 TO LENGTH-DATA. MOVE 840 TO SCREEN-POS. MOVE “HELLO” TO BUFFER3. MOVE 1 TO FUNC1. CALL SCR-IO USING FUNC1 PARAM1 BUFFER3. * read one character on screen and put it in another spot. MOVE 1 TO LENGTH-DATA. MOVE 840 TO SCREEN-POS. MOVE SPACE TO BUFFER4. MOVE 0 TO FUNC1. CALL SCR-IO USING FUNC1 PARAM1 BUFFER4. MOVE 1241 TO SCREEN-POS. MOVE 1 TO FUNC1. CALL SCR-IO USING FUNC1 PARAM1 BUFFER4. * read screen attribute from line 11 and * then set line 18 to the same colors. MOVE 80 TO LENGTH-DATA. MOVE 801 TO SCREEN-POS. MOVE SPACE TO BUFFER1. MOVE 2 TO FUNC1. CALL SCR-IO USING FUNC1 PARAM1 BUFFER1. MOVE 1361 TO SCREEN-POS. MOVE 3 TO FUNC1. CALL SCR-IO USING FUNC1 PARAM1 BUFFER1. STOP RUN.

Copyright Microsoft Corporation 1989.