Microsoft KB Archive/65885

Running Batch Files Is Different in COBOL 4.00 vs. COBOL 3.x

PSS ID Number: Q65885 Article last modified on 11-19-1990

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

Summary: In Microsoft COBOL versions 3.00 and 3.00a, function 35 of the special subprogram X“91” can be used to execute batch files. This is accomplished by passing as the third parameter to X“91” a group item consisting of two fields: the first having a PIC clause of 99 COMP-X and holding the length of the name of the batch file, the second having a PIC X clause of the length specified in the first field and holding the actual name of the file. This technique does not work for running batch files (.BAT for DOS, .CMD for OS/2) from a program compiled and linked with Microsoft COBOL Professional Development System (PDS) version 4.00. To run batch files from a COBOL 4.00 program, the DISPLAY UPON COMMAND-LINE statement must be used to place the name of the batch file into the command-line interpreter’s buffer area. Then a call to function 35 of subprogram X“91” will execute the batch file. This information applies to Microsoft COBOL Professional Development System (PDS) version 4.00 for MS-DOS and MS OS/2.

More Information: Trying to execute a batch file from a COBOL 4.00 program with the first method described above usually hangs the machine in real mode, or hangs the screen group in OS/2’s protected mode. When using the DISPLAY UPON COMMAND-LINE method, the third parameter passed to function 35 of subprogram X“91” has a different meaning. The first field of this parameter must be set to 0 (zero), not the length of the name of the batch file. The value of the second field is ignored, so giving it the smallest PIC clause possible (just X) is desirable. The first code example below demonstrates the new method that COBOL 4.00 PDS must use to execute batch files. The second example demonstrates the method COBOL 3.00 and 3.00a are able to use. Both programs run the batch file named “BATCH.BAT”. For OS/2 protected mode, change the name to “BATCH.CMD”:

Code Example 1
IDENTIFICATION DIVISION. PROGRAM-ID. Batch400 DATA DIVISION. WORKING-STORAGE SECTION. 01 Result        PIC 99 COMP-X. 01 Function      PIC 99 COMP-X VALUE 35. 01 Parameter. 05 NameLength PIC 99 COMP-X VALUE 0 05 FileName   PIC X.   PROCEDURE DIVISION. DISPLAY &quot;BATCH.BAT&quot; UPON COMMAND-LINE. CALL X&quot;91&quot; USING Result, Function, Parameter. STOP RUN.

Code Example 2
IDENTIFICATION DIVISION. PROGRAM-ID. Batch300. DATA DIVISION. WORKING-STORAGE SECTION. 01 Result        PIC 99   COMP-X. 01 Function      PIC 99   COMP-X VALUE 35. 01 Parameter. 05 NameLength PIC 99   COMP-X VALUE 9. 05 FileName   PIC X(9)        VALUE &quot;BATCH.BAT&quot;. PROCEDURE DIVISION. CALL X&quot;91&quot; USING Result, Function, Parameter. STOP RUN. Copyright Microsoft Corporation 1990.