Microsoft KB Archive/40041
Detecting the ERRORLEVEL of COBOL Programs in Batch Files
PSS ID Number: Q40041 Article last modified on 04-20-1993
2.00 2.10 2.20 3.00 3.00a | 3.00 3.00a MS-DOS | OS/2
|The information in this article applies to:|
|- Microsoft COBOL for MS-DOS, versions 2.0, 2.1, 2.2, 3.0, and 3.0a - Microsoft COBOL for OS/2, versions 3.0 and 3.0a|
Summary: Microsoft COBOL Versions 2.0, 2.1, and 2.2 return an ERRORLEVEL of 255, if a COBOL program terminates abnormally. COBOL Versions 3.0 and 3.0a return a nonzero ERRORLEVEL if the program terminates abnormally. A program would be terminated abnormally if you pressed CTRL+BREAK or CTRL+C to get out of the program before it could complete execution. These ERRORLEVELs can be tested in a batch file.
More Information: It is important to remember that the IF statement in a batch file checks for ERRORLEVELs equal to or greater than the specified value. The following statement will be true for any value equal to or greater than 1: IF ERRORLEVEL 1 GOTO NONZERO More information on writing batch files can be found in “SuperCharging MS-DOS” by Van Wolverton, published by the Microsoft Press. The batch file below runs a program named “COBPROG.EXE” compiled with Microsoft COBOL Version 3.0 or 3.0a. The batch file will report whether the program terminated normally or abnormally. This same batch file can also be used to run a program compiled with COBOL Versions 2.0, 2.1, or 2.2. You would just have to add the RUNCOB command. The following is a code example:
echo off rem THE FOLLOWING LINE EXECUTES THE COBOL PROGRAM “cobprog” cobprog if errorlevel 1 goto nonzero if errorlevel 0 goto zero :nonzero echo PROGRAM COBPROG TERMINATED ABNORMALLY goto end :zero echo PROGRAM COBPROG TERMINATED NORMALLY goto end echo on :end
Additional reference words: 2.00 2.10 2.20 3.00 3.00a Copyright Microsoft Corporation 1993.