Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"COPY" statement with "REPLACING" in COBOL

I am getting compilation error as,

A "COPY" statement with "REPLACING" phrase was found within a nested "COPY".

This is our compilation setting that we can not use REPLACING verb in nested copy. We have one copybook which is having multiple copy statements with replacing verb. Can anyone help me to resolve this error?

like image 601
Manasi Avatar asked Sep 12 '11 10:09

Manasi


People also ask

What is copy replacing in COBOL?

The REPLACING function allows a programmer to use a single copy file to define multiple data structures of identical format with different field names. Note: The COBOL language also has an INSPECT REPLACING function that is used to replace characters or text strings in a field at program execution time.

What does the replacing option do in a COPY statement?

The COPY statement with REPLACING phrase can be used to replace parts of words. By inserting a dummy operand delimited by colons into the program text, the compiler will replace the dummy operand with the desired text. Example 3 shows how this is used with the dummy operand :TAG: .

What is copy statement COBOL?

The COPY statement is a library statement that places prewritten text in a COBOL compilation unit. Prewritten source code entries can be included in a compilation unit at compile time. Thus, an installation can use standard file descriptions, record descriptions, or procedures without recoding them.

What is the difference between the copy and include COBOL statements?

The main difference between INCLUDE and COPY statement is the PDS member with INCLUDE statement is expanded during pre-compilation while the PDS member with COPY statement is expanded during compilation.


1 Answers

Nesting COPYBOOKS in COBOL is a bit of a trick. In general you may nest copybooks only if they do not contain the REPLACING phrase and do not cause recursion.

Suppose you had the following two copybooks:

COPYBOOK ABC

  01 :A:-VAR-A1     PIC X.
  01 :A:-VAR-A2     PIC X.
  COPY XYZ REPLACING ==:A:== BY ==B==.

and

COBPYOOK XYZ

  01 :A:-VAR-X1     PIC X.
  01 :A:-VAR-X2     PIC X.

The nesting in COPYBOOK ABC is not allowed because it contains a REPLACING phrase.

However, you can do the following. Drop RELACING from COPYBOOK ABC so it becomes:

COPYBOOK ABC

  01 :A:-VAR-A1     PIC X.
  01 :A:-VAR-A2     PIC X.
  COPY XYZ.

Now include COPYBOOK ABC into your source program as follows:

  REPLACE ==:A:== BY ==B==.
  COPY ABC.
  REPLACE OFF.

The REPLACE directive causes all occurances of :A: to be replaced by B until a REPLACE OFF directive is encountered, and these replacements occur after all COPY directives have been actioned. The net result of the above statements would be:

  01 B-VAR-A1     PIC X.    <== from ABC
  01 B-VAR-A2     PIC X.    <== from ABC
  01 B-VAR-X1     PIC X.    <== Nested copy of XYZ from ABC
  01 B-VAR-X2     PIC X.    <== Nested copy of XYZ from ABC

This is the only 'legal' way of performing replacements to nested copybooks in COBOL that I am aware of.

like image 196
NealB Avatar answered Sep 30 '22 12:09

NealB