CA SOLVE

Take care when using &IF in NCLs

  • 1.  Take care when using &IF in NCLs

    Posted 09-18-2013 04:38 AM

    When comparing values in a NCL in an &IF clause take special care.
    It is a good practice to prefix the variables to be compared with a dot '.' to avoid syntax errors. But when comparing numeric values this practice can lead to logical errors as this example shows:

     

    &A = 3
    &B = 25
    &IF .&A < .&B &THEN &DO
    ...
    &DOEND

     

     

     

    As 3 < 25 is true the programming logic should follow the &THEN branch.
    But after variable substitution that &IF looks like

     

     

    &IF .3 < .25 &THEN &DO
    ...
    &DOEND

     

     

    As NCL interpret numbers with a preceeding dot as floating point numbers the logic changes! As 0.3 is greater than 0.25 the logical expression is not true and the &THEN branch is not executed. So please use a zero '0' instead a dot '.' as prefix when comparing numeric values in &IF clauses.