enskill.com iSeries Training Onsite classes
DVD training
Books
Online e-Learning
Home
Resources
Contact
(c)2002-2008

This page is powered by Blogger. Isn't yours? Bryan's RPG IV Journal


Using /COPY for Prototypes


Q. You've recommended placing prototype (PR) definitions in copybook(s), then using /COPY to copy the prototypes into the modules that need them. At our company, some programmers place not only the prototypes in copybooks but also the procedure interface (PI) definitions too. Could there ever be a good reason to do this? Here's an example of a copybook:
 /If Defined(GetInterest_Pr)    
D GetInterest PR
D @@DSName 10 Const
D @@DSPtr *
D CIRulesPtr *
/Endif

/If defined ( GetInterest_Pi )
// ----------------------------------------
// Function : get Interest Info
// ----------------------------------------
P GetInterest B Export
D PI
D @@DSName 10 Const
D @@DSPtr *
D CIRulesPtr *
/Endif
A. Putting PR definitions in a /COPY member makes sense because the PR must be in every compile unit that refers to a procedure. But the PI definition needs only to be in one place -- the procedure's compile unit itself.

You might get a small maintenance advantage of having both definitions in the same /COPY member. But storing both definitions in the same /COPY member requires the added complexity of conditional compilation (and your example includes the beginning P-spec for the procedure, but not the ending one, which I find confusing), and I would discourage it.

Unless you're using the procedure's source member itself as the /COPY member, then using conditional compilation to copy only the PR definitions. Then, I can see the advantage. Here's an example (using your code):
 /If Not Defined(PR_Only)
H Nomain
/Endif

/If Not Defined(GetInterest_Parms)
// -------------------------------------- GetInterest Prototype
D GetInterest Pr
D @@DSName 10 Const
D @@DSPtr *
D CIRulesPtr *
/Define GetInterest_Parms
/If Defined(PR_Only)
/Eof
/Endif
/Endif

// ------------------------------------------------------------
// Procedure: GetInterest
// Function: Get interest information
// ------------------------------------------------------------

P GetInterest B Export
D PI
D @@DSName 10 Const
D @@DSPtr *
D CIRulesPtr *

// ... (The rest of the procedure)

P GetInterest E
Then, in every module that uses GetInterest, you'd include /COPY statements along the following lines:
 /Define PR_Only
/Copy GetInterest
// ... More /COPY statements to other procedures
/Undefine PR_Only
This technique keeps the prototype in the module where it's used so it doesn't require an extra source member to be maintained. It also facilitates useful "piggybacking" of structures needed for the call.


Log of Journal Entries

Use this scrollable blog map to view other journal entries:
Journal Home
It is your responsibility to ensure procedures, techniques, and code used from this website are accurate and appropriate for your installation. No warranty or support is implied or expressed.
E-mail to Bryan Meyers
Privacy and Email Policy
 
AS/400®, eServer, i5/OS, IBM i, Integrated Language Environment®, iSeries, OS/400®, RPG/400®, System i5, VisualAge®, and WebSphere® are trademarks of IBM Corporation. Note: IBM® System i is the latest member of the family of eServer iSeries. This site might refer to System i as System i5, iSeries, or AS/400.
 

If you are having trouble navigating the menu at the top of this page, you may use the following scrollable site map instead:
 

Self-paced DVD Training
DVD: RPG IV for RPG Programmers
DVD: RPG IV Modules, Procedures, and Service Programs
 
In association with Amazon.com
Programming in RPG IV
RPG IV Jump Start
Power Tips for RPG IV
Control Language Programming for the AS/400
VisualAge for RPG by Example
 
International visitors: click hereInternational visitors:
Click here!