“复制”带有“REPLACING”的语句在COBOL中

发布于 2024-12-04 06:23:14 字数 149 浏览 1 评论 0原文

我收到编译错误,因为

在嵌套的“COPY”中找到了带有“REPLACING”短语的“COPY”语句。

这是我们的编译设置,我们不能在嵌套副本中使用 REPLACING 动词。 我们有一本抄写本,其中有多个带有替换动词的复制语句。 谁能帮我解决这个错误?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

沒落の蓅哖 2024-12-11 06:23:14

在 COBOL 中嵌套 COPYBOOKS 是有一点技巧的。一般来说
仅当不存在时才可以嵌套习字簿
包含 REPLACING 短语并且不会导致递归。

假设您有以下两个字帖:

COPYBOOK ABC

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

COBPYOOK XYZ

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

不允许在 COPYBOOK ABC 中嵌套,因为它包含 REPLACING 短语。

但是,您可以执行以下操作。从 COPYBOOK ABC 中删除 RELACING 这样
它变成:

COPYBOOK ABC

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

现在将 COPYBOOK ABC 包含到源程序中,如下所示:

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

REPLACE 指令会导致所有出现 :A:
B 替换,直到遇到 REPLACE OFF 指令,并且这些
替换发生在所有 COPY 指令执行后。网
上述语句的结果将是:

  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

这是执行嵌套抄写本替换的唯一“合法”方式
据我所知,在 COBOL 中。

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.

清欢 2024-12-11 06:23:14

虽然 Neal 的答案对于他和 OP 正在使用的 Cobol 变体来说可能是正确的,但值得注意的是,一些 Cobol 编译器将允许嵌套 COPY ... REPLACING 语句。

事实上,我们有很多在代码中使用它的实例。

例如,我有许多 Cobol 模块程序,其中包含以下方式的复制成员:

COPY 'uwxxxxsel.prg' REPLACING
             LEADING "xxxxSEL" BY "AREASEL".

并且“uwxxxxsel.prg”复制成员包含另一个文件的以下 COPY,如下所示:

COPY 'uwf8list.prg'
       REPLACING LEADING 'XXXXXX-F8-' BY 'SELECT-F8-'
                 ==FUNCTION-KEY== BY ==F8-FUNCTION-KEY==.

并且效果很好。

我将其用作通用功能的一种“继承”结构。

不过,我们的编译器有一个问题。更高级别的REPLACING在嵌套的REPLACING之后不会继续,但是只要嵌套的REPLACING是copymember中的最后一个东西,它就是美好的。

While Neal's answer may be correct for the Cobol variant he and the OP are using, it is worth noting that some Cobol compilers will allow nested COPY ... REPLACING statements.

Indeed we have many instances where we use this in our code.

For example, I have many Cobol module programs that include a copymember in the following way:

COPY 'uwxxxxsel.prg' REPLACING
             LEADING "xxxxSEL" BY "AREASEL".

and the 'uwxxxxsel.prg' copymember contains the following COPY of another file as follows:

COPY 'uwf8list.prg'
       REPLACING LEADING 'XXXXXX-F8-' BY 'SELECT-F8-'
                 ==FUNCTION-KEY== BY ==F8-FUNCTION-KEY==.

and this works fine.

I use this as a kind of 'inheritance' structure for common functionality.

There is one gotcha, though, with our Compiler. The higher level REPLACING does not continue after the nested REPLACING, but as long as the nested REPLACING is the last thing in the copymember, it is fine.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文