Both commands will suck in program source code from a copybook – typically stored in QCPYLESRC. But there is one big difference between how the compile directives work in RPGLE and SQLRPGLE programs : in RPG ILE programs the /copy directive is expanded by sql preprocessor, but /include does not get expanded by SQLRPGLE code.
RPGSQL is a little more precise on its compiles thats why!
Your RPG SQL Source code and include copybooks. These copybooks can copy in other copybooks. Which can suck in yet more copybooks. These are called levels and we can specify how many levels we want to allow using a precompile option.
CRTSQLRPGI has a parameter called RPGPPOPT which defines how many levels deep any copybooks will go through to suck in copybook source code.
The screen is a little confusing:
Help for this says:
Specifies if the ILE RPG compiler will be called to preprocess the source member before the SQL precompile is run. Preprocessing the SQL source member will allow some compiler directives to be handled before the SQL precompile. The preprocessed source will be placed in file QSQLPRE in QTEMP. This source will be used for the SQL precompile.
The compiler is not called for preprocessing.
The compiler is called for preprocessing to expand /COPY and handle the conditional compilation directives except the /INCLUDE directive.
The compiler will be called for preprocessing to expand /COPY and /INCLUDE and handle the conditional compilation directives.
OK, lets try to write this in a more waffley version of English- by default, creating a SQL module or program will only suck in one copybook if you use /include but will suck in all embedded copybooks if you use /copy (when I say embedded i mean if a copybook #1 also has more /copy statements to pull in more code from copybook #2 which might have even more to pull in from copybook #3 and so on).
/copy and /include copybook code is “pulled” into the source by the compiler before executing the compile, this eliminates having to duplicate the code a million times over (but I mainly use for prototypes, data structures…not calculations!).
/define is used to segregate code in copybooks (or skip code depending on usage).
/copy and /include both are used to add program source code to RPGLE and SQLRPGLE programs.
RPGLE use either /INCLUDE or /COPY SQLRPGLE use /COPY
Why? The /COPY and /INCLUDE directives have the same purpose and the same syntax, but are handled differently by the SQL precompiler. SQL will check the RPGPPOPT parameter to see how deep it can go but RPG will always load all from multiple levels. This can lead to some head scratching moments… I know it has for me.
So, if writing SQL RPG with /include then check the RPGPPOPT parameter. Or just use /copy and dont worry about it 🙂
IBM i Software Developer, Digital Dad, AS400 Anarchist, RPG Modernizer, Alpha Nerd and Passionate Eater of Cheese and Biscuits. Nick Litten Dot Com is a mixture of blog posts that can be sometimes serious, frequently playful and probably down-right pointless all in the space of a day. Enjoy your stay, feel free to comment and in the words of the most interesting man in the world: Stay thirsty my friend.
IBM R.P.G. Programming – Source /COPY RPG Copybooks
What is IBM i Email and SPF?
Updating Numeric DTAARA in RPGLE
How to capture IBM-i job info for submitted jobs
Register license key in SOFTLANDING SOFTMENU
Going the (Levenshtein) Distance in RPG Free
Don’t hardcode library names in your TURNOVER SQL source #youbigsilly
How to Install IBM Access Client Solutions (ACS)
5733XJ1 IBM i Access Client Solutions – QuickStartGuide