Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In Cobol, to test "null or empty" we use "NOT = SPACE [ AND/OR ] LOW-VALUE" ? Which is it?

Tags:

cobol

I am now working in mainframe, in some modules, to test

Not null or Empty

we see : NOT = SPACE OR LOW-VALUE The chief says that we should do : NOT = SPACE AND LOW-VALUE

Which one is it ?

Thanks!

like image 243
Tom Avatar asked Nov 04 '10 09:11

Tom


People also ask

How do you check if a value is NULL in COBOL?

In Cobol, to test "null or empty" we use "NOT = SPACE [ AND/OR ] LOW-VALUE" ?

WHAT IS NULL value in COBOL?

Many SQL-conversant data sources allow a NULL (empty) value in a data field. COBOL and ACUCOBOL-GT do not recognize or support the NULL value. When the value of a field returned from a query is NULL, the contents of the bound variable are undefined.

Does COBOL have spaces?

SPACE or SPACES: Represents one or more of the character space or blank. SPACE is treated as an alphanumeric literal when used in a context that requires an alphanumeric character. This can be used to handle the blank spaces in the string variables.

Is blank in COBOL?

BLANK WHEN ZERO clause specifies an item filled with spaces when its value is zero. This clause used only for elementary items where its PICTURE clause defined as category numeric-edited or numeric without the symbol S or *.


1 Answers

Chief is correct.

COBOL is supposed to read something like natural language (this turns out to be just another bad joke).

Lets play with the following variables and values:

 A = 1
 B = 2
 C = 3

An expression such as:

IF A NOT EQUAL B THEN...

Is fairly straight forward to understand. One is not equal to two so we will do whatever follows the THEN. However,

IF A NOT EQUAL B AND A NOT EQUAL C THEN...

Is a whole lot harder to follow. Again one is not equal to two AND one is not equal to three so we will do whatever follows the 'THEN'.

COBOL has a short hand construct that IMHO should never be used. It confuses just about everyone (including me from time to time). Short hand expressions let you reduce the above to:

IF A NOT EQUAL B AND C THEN...

or if you would like to apply De Morgans rule:

IF NOT (A EQUAL B OR C) THEN...  

My advice to you is avoid NOT in exprssions and NEVER use COBOL short hand expressions.

What you really want is:

 IF X = SPACE OR X = LOW-VALUE THEN...
    CONTINUE
 ELSE
    do whatever...
 END-IF

The above does nothing when the 'X' contains either spaces or low-values (nulls). It is exactly the same as:

 IF NOT (X = SPACE OR X = LOW-VALUE) THEN
    do whatever...
 END-IF

Which can be transformed into:

 IF X NOT = SPACE AND X NOT = LOW-VALUE THEN...

And finally...

 IF X NOT = SPACE AND LOW-VALUE THEN...

My advice is to stick to simple to understand longer and straight forward expressions in COBOL, forget the short hand crap.

like image 162
NealB Avatar answered Oct 21 '22 05:10

NealB