Tips and Techniques: Dealing with /COPY and Embedded SQL

RPG
Typography
  • Smaller Small Medium Big Bigger
  • Default Helvetica Segoe Georgia Times

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:

/COPY  QRPGLESRC,xtools

New /INCLUDE style:

/INCLUDE QRPGLESRC,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 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:

/INCLUDE  "/xtools/include/rpgxtools.rpgle"

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.

BOB COZZI

Bob Cozzi is a programmer/consultant, writer/author, and software developer. His popular RPG xTools add-on subprocedure library for RPG IV is fast becoming a standard with RPG developers. His book The Modern RPG Language has been the most widely used RPG programming book for more than a decade. He, along with others, speaks at and produces the highly popular RPG World conference for RPG programmers.


MC Press books written by Robert Cozzi available now on the MC Press Bookstore.

RPG TnT RPG TnT
Get this jam-packed resource of quick, easy-to-implement RPG tips!
List Price $65.00

Now On Sale

The Modern RPG IV Language The Modern RPG IV Language
Cozzi on everything RPG! What more could you want?
List Price $99.95

Now On Sale

BLOG COMMENTS POWERED BY DISQUS

LATEST COMMENTS

Support MC Press Online

$

Book Reviews

Resource Center

  •  

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

  • The MC Resource Centers bring you the widest selection of white papers, trial software, and on-demand webcasts for you to choose from. >> Review the list of White Papers, Trial Software or On-Demand Webcast at the MC Press Resource Center. >> Add the items to yru Cart and complet he checkout process and submit

  • SB Profound WC 5536Join us for this hour-long webcast that will explore:

  • Fortra 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: