In rpgle /sqlrpgle code I have come across compiler directives like /INCLUDE and /COPY, can somebody tell me what is the core defference between the two because it seems they pretty much do the same thing.
1 Answers
They differ in the treatment that the RPGPPOPT parameter of CRTSQLRPGI applies to them. See 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.
If one of your SQL statements refers to a host variable defined in another member or defined LIKE a variable in another member, you can use /COPY for that member and /INCLUDE for the others, compiling with RPGPPOPT(*LVL1). This way the preprocessor will know about the variable without having to read the /INCLUDE members that are not useful to it.

- 2,812
- 6
- 16
-
2The documentation for the ILE RPG compiler also explains how these directives are the same for the compiler but different for the SQL precompiler: https://www.ibm.com/docs/en/i/7.4?topic=directives-copy-include and https://www.ibm.com/docs/en/i/7.4?topic=ci-using-copy-include-in-source-files-embedded-sql – Barbara Morris Jun 01 '22 at 16:18