IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Checking for a null value in cobol


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
bibek24

New User


Joined: 14 Aug 2007
Posts: 35
Location: Hyderabad

PostPosted: Thu Jun 12, 2008 7:38 pm
Reply with quote

Hi all,

I have a feild[9(2)] in an i/p file which is null means an invalid feild for certain number of records in the file.

When I am directly moving it to the feild[S 9(4) COMP] in the O/P file,its populating as 0 instead of blank(as in the I/P).

But I want the O/P as same as I/P because it has to be stored in a table as null value instead of 0.

Moreover I also need to check the feild if it is not null,so that I can count the number of records having not null values for the particular feild.

Please suggest me what to do?
Back to top
View user's profile Send private message
srj1957

New User


Joined: 15 Dec 2005
Posts: 72
Location: RALEIGH NC, USA

PostPosted: Thu Jun 12, 2008 9:21 pm
Reply with quote

bibek24 wrote:
Hi all,

I have a feild[9(2)] in an i/p file which is null means an invalid feild for certain number of records in the file.

When I am directly moving it to the feild[S 9(4) COMP] in the O/P file,its populating as 0 instead of blank(as in the I/P).

But I want the O/P as same as I/P because it has to be stored in a table as null value instead of 0.

Moreover I also need to check the feild if it is not null,so that I can count the number of records having not null values for the particular feild.

Please suggest me what to do?


We usually code
Code:
IF WS-FIELD = LOW-VALUES




LET ME KNOW IF IT WORKS
Back to top
View user's profile Send private message
srj1957

New User


Joined: 15 Dec 2005
Posts: 72
Location: RALEIGH NC, USA

PostPosted: Thu Jun 12, 2008 9:40 pm
Reply with quote

bibek24 wrote:
Hi all,

I have a feild[9(2)] in an i/p file which is null means an invalid feild for certain number of records in the file.

When I am directly moving it to the feild[S 9(4) COMP] in the O/P file,its populating as 0 instead of blank(as in the I/P).

But I want the O/P as same as I/P because it has to be stored in a table as null value instead of 0.

Moreover I also need to check the feild if it is not null,so that I can count the number of records having not null values for the particular feild.

Please suggest me what to do?


To check for NULLS we usually code

Code:
IF WS-FIELD = LOW-VALUES


To check for NOT NULL we usually code

Code:
IF WS-FIELD > LOW-VALUES



LET ME KNOW IF IT WORKS
Back to top
View user's profile Send private message
enrico-sorichetti

Superior Member


Joined: 14 Mar 2007
Posts: 10873
Location: italy

PostPosted: Thu Jun 12, 2008 9:45 pm
Reply with quote

there is no NULL value in se...
nullness is a convention....
every bit configuration is a valid configuration without any implied meaning

a NULL value is any bit configuration defined as such by the application specifications...

somebody uses low values, but that' s not mandatory
for example if a field is unsigned binary numeric, a negative value might b use to indicate a NULL/invalid value

so the answer is ... check the appliaction data description specifications
Back to top
View user's profile Send private message
Bill O'Boyle

CICS Moderator


Joined: 14 Jan 2008
Posts: 2501
Location: Atlanta, Georgia, USA

PostPosted: Thu Jun 12, 2008 9:47 pm
Reply with quote

If the field is display-numeric, you can test it for X'00's using reference modification -
Code:

03  WS-FIELD PIC  9(02).
*
IF  WS-FIELD (1:) = LOW-VALUES

You're correct in testing a binary-field for ZERO (same as LOW-VALUES), but if you have a packed-decimal field, you need to redefine it as alphanumeric (PIC X), then you can test it for LOW-VALUES.

Note that depending on the field, there's also this wonderful "NULL" value that IBM uses in POINTER fields which is X'FF000000', so keep this in mind if at one time a binary-fullword had been a POINTER.

Bill
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Thu Jun 12, 2008 9:47 pm
Reply with quote

Hello,

NULL VALUE is a databse term/concept.

A qsam input file cannot have the "database NULL" in it. The qsam file will have values in each byte between x'00' and x'FF' - none of which is null.

The spaces you see are probably unprintable characters (maybe x'00's).
Back to top
View user's profile Send private message
the_gautam

Active User


Joined: 05 Jun 2005
Posts: 165
Location: Bangalore

PostPosted: Fri Jun 13, 2008 3:30 pm
Reply with quote

Quote:
But I want the O/P as same as I/P because it has to be stored in a table as null value instead of 0

In order to store the data as NULL in the table, why dont you use the NULL INDICATORs? passing the value -1 to the NULL INDICATOR before inserting it to the table will insert the field as NULL in the table....
Back to top
View user's profile Send private message
birdy K

New User


Joined: 05 Mar 2008
Posts: 72
Location: chennai

PostPosted: Fri Jun 13, 2008 4:09 pm
Reply with quote

Check for the low-values or invalid fields. For invalid fields, move -1 to host variable and insert it.
Back to top
View user's profile Send private message
bibek24

New User


Joined: 14 Aug 2007
Posts: 35
Location: Hyderabad

PostPosted: Fri Jun 13, 2008 4:22 pm
Reply with quote

checking for low-values,<0 etc are not working.
I am not using null indicator because the table has to be loaded with a load file through a load utility.

anywys let the fields come as 0 to the load file(O/P) .Is there any way to load the table field as null wherever there is 0 for the field in the load file.
I mean whenever the load utility will find a 0 in the load file for the particular field ,the corresponding field in the table should be null.

Any suggestions?
Back to top
View user's profile Send private message
enrico-sorichetti

Superior Member


Joined: 14 Mar 2007
Posts: 10873
Location: italy

PostPosted: Fri Jun 13, 2008 4:29 pm
Reply with quote

use the NULLIF construct of the load utility

something like ( logic, the syntax might be wrong)
Code:
field_name  POSITION(field_position ) field_type
NULLIF (field_to_be_checked_coordinates)=condition_to_be_checked 


but it would be better to read the load utility documentation
Back to top
View user's profile Send private message
bibek24

New User


Joined: 14 Aug 2007
Posts: 35
Location: Hyderabad

PostPosted: Fri Jun 13, 2008 5:14 pm
Reply with quote

hi all,

I tried for the following and got the result

exp - FIELD1 POSITION (655) SMALLINT
NULLIF (35:36)=X'0000' ,

But I didn't meet my 1st requirement,moving a null value from a input field to its corresponding O/P field.
Its always coming as 0.
Back to top
View user's profile Send private message
Craq Giegerich

Senior Member


Joined: 19 May 2007
Posts: 1512
Location: Virginia, USA

PostPosted: Fri Jun 13, 2008 5:28 pm
Reply with quote

In DB2 a column which is defined as nullable and has the null indicator set to -1 does not have any value, there is no such thing as a null value in DB2. If the column is defined as char you can put hex'00' in the column but that does not make it null.
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts Replace each space in cobol string wi... COBOL Programming 3
No new posts COBOL -Linkage Section-Case Sensitive COBOL Programming 1
No new posts COBOL ZOS Web Enablement Toolkit HTTP... COBOL Programming 0
No new posts Calling DFSORT from Cobol, using OUTF... DFSORT/ICETOOL 5
No new posts Generate random number from range of ... COBOL Programming 3
Search our Forums:

Back to Top