Microsoft KB Archive/35327

3.0 COPY Text File Must End with Carriage Return, Linefeed

PSS ID Number: Q35327 Article last modified on 04-21-1993

3.00 | 3.00 MS-DOS | OS/2

Summary: The COBOL COPY statement incorporates text into a source program. The final line of text in the file specified by the COPY command must be terminated by a carriage return and linefeed (CR/LF); otherwise, that line is not merged in at compile time. COPY has the same function as the #include directive in Microsoft C, or the $INCLUDE: metacommand of the Microsoft BASIC or FORTRAN compilers.

More Information: This problem can occur when you use a word processor to divide a COBOL source program into a main file and one or more COPY files. It is easy to inadvertently omit the CR/LF while making one of the files to be used in a COPY statement. Although the original program may have worked correctly, the divided code will not if a CR/LF is missing at the end. The missing CR/LF removes the last line of code in the COPY file, possibly causing erratic results, run-time failure, or a compilation failure. Note that COBOL cannot always detect the missing line at compile time. While splitting a source file with Microsoft Word (or other text editors), be certain that the cursor remains at the bottom-left margin on a line of its own after any trailing text has been deleted from the COPY file.

Code Example If the final carriage return is deleted in the STAR65B.CPY file, you will get the following errors when compiling the code below: 14 PROCEDURE DIVISION. ** 44-S ********* Literal expected 20 EXHIBIT DUMMY-THREE ** 12-S ********* Operand is not declared IDENTIFICATION DIVISION. PROGRAM-ID. DRIVER. DATA DIVISION. WORKING-STORAGE SECTION. 01 COPY C:65B.CPY. PROCEDURE DIVISION. DISPLAY “DRIVER:” EXHIBIT DUMMY-FIELD. EXHIBIT DUMMY-TOO. EXHIBIT DUMMY-THREE. STOP RUN. * The following are the contents of file STAR65B.CPY: DUMMY IS GLOBAL. 05 DUMMY-FIELD PIC X(23) VALUE “THIS IS THE FIRST VALUE”. 05 DUMMY-TOO PIC X(5) VALUE “TEST1”. 05 DUMMY-THREE PIC X(5) VALUE “TEST2”.

Additional reference words: 3.00 Copyright Microsoft Corporation 1993.