1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

simple question, preprocessor directives

Discussion in 'Development' started by whwar9739, Jul 16, 2010.

  1. whwar9739

    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,
     
  2.  
  3. MaximMonin

    MaximMonin Member

    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
     
  4. whwar9739

    whwar9739 Member

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

    Code (progress):
    1.  
    2. &IF {&tbl} = 'tablename' &THEN
    3.    DEF STREAM slo-table1.
    4.    OUTPUT STREAM slo-table1 TO table1.d.
    5. &ELSE
    6.    DEF STREAM slo-{&tbl}.
    7.    OUTPUT STREAM slo-{&tbl}.
    8. &ENDIF
    9.  
    Here is the code from my main program:

    Code (progress):
    1.  
    2. {include.i &tbl = "tablename"}
    3.  
    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.
     
  5. Stefan

    Stefan Active 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 (progress):
    1.  
    2. { include.i &tbl=tablename }
    3.  
    Code (progress):
    1.  
    2. &IF '{&tbl}' = 'tablename' &THEN
    3.    DEF STREAM slo-table1.
    4.    OUTPUT STREAM slo-table1 TO table1.d.
    5. &ELSE
    6.    DEF STREAM slo-{&tbl}.
    7.    OUTPUT STREAM slo-{&tbl}.
    8. &ENDIF
    9.  
    Note that you can easily debug errors like this by preprocessing the file (compile with preprocess option).
     
  6. mjpowellesq

    mjpowellesq New Member

    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
     
  7. Stefan

    Stefan Active Member

    Which is indeed hard to believe, especially since the post above yours already has the quotes and is sending no one on a wild goose chase.
     
  8. mjpowellesq

    mjpowellesq New Member

    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
     

Share This Page