Microsoft KB Archive/62819

CHAINing to Resident Program, New Copy Loaded If Path Used

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

3.00 3.00a MS-DOS

Summary: When a program is being CHAINed to and a copy of that program is already in memory (whether it was the start-up program or CALLed or CHAINed in), the copy of the program in memory is executed, and another one is not loaded. However, if a path is included in the CHAIN statement that invokes the program, a new copy will be loaded. This is not correct behavior. Microsoft has confirmed this to be a problem in Microsoft COBOL Compiler versions 3.0 and 3.0a for MS-DOS and MS OS/2. This problem has been corrected in Microsoft COBOL Professional Development System version 4.0. Note: You must change the sample code to run under COBOL 4.0. You will need to use the DISPLAY UPON COMMAND-LINE syntax. For more information on this change, query on the following words: COBOL and running and batch and files

More Information: Suppose PROG1.EXE is invoked from the DOS command line and chains to PROG2.EXE, which in turn chains back to PROG1.EXE. Since PROG1.EXE is the start-up program, it is already in memory and therefore should not have to be reloaded. In practice, this is the case if the CHAIN statement in PROG2.EXE that invokes PROG1.EXE does not have a path preceding the filename. However, if a path is included, PROG1.EXE will be reloaded, thus taking up more memory. The following programs illustrate the problem. PROG1.EXE chains to PROG2.EXE, which chains back to PROG1.EXE. Both programs display their name and the available memory (by using the subprogram X“91” to call CHKDSK). When the CHAIN statement in PROG2.EXE includes a path to PROG1.EXE, the available memory reported by PROG1.EXE will be less than it was in PROG2.EXE. When the path is taken out, this memory will not go down. To compile and link the programs, use the following: cobol prog1; cobol prog2; link prog1; link prog2;

PROG1
IDENTIFICATION DIVISION. PROGRAM-ID. PROG1. DATA DIVISION. WORKING-STORAGE SECTION. *  Parameters for X&quot;91&quot; call. 01 RESULT         PIC 99   COMP-X. 01 FUNCTION       PIC 99   COMP-X. 01 PARAMETER. 05 FILELENGTH  PIC 99   COMP-X. 05 FILENAME    PIC X(6). PROCEDURE DIVISION. DISPLAY &quot;PROG1&quot;. *   Setup call to X&quot;91&quot;, function 35. MOVE 35      TO FUNCTION. *   CHKDSK is 6 characters long. MOVE 6       TO FILELENGTH. *   Name of file (or DOS command) to execute. MOVE &quot;CHKDSK&quot; TO FILENAME. *   Make the call, available memory will be displayed. CALL X&quot;91&quot; USING RESULT, FUNCTION, PARAMETER. CHAIN &quot;PROG2&quot;.

PROG2
IDENTIFICATION DIVISION. PROGRAM-ID. PROG2. DATA DIVISION. WORKING-STORAGE SECTION. *  Parameters for X&quot;91&quot; call. 01 RESULT         PIC 99   COMP-X. 01 FUNCTION       PIC 99   COMP-X. 01 PARAMETER. 05 FILELENGTH  PIC 99   COMP-X. 05 FILENAME    PIC X(6). PROCEDURE DIVISION. DISPLAY &quot;PROG2&quot;. *   Setup call to X&quot;91&quot;, function 35. MOVE 35      TO FUNCTION. *   CHKDSK is 6 characters long. MOVE 6       TO FILELENGTH. *   Name of file (or DOS command) to execute. MOVE &quot;CHKDSK&quot; TO FILENAME. *   Make the call, available memory will be displayed. CALL X&quot;91&quot; USING RESULT, FUNCTION, PARAMETER. *   If the path is taken out of the CHAIN statement, the memory *   reported by PROG1.EXE will be the same as that reported by  *    PROG2.EXE. CHAIN &quot;.\PROG1&quot;. Additional reference words: 3.00 3.00a Copyright Microsoft Corporation 1993.