simple question, preprocessor directives

whwar9739

Member
Here is a high level of what I want to do but can't seem to get it to work correctly.

IF {&var} = "asdfasdf"
then
code
else
code

My problem is I tried using the preprocessor &IF, doesn't like using the preprocessor argument.
I try using the progress if, then, else and I can't figure out how to make the if statement look at the preprocessor argument as a charater.

Any help would be great.

Thanks,
 
config.i:
&IF DEFINED(SCM) = 0 &THEN
&GLOBAL-DEFINE SCM "YES"
&ENDIF

&IF DEFINED(ECR) = 0 &THEN
&GLOBAL-DEFINE ECR "NO"
&ENDIF

&IF DEFINED(COURIER) = 0 &THEN
&GLOBAL-DEFINE COURIER "NO"
&ENDIF
....

code

{config.i}

....

&IF {&SCM} = 'YES' &THEN
connect value ( "dba/scm.db" ) -ld scm no-error.
&ENDIF
 

whwar9739

Member
Here is the code as I have it in my include file:

Code:
&IF {&tbl} = 'tablename' &THEN
   DEF STREAM slo-table1.
   OUTPUT STREAM slo-table1 TO table1.d.
&ELSE
   DEF STREAM slo-{&tbl}.
   OUTPUT STREAM slo-{&tbl}.
&ENDIF

Here is the code from my main program:

Code:
{include.i &tbl = "tablename"}

With this I get the following error "Invalid use of nonconstant elements in preprocessor expression. (2965)"

The real issue is I have one instance where the table name plus the slo- is over the 12 character limit for stream names. So I was going to 'hard code' a stream name for this one table.
 

Stefan

Well-Known Member
Since you want to use the preprocessor value as something 'real', you need to drop the quotes in the including .p - you also, since you are combining the preprocessor value directly, need to drop extra spaces.

Code:
{ include.i &tbl=tablename }

Code:
&IF '{&tbl}' = 'tablename' &THEN
   DEF STREAM slo-table1.
   OUTPUT STREAM slo-table1 TO table1.d.
&ELSE
   DEF STREAM slo-{&tbl}.
   OUTPUT STREAM slo-{&tbl}. 
&ENDIF

Note that you can easily debug errors like this by preprocessing the file (compile with preprocess option).
 
Dude,
Close but no cigar with what U are trying to do.
As you have declared you would like this functionality.
IF {&var} = "asdfasdf"
then
code
else
code

The 4GL isn`t able to read what you are trying to action, simply make this ammendment to your syntax:
IF "{&var}" = "asdfasdf"
then
code
else
code
Did you notice the alteration? I will point it out for you:
IF "{&var}" = "asdfasdf"
You are attempting to compare strings. IF "PREPROCESSOR" = "WHATEVER STRING"
Good look.
I can`t believe nobody else noticed, sending U off on a goose chase
 
Goosw chase

Greetings.

Indeed the answer above mine detailed the same thing.
Though it was encapsulated within a preprocessor if statement.
I simply broke it down to basic 4GL and explained the solution instead of burying it within other directives ie. Preprocessed if statement
BFN
 
Top