copy/include command

Copybook Files

Copybook files are external code files that can be loaded into a CobolScript program via a single statement. The contents of the copybook file are then treated as if they were part of the program. Copybooks are most commonly used to store variable definitions, especially record variable definitions, since the same data file is often used by multiple programs. Using a copybook to store a record variable definition reduces programming effort and eliminates the possibility of discrepancies in the definition across programs. Copybooks also work well for storing group-level data items that contain HTML that you want to replicate across your CobolScript CGI programs.

Copybook files are included in a program with the COPY or INCLUDE statement. These statements are special in that they can be located anywhere within a program. This allows the code in a copybook to be substituted into the program at any location, wherever the COPY or INCLUDE statement is placed.

In the following example, an INCLUDE statement is inserted into a program to include the file testvars.cpy, which is located in the parent directory of the CobolScript engine’s directory, on a Windows machine:

FD test.dat RECORD IS 17 BYTES.

INCLUDE `..\testvars.cpy`.

Although it’s possible to include a path in the INCLUDE statement like this example does, it’s inadvisable if you frequently move your code between machines with Windows file systems and ones with Unix file systems. The directory symbol is different for these file systems ( ‘\’ versus ‘/’ ) and your code will then require that you change this symbol every time you switch between the two platforms.

When we examine the contents of testvars.cpy, we see that this file contains a few simple variable definitions that can then be referenced by the calling program:

1 content_length PIC 9(5).

1 eof PIC 9.

1 occurs_var OCCURS 5 TIMES.

5 occurs_var_1 PIC 999.

Assuming that it follows the INCLUDE statement in our original program, the following MOVE is legitimate because the definition for eof is now included in the program’s variables:

MOVE 1 TO eof.

For more information on the COPY and INCLUDE statements, see their respective entries in Appendix A, Language Reference.




Command:

COPY

Syntax:

COPY <copybook-literal>.

Description:

COPY loads the file named by the literal value copybook-literal into a CobolScript program. The code that is in the copybook file is loaded and executed as if it were part of the loading program, exactly in the position of the COPY statement.

In CobolScript, there is no material difference between INCLUDE and COPY.

Example Usage:

COPY `COPYBOOK.CPY`.

COPY `copybook.cpy`.

See Also:

INCLUDE

Sample Program:

COPY.CBL




Command:

INCLUDE

Syntax:

INCLUDE <copybook-literal>.

Description:

INCLUDE loads the file named by the literal value copybook-literal into a CobolScript program. The code that is in the copybook file is loaded and executed as if it were part of the loading program, exactly in the position of the COPY statement.

In CobolScript, there is no material difference between INCLUDE and COPY.

Example Usage:

INCLUDE `COPYBOOK.INC`.

INCLUDE copybook_var.

See Also:

COPY

Sample Program:

COPY.CBL