Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

usage of null indicators

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2
View previous topic :: :: View next topic  
Author Message
abdulrafi

Active User


Joined: 14 Sep 2009
Posts: 135
Location: Coimbatore

PostPosted: Wed Nov 17, 2010 7:23 pm    Post subject: usage of null indicators
Reply with quote

Hi,

I have designed a Db2 program. I got a doubt in handling null indicators. i have declared the null indicator variable as s9(4) comp.

i have a NULL field. so while inserting and updating i have moved -1 to null indicator to insert it in db2 table.

My doubt is, whether i need to move 0 to null indicator if the column defined as NULL has a valid value ?. I have moved the value to the db2 field and 0 to the null indicator during insertion and updation?. please let me know what i have done is correct ?.

i have given a sample psuedo code which i have used in my program.

if sql-code = 0
move "valid-value" to db2 field
move "0" to null-indicator
else
if sql-code = 100
move -1 to null-indicator
end-if
end-if.

Moreover during SUM(db2 field), this db2 field is a NULL field, whether it is necessary to use null indicators or is it enough to use host variables alone to handle the sum.

please help me out.
Back to top
View user's profile Send private message

GuyC

Senior Member


Joined: 11 Aug 2009
Posts: 1278
Location: Belgium

PostPosted: Wed Nov 17, 2010 7:51 pm    Post subject:
Reply with quote

pseudo code looks fine, just move 0 and not "0"
Code:
select sum(col) from tab where ...

- returns NULL when no rows qualify the where clause, even when field itself is not nullable.
- returns null when all "col" from qualifying rows are null

so, yes you have to use null-indicator or use the function coalesce() :
Code:
select coalesce(sum(col),0) from tab where ...
Back to top
View user's profile Send private message
Phrzby Phil

Active Member


Joined: 31 Oct 2006
Posts: 962
Location: Richmond, Virginia

PostPosted: Wed Nov 17, 2010 8:22 pm    Post subject:
Reply with quote

if you really want to learn this and remember it, I suggest you create a few sandbox tables to play with, then test each variant of how this might work, and see the results.

Then you will be the valuable goto person in your org who knows this stuff.
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2 All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts Syncsort - NULL in Integer field chec... nartcr SYNCSORT 4 Thu Oct 06, 2016 6:47 am
No new posts Converting NULL column into NOT NULL ... Raghu navaikulam DB2 5 Sat Aug 06, 2016 3:45 pm
No new posts GetObjectArrayElement returns NULL Majid Hussain Java & MQSeries 2 Wed Mar 30, 2016 2:59 am
No new posts How can amount of the Storage Usage b... esduman61 CICS 6 Wed Mar 09, 2016 1:19 pm
No new posts Query to select Null row on priority RahulG31 DB2 24 Thu Jan 21, 2016 5:45 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us