Microsoft KB Archive/63196

CALL X“B7” Fails If Passed Data from Other Module Used in CALL

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

3.00 3.00a MS-DOS

Summary: A call to the special subprogram X“B7” may not execute correctly if the third parameter in the CALL was passed to the current program via the LINKAGE SECTION from a program in a separate source file. For example, when using X“B7” to set a character on the screen, a different character than the one specified may actually be displayed. The following are three known workarounds to the problem: 1. Use nested programs rather than programs in separate source files. 2. Assign the passed parameter to a local data item, and use the local data item in the call to X“B7”. 3. Declare the passed parameter in the WORKING-STORAGE rather than the LINKAGE SECTION. Passing the parameter BY CONTENT will not work. Microsoft has confirmed this to be a problem in Microsoft COBOL Compiler versions 3.0 and 3.0a for MS-DOS. We are researching this problem and will post new information here as it becomes available.

More Information: The special subprogram X“B7” is used in COBOL 3.0 and 3.0a to set, read, or clear screen characters and attributes. The output of this subprogram may be incorrect when the third parameter passed to it is declared in the LINKAGE SECTION and that parameter is passed from another nonnested program. The third parameter is the buffer area and sends or receives attributes or characters depending on which function is chosen for X“B7”. The following two COBOL programs illustrate the problem. The program MAIN passes a PIC X data item called “Char” to the program SUB to be used as the third (buffer) parameter in a call to the subprogram X“B7”. Char is assigned the value “A” in MAIN, so the call to X“B7” in SUB should display an “A”. However, another ASCII character is displayed.

$SET VSC2 IDENTIFICATION DIVISION. PROGRAM-ID. MAIN. DATA DIVISION. WORKING-STORAGE SECTION. 01 Char  PIC X VALUE &quot;A&quot;. PROCEDURE DIVISION. *   Clear screen and call SUB CALL X&quot;E4&quot;. CALL &quot;SUB&quot; USING BY CONTENT Char. STOP RUN. IDENTIFICATION DIVISION. PROGRAM-ID. SUB. DATA DIVISION. WORKING-STORAGE SECTION. *  Function 1 writes 1 or more characters to screen. 01 Function          PIC 99   COMP-X VALUE 1. 01 Parameter. *  Number of characters to write is 1. 05 DataLength     PIC 9(4) COMP-X VALUE 1. *  Location on screen to write character (Row 10, Column 10) 05 StartPosition  PIC 9(4) COMP-X VALUE 730. *  Start at first character of buffer parameter. 05 BufferStart    PIC 9(4) COMP-X VALUE 1. LINKAGE SECTION. *  Parameter passed from MAIN, value is &quot;A&quot;. It is buffer area. 01 Char              PIC X.   PROCEDURE DIVISION USING Char. *   Some other ASCII character, not &quot;A&quot; will be output. CALL X&quot;B7&quot; USING Function, Parameter, Char. EXIT PROGRAM. The program below illustrates one of the workarounds for the problem. If the program being called and the program doing the calling are in the same source file, declaring the parameter in the LINKAGE SECTION and using it as the third parameter in a call to X“B7” will work properly. Putting two programs in the same source file is accomplished by nesting them and using the NESTCALL directive.

$SET NESTCALL * Outer program. IDENTIFICATION DIVISION. PROGRAM-ID. Main. DATA DIVISION. WORKING-STORAGE SECTION. 01 Char  PIC X VALUE &quot;A&quot;. PROCEDURE DIVISION. *   Clear screen and call SUB. CALL X&quot;E4&quot;. CALL &quot;SUB&quot; USING Char. STOP RUN. * Inner (nested) program. IDENTIFICATION DIVISION. PROGRAM-ID. SUB. DATA DIVISION. WORKING-STORAGE SECTION. *  Function 1 writes 1 or more characters to screen. 01 Function          PIC 99   COMP-X VALUE 1. 01 Parameter. *  Number of characters to write is 1. 05 DataLength     PIC 9(4) COMP-X VALUE 1. *  Location on screen to write character (Row 10, Column 10) 05 StartPosition  PIC 9(4) COMP-X VALUE 730. *  Start at first character of buffer parameter. 05 BufferStart    PIC 9(4) COMP-X VALUE 1. LINKAGE SECTION. *  Parameter passed from MAIN, value &quot;A&quot;. It is buffer area. 01 Char              PIC X.   PROCEDURE DIVISION USING Char. *   &quot;A&quot; will be output, parameter will not be corrupted. CALL X&quot;B7&quot; USING Function, Parameter, Char. EXIT PROGRAM. END PROGRAM Sub. END PROGRAM Main. The other two workarounds involve simple changes to the first SUB and are not illustrated here. One way is to declare the parameter Char in the WORKING-STORAGE rather than the LINKAGE SECTION. The other way is to assign Char to another PIC X data item and use that in the call to X“B7” rather than Char.

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