COBOL 中是否允许嵌套的抄写本?

Are nested copybooks allowed in COBOL?

我知道许多 COBOL 编译器确实允许嵌套副本(具有不同的深度),但我没有找到任何 "official" 规则。 问题:

  1. 是否有明确允许或禁止嵌套字帖的 COBOL 标准?

  2. 有没有不允许嵌套copybooks的COBOL编译器?

可以在主程序中使用COPY REPLACING插入字帖

您可以在字帖中使用COPY REPLACING,将其他字帖复制到字帖中。

所以,是的,允许嵌套抄写本。所以 COBOL 编译器允许这样做。 它们在实践中出现的次数不多,但确实会出现。

标准(2010年草案)有7.2.2.3 13)

实施应支持至少 5 层的嵌套,包括序列中的第一个 COPY 语句。正在复制的库文本不应导致处理直接或间接复制自身的 COPY 语句。

但是 11) 12) 和 14) 提到了对这些嵌套书籍的限制,不包括任何 REPLACING 短语,或者替换包括 COPY。这一切都是有道理的,因为单个 COPY 语句并不意味着递归,而是可以在处理过程中封装其他 COPY 语句。

标准允许嵌套副本,但不允许在 REPLACING 子句中提及或操纵任何 COPY 语句。从标准 COPY 语句,一般规则 11 到 14(COBOL 2014 7.2.2.3,在 COBOL 2002 7.1.2.3 中相同):

  1. If the REPLACING phrase is specified, the library text shall not contain a COPY statement.
  2. ...
  3. If the REPLACING phrase is not specified, the library text may contain a COPY statement that does not include a REPLACING phrase. The implementation shall support nesting of at least 5 levels, including the first COPY statement in the sequence. The library text being copied shall not cause the processing of a COPY statement that directly or indirectly copies itself.
  4. The replacing action of a COPY statement shall not introduce a COPY statement, a SOURCE FORMAT directive, a comment or a blank line.