COBOL Manual for TNS/E Programs (H06.08+, J06.03+)
77 AVG-MONTHLY-COST PIC S9(8).99.
77 AVG-ANNUAL-COST PIC S9(8).99.
Compare the preceding example to the example in Replacing Substrings.
Replacing Text-Words From COPY Libraries
The compiler processes REPLACE statements after it has processed any COPY statements. REPLACE
statements do not change COPY libraries.
In Example 239, the compiler substitutes OFFICES for COPY OFFNUM and SQ-FT-SIZE for COPY
AREA first and then substitutes 10 for OFFICES and 5 for SQ-FT-SIZE.
Example 239 Replacing Text-Words From a COPY Library
Source code:
REPLACE ==OFFICES== BY ==10==
==SQ-FT-SIZE== BY ==5==
01 OFFS.
03 OFFICE-INFO OCCURS COPY OFFNUM. TIMES.
05 DISTRICT PICTURE 99.
05 SQUARE-FEET PICTURE S9(COPY AREA.)
REPLACE OFF
Lines in default COPY library:
?SECTION OFFNUM
OFFICES
?SECTION AREA
SQ-FT-SIZE
Resulting source code (COPY library is unchanged):
01 OFFS.
03 OFFICE-INFO OCCURS 10 TIMES.
05 DISTRICT PICTURE 99.
05 SQUARE-FEET PICTURE S9(5).
If the COPY statement has a REPLACING phrase, the compiler applies the REPLACING phrase
before applying the REPLACE statement. For an example of a COPY statement with a REPLACING
phrase, see Copying With Replacement.
Replacing Text-Words From SOURCE Libraries
If a REPLACE statement is active when the compiler encounters a SOURCE directive, the REPLACE
statement applies to the copy of the library text that the compiler includes in the HP COBOL source
program (but not to the original text in the SOURCE library).
Example 240 Replacing Text-Words From a SOURCE Library
Source code:
REPLACE ==OFFICES== BY ==10==
==SQ-FT-SIZE== BY ==5==
?SOURCE SRCFILE
REPLACE OFF
Lines in SOURCE library:
01 OFFS.
03 OFFICE-INFO OCCURS OFFICES TIMES.
05 DISTRICT PICTURE 99.
05 SQUARE-FEET PICTURE S9(SQ-FT-SIZE).
Resulting source code (SOURCE library is unchanged):
768 Creating and Compiling HP COBOL Source Programs










