rpgle(sqlrpgle) 中的编译器指令 /Include 和 /copy 之间的区别

Difference between compiler directive /Include and /copy in rpgle(sqlrpgle)

在 rpgle /sqlrpgle 代码中,我遇到过像 /INCLUDE 和 /COPY 这样的编译器指令,有人能告诉我两者之间的核心差异是什么吗,因为看起来它们几乎做同样的事情。

它们的区别在于 CRTSQLRPGI 的 RPGPPOPT 参数适用于它们的处理方式。参见 docs

When the value is *LVL1, the RPG preprocessor will be called to preprocess the RPG source. All /COPY statements are expanded, even nested /COPY statements, and the conditional compilation directives will be handled.

When the value is *LVL2, the RPG preprocessor will be called to preprocess the RPG source. All /COPY and /INCLUDE statements are expanded and the conditional compilation directives will be handled.

如果您的 SQL 语句之一引用在另一个成员中定义的主机变量或在另一个成员中定义的 LIKE 变量,您可以对该成员使用 /COPY,对其他成员使用 /INCLUDE,编译时使用RPGPPOPT(*LVL1)。这样预处理器就可以知道变量,而不必读取对它没有用的 /INCLUDE 成员。