A COPY statement is used to bring a series of prewritten COBOL entries that have been stored in library, into a program.
1.Common routines like error routine, date validation routine are coded in a library and bring into the program by COPY.
2. Master files are used in multiple programs. Their layout can be placed in one copybook and be placed wherever the files are used. It promotes program standardization since all the programs share the same layout and the same data names.
This reduces coding and debugging time. Change in layout needs change in copybook only. It is enough if we just recompile the program for making the new copy effective.
Syntax:
COPY copybook-name [(OF/IN) library name]
[REPLACING string-to-be-replaced BY replacing-string]
Copybooks are stored as members in PDS library and during compilation time, they are included into the program. By default, the copybook library is SYSLIB and it can be changed using IN or OF of COPY statement.
Copybooks can be used in the following paragraphs.
SOURCE-COMPUTER, OBJECT-COMPUTER, SPECIAL-NAMES, FILE-CONTROL, IO-CONTROL, FD SECTION, PARAGRAPHS IN PROCEDURE DIVISION.
If the same copybook is used more than once in the program, then there will be “duplicate data declaration” error during compilation, as all the fields are declared twice. In this case, one copybook can be used with REPLACING verb to replace high-level qualifier of the all the variables with another qualifier.
Example: COPY CUSTOMER REPLACING ‘CUST1-‘ BY ‘CUST2-‘.
Delimiter ‘= =’ should be used for replacing pseudo texts. The replacing option does not alter the prewritten entries in the library; the changes are made to the user’s source program only.
No comments:
Post a Comment