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: 147
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: 1281
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: 964
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 )SEL and )ENDSEL usage cvnlynn TSO/ISPF 4 Thu Jun 15, 2017 1:15 am
No new posts Fileaid Update Replace with null string descann Compuware & Other Tools 4 Mon May 15, 2017 3:00 pm
No new posts Need inputs on Space requirement and... ashek15 IMS DB/DC 0 Sat Apr 01, 2017 8:26 am
No new posts VALIDATE NULL VALUE IN DB2 CASE STATE... useit DB2 5 Thu Feb 09, 2017 4:34 pm
No new posts Syncsort - NULL in Integer field chec... nartcr SYNCSORT 4 Thu Oct 06, 2016 6:47 am


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