Text Words
The matching procedure in the REPLACING phrase operates on text words.
A text word is defined as ;
Any COBOL text enclosed in double equal signs (e.g. ==ADD 1==). This text is known as PseudoText and it allows us to replace a series of words or characters as opposed to an individual identifier, literal or word.
Any literal including opening and closing quotes
Any separator other than;
A space
A Pseudo-Text delimiter
A Comma
Any COBOL reserved word
Any Identifier.
Any other sequence of contiguous characters bounded by separators.
Text Word examples
MOVE
1 Text Word
MOVE Total TO Print-Total
4 Text Words - MOVE Total TO Print-Total
MOVE Total TO Print-Total.
5 Text Words - MOVE Total TO Print-Total .
PIC S9(4)V9(6)
9 Text words - PIC S9 ( 4 ) V9 ( 6 )
The COPY verb is generally used when creating large software systems. These systems are subject to a number of problems that the COPY verb helps to alleviate.
For instance, when data files are used by a number of programs in a large software system, it is easy for programmers describing those files to make errors in defining the key fields (Indexed files) or the file organization or the type of access allowed or the number, type and size of the fields in a record. Any errors in these descriptions may result in difficult-to-find bugs. For instance, if one program writes a file using an incorrect record description and the others read it using the correct description, a program crash may occur in in one of the correct subprograms rather than the one which actually has the problem.
Using copy libraries or files helps to reduce programmer transcription errors and also makes implementation simpler by reducing the amount of coding required. For instance, when a number of programs need to access the same file, the relevant file and record descriptions can be copied from a copy library instead of each programmer having to type their own (and possibly get them wrong).
Another advantage of using copy libraries is that they permit item descriptions such as file, record and table descriptions, to be kept and updated centrally in a copy library, often under the control of a copy librarian. This makes it more difficult for programmers to make ad hoc changes to file and record formats. Such changes generally have to be approved by the COPY librarian.
In a large software system using the COPY verb makes some maintenance tasks easier and safer. Certain changes may only require an update to the text in the copy library and a recompilation of any affected programs. If a copy library were not used each affected program would have to be changed
COPY statements in a COBOL program are very different from other COBOL statements. While other statements are executed at run time, COPY statements are executed at compile time.
A COPY statement is similar to the "Include" used in languages like C and C++. It allows programs to include frequently used source code text.
When a COPY statement is used in a COBOL program the source code text is copied into the program from from a copy file or from a copy library before the program is compiled.
A copy file, is a file containing a segment of COBOL code.
A copy library, is a collection code segment each of which can be referenced using a name. Each program that wants to use items described in the copy library uses the COPY verb to include the descriptions it requires.
When COPY statements include source code in a program, the code can be included without change or the text can be changed as it is copied into the program. The ability to change the code as it being included greatly adds to the versatility of the COPY verb.