One of the most frequently asked questions I get is how to use the nested /COPY feature in RPG IV. This feature allows you to use /COPY to copy a source member and, in the copied source member, also have another /COPY directive that copies in yet another member.
This capability is supported up to 2,048 levels deep and is controlled with the COPYNEST keyword on the Header specification. The COPYNEST keyword allows you to adjust the default maximum nesting level up or down (the default is 32).
Nested /COPYs are powerful and very useful; however, the popular IBM SQL preprocessor does not support nested /COPY statements. Therefore, many applications and third-party software tools cause the SQL preprocessor to generate an error during the preprocessor "compile" phase. This can create hours, if not days, of headaches and research for those who run into this problem.
To resolve this problem, IBM introduced the /INCLUDE directive. This directive is unknown to the SQL preprocessor. Since the SQL preprocessor was written prior to the introduction of /INCLUDE, this directive simply passes unnoticed through the SQL preprocess phase of the compiler. Here's all you have to do:
Old /COPY style:
New /INCLUDE style:
Aside from SQL's ignoring /INCLUDE, it functions exactly like /COPY. In fact, there's no reason to continue to use /COPY at all unless you need the copied source to be used by the SQL preprocessor. But even in that case, you can embed a nested /INCLUDE in a source member that is /COPYed into another source member. The SQL preprocessor sees and processes the /COPY while it ignores the nested /INCLUDE.
As a side note, both /COPY and /INCLUDE allow you to store and include source code on the IFS and /COPY it into your compiled RPG IV source. Simply specify the IFS file (including the full path name) enclosed in quotes on the /INCLUDE statement as follows:
The quotes are actually double quotes, not the traditional CL-style apostrophes that you're used to using.
Bob Cozzi is a programmer/consultant, writer/author, and software developer of the RPG xTools, a popular add-on subprocedure library for RPG IV. His book The Modern RPG Language has been the most widely used RPG programming book for nearly two decades. He, along with others, speaks at and runs the highly-popular RPG World conference for RPG programmers.



Business users want new applications now. Market and regulatory pressures require faster application updates and delivery into production. Your IBM i developers may be approaching retirement, and you see no sure way to fill their positions with experienced developers. In addition, you may be caught between maintaining your existing applications and the uncertainty of moving to something new.
IT managers hoping to find new IBM i talent are discovering that the pool of experienced RPG programmers and operators or administrators with intimate knowledge of the operating system and the applications that run on it is small. This begs the question: How will you manage the platform that supports such a big part of your business? This guide offers strategies and software suggestions to help you plan IT staffing and resources and smooth the transition after your AS/400 talent retires. Read on to learn:
LATEST COMMENTS
MC Press Online