Microsoft KB Archive/37881

CANCEL Must Cancel the PROGRAM-ID of the Called Program

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

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

Summary: When a dynamic Microsoft COBOL Version 3.0 or 3.0a subprogram is CALLed and exited, the subprogram should subsequently be CANCELled using the subprogram’s PROGRAM-ID value. If the subprogram is not CANCELled or it is CANCELled using its different .EXE filename, it remains in memory and can eventually cause a load error, such as the following: Failed to load program Run time error number: 198 The program will return to the MS-DOS prompt.

More Information: In the example below, the subprogram will not be unloaded from memory if the “driver” program CANCELs the .EXE subprogram filename instead of the PROGRAM-ID name. If the CANCEL statement is changed to look like CANCEL “PASSENGER”, it should then unload and free memory as expected. Other than ANS85, these programs can be compiled with most any directive.

Code Example
Program name “DRIVER.CBL”: $SET ANS85 IDENTIFICATION DIVISION. PROGRAM-ID. DRIVER. DATA DIVISION. WORKING-STORAGE SECTION. 01 PASS-VALUE PIC 9(6) VALUE ZERO. PROCEDURE DIVISION. MAIN. PERFORM UNTIL PASS-VALUE = 100 CALL “SUBPROG.EXE” USING BY REFERENCE PASS-VALUE DISPLAY PASS-VALUE AT 2020 CANCEL “SUBPROG.EXE” END-PERFORM. STOP RUN. Program name “SUBPROG.CBL”: $SET ANS85 IDENTIFICATION DIVISION. PROGRAM-ID. PASSENGER. DATA DIVISION. LINKAGE SECTION. 01 DUMMY-ONE PIC 9(6). PROCEDURE DIVISION USING DUMMY-ONE. ADD 1 TO DUMMY-ONE. END PROGRAM PASSENGER.

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