I agree with Duane. I often see a reason to have a template data structure in a copybook. I generally do this when I have a procedure parameter data structure. I define the DS parm like the template DS. That way any calling modules using the procedure can define its own receiving DS parameter like the template DS as well.
I'll also create any kind of variable/constant that is (potentially) required by both the calling module & service program. More often than not these are constants. (I suppose this would be a good place to use compiler directives for any EXPORT/IMPORT variables, but I haven't used those keywords.)
That said: I know some people create a copybook for prototypes across multiple service programs. I create one copybook per service program.
I also agree with the concept, that I believe Lim mentioned, of anything within these service program copybooks should be named as such so there isn't any conflict with other copybooks.
- Kurt Anderson
-----Original Message-----
From: rpg400-l-bounces@xxxxxxxxxxxx [mailto:rpg400-l-bounces@xxxxxxxxxxxx] On Behalf Of Christen, Duane
Sent: Wednesday, September 23, 2009 12:53 PM
To: RPG programming on the IBM i / System i
Subject: RE: Problem with non QUALIFIED DS
I disagree with Jon, I use only one set of compiler directives, if the copybook name is "RCS0000" and thus the name of the service program is RCS0000 in my environment, the compiler directives would look like:
/If Not Defined(RCS0000)
/Define RCS0000
/Else
/Eof
/EndIf
If this copybook has been copied into the module before by the compiler it will hit the /Eof directive and stop reading/copying the copybook. This prevents you from having 10s or 100s of compiler directives.
The other point is ALL data structures in a copy book should be Qualified and Templates. Pre 6.1 I would do this:
MyDs_t DS Qualified
Based(templateBase)
templateBase would be created by the compiler and would never be used in the code, the compiler will probably eventually throw it away because it is not used, but at worst you would only have 16 bytes of unused storage.
When we went to 6.1 I found all the "Based(templateBase)" strings in copybooks and replace them with "Template".
Duane Christen
--
Duane Christen
Senior Software Engineer
(319) 790-7162
Duane.Christen@xxxxxxxxxx
Visit PAETEC.COM
-----Original Message-----
From: rpg400-l-bounces@xxxxxxxxxxxx [mailto:rpg400-l-bounces@xxxxxxxxxxxx] On Behalf Of Jon Paris
Sent: Wednesday, September 23, 2009 12:16 PM
To: rpg400-l@xxxxxxxxxxxx
Subject: Re: Problem with non QUALIFIED DS
First option - including DS definitions in a proto member s not a terribly good idea unless you are going to incorporate compiler directives. So you could add:
/If not defined (MyDS)
D MyDS E DS extname( myfile)
/Define (MyDS)
/EndIf
Sysntax may not be right but you'll get the picture. Include this in all protos that include the MyDS definition. This ensures you will only get it copied once. You could also replace the definition of MyDS with a /COPY of the MyDS details.
Second option - Use the PREFIX keyword on the MyDS definition to give each copy a unique name.
It all depends on whether you want/need multiple copies of MyDS.
Jon Paris
www.Partner400.com
www.SystemiDeveloper.com
On 23-Sep-09, at 1:00 PM, rpg400-l-request@xxxxxxxxxxxx wrote:
I've just added a prototype via a copybook in my module and it won't
compile because it now has several fields defined more than once.
I discover that I now have 2 prototypes copied in, each one with a
data structure parameter declared like so :
D Parm likeds (myds)
D MyDS E DS extname( myfile)
...
Any thoughts on this? I'm not looking forward to taking time out to
correct this, test it, etc. Maybe there's a work around?
As an Amazon Associate we earn from qualifying purchases.