Page 1 of 1

how to find string is null

PostPosted: Wed Jul 16, 2008 1:03 pm
by mohd dalib
hi
how to find that a string
strng pic x(10).
contains no char.


through finding length of the string we can find out that the string contains no character in it.i.e null string
but is there any other way to find it out? that sting variable contains no character.

Re: how to find string is null

PostPosted: Wed Jul 16, 2008 2:02 pm
by jayind
Hi mohd dalib,

In COBOL,
I hope you know the difference between a NULL and a SPACE.. Alphanumeric variables usually will have spaces but not nulls to my knowledge..Numeric variables can have nulls. Anyway, if you want to check for spaces you can check directly VAR = SPACES (HEX equivalent of a SPACE is X'40'), if you want to check for nulls "VAR = LOW-VALUES" (it is equivalent to null value having HEX value X'00').

Hope this helps...

Regards,
Jayind

Re: how to find string is null

PostPosted: Thu Jul 17, 2008 1:00 am
by dick scherrer
Hello,

how to find that a string
strng pic x(10).
contains no char.
What you ask cannot really be done - every value from x'00' to x'FF' is "a char" and every PIC X byte will contain a value between x'00' and x'FF'.

There is no such thing as a NULL in a pic x field. You can test if some specific value(s) exist or do not exist.

If you clarify what you want to do, we can probably offer suggestions.

Re: how to find string is null

PostPosted: Fri Jul 18, 2008 7:52 pm
by ranga_subham
Dick, you say that there is no such thing as "NULLS" or "BLANKS". Is this pertaining to COBOL only :?:

I remember using the check such as variable = spaces or not !!

If so, why do we use NOT NULL while creating DB2 fields for tables :?

Thanks.

Re: how to find string is null

PostPosted: Fri Jul 18, 2008 8:15 pm
by dick scherrer
Hello,

Dick, you say that there is no such thing as "NULLS" or "BLANKS".
You just made a very wrong quantum leap. . . There probably should never be a thought that has "null" and "blank" together - they have nothing to do with each other. . . Simply said (again) - there is no such thing as a null in a pic x field.

If someone in your organization wants to call a space a null, that is just ignorant. They need to learn that a space (x'40') is not a null (which by definition has no value).

I remember using the check such as variable = spaces or not !!
Sure you do - we all do that. When we do that, we are not checking for null we are checking for some number of x'40's.

If so, why do we use NOT NULL while creating DB2 fields for tables
Some database management systems support the null concept - some do no. When you check for "null" or "not null" the comparison has nothing to do with spaces/blanks.

Re: how to find string is null

PostPosted: Fri Jul 18, 2008 8:28 pm
by ranga_subham
Thanks for explaining it.

Still some confusion bothers me. Let me try to put it in lines some time later.

Bye.

Re: how to find string is null

PostPosted: Fri Jul 18, 2008 10:01 pm
by dick scherrer
Hello,

You're welcome :)

Someone should be here when you organize/post what you want clarified.