Difference between revisions of "Slash COPY"
DaveLClarkI (talk | contribs) |
DaveLClarkI (talk | contribs) |
||
(8 intermediate revisions by the same user not shown) | |||
Line 17: | Line 17: | ||
For example (in the copy member): | For example (in the copy member): | ||
<pre> | <pre> | ||
− | /IF NOT DEFINED < | + | ...anything here is included regardless... |
− | /DEFINE < | + | /IF NOT DEFINED <somenamevalue> |
− | + | /DEFINE <samenamevalue> | |
+ | ...code here not included second time... | ||
/ENDIF | /ENDIF | ||
+ | ...anything here is included regardless... | ||
</pre> | </pre> | ||
Thus, if the member is copied in more than once, the code that is in the member will only be actually included once. | Thus, if the member is copied in more than once, the code that is in the member will only be actually included once. | ||
− | To exclude the entire member | + | To exclude the entire member when referenced a second time, you can use [[Slash EOF|/EOF]] as follows (at the top of the copy member). |
<pre> | <pre> | ||
− | / | + | /if defined <somenamevalue> |
− | / | + | /eof |
− | / | + | /endif |
− | / | + | /define <samenamevalue> |
− | ...code here... | + | ...code here not included second time... |
</pre> | </pre> |
Latest revision as of 22:31, 6 December 2018
/copy members are a way to include other source members in a RPG program.
They are quite often used to pull in external descriptions, such as Procedures or Data Structures.
The syntax for a /copy is:
/COPY [[<library>/]<source file>,]<member>
If the library isn't specified, then the library list will be searched.
If the source file isn't specified, then the source file the program is being compiled from will be used.
Often /IF, /DEFINE, and /ENDIF are used in the copied source member to conditionally define source so that source lines are not duplicated.
For example (in the copy member):
...anything here is included regardless... /IF NOT DEFINED <somenamevalue> /DEFINE <samenamevalue> ...code here not included second time... /ENDIF ...anything here is included regardless...
Thus, if the member is copied in more than once, the code that is in the member will only be actually included once.
To exclude the entire member when referenced a second time, you can use /EOF as follows (at the top of the copy member).
/if defined <somenamevalue> /eof /endif /define <samenamevalue> ...code here not included second time...