Preprocessor IF-ELSE and Variable Definitions

I'm getting spiritually drained trying to get this to work and researching why it doesn't, so I thought I'd just ask if anyone knows.

Basically, I want to setup a testing flag to help make sure test files don't get FTP'd off to a production server and cause trouble.

Later in my code, I use &IF DEFINED to set the FTP parameters to the correct server. Works as it should.

However, I want to save some trouble and have the flag be one-stop shopping when it comes to turning on/off the testing situation. No more forgetting to comment out something critical in the middle of the code, but this should also replaces the standard "comment out the input vars and uncomment the testing vars" drudgery with something like this:

Code:
/* Uncomment to use Testing variables and parameters */
DEF VAR NowTesting AS LOG NO-UNDO.
 
&IF DEFINED(NowTesting) <> 0 &THEN
    DEF VAR v-plant    AS CHAR FORMAT "x(4)"  INIT "1111"        NO-UNDO.
    DEF VAR v-item-nbr AS CHAR FORMAT "x(15)" INIT "12345678"    NO-UNDO.
    DEF VAR v-qty      AS INT                 INIT 1             NO-UNDO.
    DEF VAR v-job-type AS CHAR FORMAT "x(4)"  INIT "XXX"         NO-UNDO.
    DEF VAR v-job-nbr  AS CHAR FORMAT "x(25)" INIT "123456789"   NO-UNDO.
&ELSE
    DEF INPUT PARAMETER v-plant    AS CHAR FORMAT "x(4)"  NO-UNDO.
    DEF INPUT PARAMETER v-item-nbr AS CHAR FORMAT "x(15)" NO-UNDO.
    DEF INPUT PARAMETER v-qty      AS INT                 NO-UNDO.
    DEF INPUT PARAMETER v-job-type AS CHAR FORMAT "x(4)"  NO-UNDO.
    DEF INPUT PARAMETER v-job-nbr  AS CHAR FORMAT "x(25)" NO-UNDO.
&ENDIF

When running, it seems to be acting like the input parameter vars are both defined and not defined. It compiles fine (which wouldn't happen if variables are defined twice), but when running it errors out saying that the wrong number of parameters were passed to the program.

What do I not understand? I don't use preprocessors all the time, but what is the point of &IF-&ELSE if it doesn't 'take' all the time?
 

TomBascom

Curmudgeon
You're doing it wrong.

You don't use a variable for the IF DEFINED, you use a pre-processor name. Like this:
Code:
&SCOPED-DEFINE PublicVersion 1
&IF DEFINED(PublicVersion) > 0
&THEN
...
&ELSE
...
&ENDIF
 
Well, thanks for the quick answer!

Missed this tiny bit in the reference about "expression":
Code:
[FONT=LucidaSansTypewriter][SIZE=1][SIZE=1][FONT=LucidaSansTypewriter]&IF [/FONT][/SIZE][/SIZE][/FONT][I][FONT=LucidaSansTypewriter-Obl][SIZE=1][FONT=LucidaSansTypewriter-Obl][SIZE=1]expression [/SIZE][/FONT][/SIZE][/FONT][/I][FONT=LucidaSansTypewriter][SIZE=1][FONT=LucidaSansTypewriter][SIZE=1]&THEN ..... [/SIZE][/FONT][/SIZE][/FONT]

expression:

An expression that can contain preprocessor name references, the operators listed in Table 6, the ABL functions listed in Table 7, and the DEFINED( ) preprocessor function.
I guess I've always played with legacy code and never set it up from scratch before in all these years.​
 

lord_icon

Member
Preprocessor expression

Using the syntax you supplied:
&IF expression &THEN ...

Interpret expression to mean / imply simply condition.
Think the statement is just simply saying, 'IF this occurs, THEN do this'.
But it is wrapped in the preprocessor formant.
Hope this helps you work out what is happening.
 
Top