Microsoft KB Archive/35726

From BetaArchive Wiki

Invoking "_MSEXCODE" COBOL 3.0 Extension for DOS Error Level

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

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

The information in this article applies to:
- Microsoft COBOL for MS-DOS and OS/2, versions 3.0 and 3.0a

Summary: The Microsoft COBOL Version 3.0 extension subroutine "_MSEXCODE" replaces the extension “EXCODE” found in Microsoft COBOL Versions 2.x. This extension subroutine may be called from a COBOL program to set the value of the exit code (error level) passed to MS-DOS. The exit code can be detected in MS-DOS batch files using the IF ERRORLEVEL batch statement, as shown further below. The syntax for the “EXCODE” call given in the file MS2-2.DOC will cause the compiler to issue the following error message: Call parameter is literal (or LENGTH of) By content assumed Despite this warning message, the generated code may be used successfully. The sample program below works correctly and generates no error message when complied with the ANS85 directive.

More Information: In the program below, an unsigned numeric data-item with a picture range of 9 to 9(4) may be used as EXIT-CODE. The following is an EXITTEST.CON code example: IDENTIFICATION DIVISION. PROGRAM-ID. EXITTEST. DATA DIVISION. WORKING-STORAGE SECTION. 01 EXIT-CODE PIC 99 VALUE 16. PROCEDURE DIVISION. MAIN. CALL "_MSEXCODE" USING BY REFERENCE EXIT-CODE, BY CONTENT LENGTH OF EXIT-CODE. STOP RUN. To test the above program, you can create and run the following MS-DOS batch file, which runs the EXITTEST program and tests its MS-DOS exit code: EXITTEST ECHO OFF IF ERRORLEVEL = 16 GOTO WORKS IF ERRORLEVEL NOT = 16 GOTO FAILED GOTO THEEND :WORKS ECHO The EXITTEST program worked! GOTO THEEND :FAILED ECHO The EXITTEST program failed! :THEEND ECHO The EXITTEST program is done. End of batch file.

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