Avoid syntax errors in &IF Verbs of NCL
search cancel

Avoid syntax errors in &IF Verbs of NCL

book

Article ID: 20402

calendar_today

Updated On:

Products

CMDB for z/OS NetSpy Network Performance NetMaster Network Automation SOLVE NetMaster Network Management for SNA NetMaster Network Management for TCP/IP NetMaster File Transfer Management SOLVE:Operations Automation SOLVE:Access Session Management SOLVE:FTS

Issue/Introduction

Introduction:

The condition in a &IF verb can cause a NCL to fail processing. This document explains how you can avoid that and pays special attention to numeric values.

 

Environment

Release: SLOPFC00200-12.1-NetMaster-File Transfer Management
Component:

Resolution

Instructions:

When coding a &IF clause in NCL you use the syntax as described in the NCL Reference Guide:

 	&IF logical expression 	 	    [{AND|OR} logical expression] ... 	
 	&THEN command or statement 

with logical expression being an expression of the form

value1 operator value2

with operator being one of these: EQ, =, NE, ¬=, LT, <, LE, <=, GT, >, GE, >=, NG, ¬>, NL or ¬<.

For example you code

 	&A = MEYER
&IF &A = SMITH &THEN &B = 1

But if the variable &A is empty your NCL will break:

 	&A = 	 	
&IF &A = SMITH &THEN &B = 1

The Error message will be

 	 N03604 INVALID OPERATOR SM FOUND IN &IF STATEMENT.
N23610 PROCEDURE IFTEST NCLID 105228 IN ERROR, STMT NO: 00030000 FOLLOWS: &IF = SMITH
N23601 IFTEST PROCESSING TERMINATED DUE TO ERROR. NCLID 105228

Why? The reason for this is that the NCL-Interpreter expects a logical expression after the "&IF". As &A is empty the variable substitution of NCL translates the line

 &IF &A = SMITH &THEN &DO

into

  &IF = SMITH &THEN &DO

As the Interpreter expects a logical expression of the form "value1 operator value2".

So the '=' is interpreted as the first value and the string 'SMITH' is interpreted as the operator. And as SMITH is not a valid operator the syntax of the &IF is invalid and therefore the NCL ends.

To avoid this problem you can use a dot in front of the two values to be compared:

&IF .&A = .SMITH &THEN &B = 1 

This does not change the logic but avoids the NCL ending if variable &A is empty. Now the instruction reads

&IF . = .SMITH &THEN &DO

if &A is empty. Now there is a valid logical expression '. = .SMITH' after the &IF. 
 
Additional Information:

There is one problem using the dot '.': If you compare numbers the dot might change the logic! Look at this example where a sum is checked of it is larger than 5:

&SUM = 23 	 	&IF .&SUM > .5 &THEN &DO

If you use the dots as in the first example your NCL does not break down but here you changed the logic! While 23 certainly is larger than 5 the same is not true if both numbers are preceeded by a dot: Now .23 > .5 is not true any more! The dot is interpreted as the decimal point and therefore you compare 0.23 and 0.5 with the consequence of having your logic changed totally!

So please use the zero '0' instead of the dot '.' if comparing numeric values in order not to change your logic:

&SUM = 23 	 	&IF 0&SUM > 05 &THEN &DO

This results in 023 > 05 and does not reverse the result of the logical expression.