RPGLE: Conditional Compilation?

351925 pts.
Tags:
AS/400
RPG
RPGLE
This is more of a general question but I'm wondering if I can include a section of code that's based on whether a variable is defined in my program or is the preprocessor completely not able to access this info (only compilation conditions)? This is what I'm looking for:
/IF DEFINED(myVariable)
D myOtherVariable       S                  like(myVariable)
/ELSE
D myOtherVariable       S             20A
/ENDIF
 Does anyone know if this is possible?

Answer Wiki

Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Discuss This Question: 3  Replies

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
  • ToddN2000

    Do you mean something like if variable 1="Y" than compile code Source1 in variable 1="N" then compile Source2? If so you wound have to do it within a CLLE program and condition the CRTOBJ / CRTBNDPGM or what ever it is you are looking to compile.

    You could call this CLLE program from within an RPGLE as well.

    My question would be why would you want to do this? Is the program to be compiled to have the same object name?

    Why not just have 2 programs?

    15,080 pointsBadges:
    report
  • TomLiotta
    No, it can't be done. And since there can be any number of declarations of a variable named 'myVariable' in a module, a pre-compiler couldn't know which one to reference anyway. Only the compiler could know by checking scope of all declarations against the scope of the conditional statement. And the scope of conditional statements can't be known until after they're resolved and fit into surrounding statements. -- Tom
    125,585 pointsBadges:
    report
  • TomLiotta

    BTW, the IF DEFINED statement acts against defined conditions, not against defined variables. If you have an earlier statement that says:

    /define myVariable

    ...then /IF DEFINED(myVariable) would be effective.

    Tom

    125,585 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following