Search code examples
ibm-midrangerpglerpg

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


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.


Solution

  • 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.