views:

145

answers:

2

Can I include a section of code based on whether a variable is defined in my program, or is the preprocessor completely unable to access this information, only compilation conditions? I.e. I'm after something like:

/IF DEFINED(myVariable)
D myOtherVariable       S                  like(myVariable)
/ELSE
D myOtherVariable       S             20A
/ENDIF

This link appear to suggest it is not possible. If so does anyone know of another way to achieve this?

+3  A: 

It would be a nice feature to have, but unfortunately, it doesn't work that way today. The value in parenthesis after DEFINED must be a defined condition name, not a variable name. The way to make it work is to have a /DEFINE directive whenever you define that specific variable in any of programs or copybooks. It all depends on usage for these situations as far as whether or not this is a recommended practice.

The link provided in your question is spot-on and I agree with the conclusions.

Tracy Probst
Yes, I've been reading more since posting your question and agree with your agrement.
nearly_lunchtime
+1  A: 

As an additional hint, use C programming books for this subject, not the IBM RPGLE books. The IBM books describe what can be done with directives. The C books describe how it is used in real world programs (e.g. Linux open source programs). Following that style makes your RPG sources much more readable for other programmers.

robertnl