How to Write IF Conditions Correctly ( And Vs. Or)

In COBOL, IF condition is popular. Here is the best way to use ‘and’/ ‘or’ conditions. If you don’t give parenthesis correctly, the condition may not work as expected. Recently I have faced the same problem.

Here is My Best Suggestion How to Use conditions

IF abc > 'HI'
and mfg = '10' or '20' '20'
do-this
END-IF.

The above logic will not work correctly since its parenthesis not correct. When you would need to use ‘or’ follow the below way:

IF (abc > 'HI')
and (mfg = '10' or '20' '20')
do-this
END-IF.

The other way you can write as:

IF abc > 'HI'
and (mfg = '10' or '20' '20')
do-this
END-IF.

The other best example

IF (abc > 'HI')
or (mfg_unit = 'HYD')
do-this
END-IF.

Related posts

Discover more from Srinimf

Subscribe now to keep reading and get access to the full archive.

Continue reading

Discover more from Srinimf

Subscribe now to keep reading and get access to the full archive.

Continue reading