Tips and Techniques Dealing With COPY and Embedded SQL

Embed Size (px)

Citation preview

  • 7/27/2019 Tips and Techniques Dealing With COPY and Embedded SQL

    1/2

    Tips and Techniques: Dealing with /COPY and Embedded SQL

    Contributed by Robert CozziTuesday, 06 July 2004Last Updated Tuesday, 06 July 2004

    /INCLUDE solves problems with the SQL preprocessor.

    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 sourcemember and, in the copied source member, also have another /COPY directive thatcopies in yet another member.

    This capability is supported up to 2,048 levels deep and is controlled withthe COPYNEST keyword on the Header specification. The COPYNEST keyword allowsyou to adjust the default maximum nesting level up or down (the default is32).

    Nested /COPYs are powerful and very useful; however, the popular IBM SQLpreprocessor does not support nested /COPY statements. Therefore, manyapplications and third-party software tools cause the SQL preprocessor togenerate an error during the preprocessor "compile" phase. This can createhours, if not days, of headaches and research for those who run into thisproblem.

    To resolve this problem, IBM introduced the /INCLUDE directive. Thisdirective is unknown to the SQL preprocessor. Since the SQL preprocessor waswritten prior to the introduction of /INCLUDE, this directive simply passesunnoticed through the SQL preprocess phase of the compiler. Here's all you have to do:

    Old /COPY style:/COPYQRPGLESRC,xtools

    New /INCLUDE style:/INCLUDEQRPGLESRC,xtools

    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 copiedsource 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 sourcecode on the IFS and /COPY it into your compiled RPG IV source. Simply specifythe IFS file (including the full path name) enclosed in quotes on the /INCLUDEstatement as follows:/INCLUDE"/xtools/include/rpgxtools.rpgle"

    The quotes are actually double quotes, not the traditional CL-styleapostrophes that you're used to using.

    MC Press Online

    http://www.mcpressonline.com Powered by Joomla! Generated: 6 October, 2008, 00:18

  • 7/27/2019 Tips and Techniques Dealing With COPY and Embedded SQL

    2/2

    Bob Cozzi is a programmer/consultant,writer/author, and software developer of the RPG xTools, a popularadd-on subprocedure library for RPG IV. His book The Modern RPGLanguage has been the most widely used RPG programmingbook for nearly two decades. He, along with others, speaks at and runs thehighly-popular RPGWorld conference for RPG

    programmers.

    MC Press Online

    http://www.mcpressonline.com Powered by Joomla! Generated: 6 October, 2008, 00:18