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

Host variables will not be able to read NULL values


IBM Mainframe Forums -> DB2
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
ranjani
Warnings : 1

New User


Joined: 25 Oct 2006
Posts: 13

PostPosted: Sun Feb 25, 2007 9:59 am
Reply with quote

in my table, i have a null value in the NAME field in the 2nd row. When i tried to read the values in the table, using cursor, my cursor fetch returned the same NAME field value as of the first row while fetching the second row 'NAME" field. So is that host variables will not be able to read NULL values. Do we have to use indicator variable and set the column value to SPACES if the indicator value is negative????
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: Sun Feb 25, 2007 10:24 am
Reply with quote

Hello,

Yes, if the null-indicator is set, either ignore the (previous) value for that field or move spaces (or whatever is appropriate for your situation).
Back to top
View user's profile Send private message
sachin_star3
Warnings : 1

New User


Joined: 30 Sep 2006
Posts: 78
Location: pune

PostPosted: Mon Feb 26, 2007 4:15 pm
Reply with quote

yes you have to move some value when you get null indicator value is negative
because host variable not able to detect the null value ,means host variavles means the variables structured as for hast language i.e. cobol and cobol cannot read the null values so the null indicator comes in picture
i given you programme
check it out
Code:
                                ID DIVISION
                                PROGRAME-ID.  SACHIN.
                                DATA DIVISION.
                                EXEC SQL
                                        INCLUDE MEMBER1
                                 END-EXEC.
                                  EXEC SQL
                                        INCLUDE SQLCA
                                  END-EXEC.
                                   EXEC SQL
                                          DECLARE CURSOR C1 FOR
                                     SELECT * FROM EMP
                                WORKING-STORAGE SECTION
                                  77  N1 PIC 9(4) USAGE COMP.
                       
                                 PROCEDURE DIVISION.
                                      EXEC SQL
                                          OPEN C1
                                      END-EXEC.
                                    PERFORM FETCH-PARA VARYING I FROPM 1 BY 1 UNTIL  SQLCODE NO=100
                                    EXEC SQL
                                       CLOSE C1
                                        END EXEC
                                      STOP RUN.
                                 [b]FETCH-PARA[/b]
                                     EXEC SQL
                                    FETCH INTO :ECODE,:ENAME,:ESAL:N1
                                      END-EXEC.
                                     IF SQLCODE=-1
                                       MOVE  "NULL" TO ESAL
================= FROM-
SACHIN BORASE
PUNE
Back to top
View user's profile Send private message
MoLong

New User


Joined: 07 Feb 2007
Posts: 32
Location: Chennai

PostPosted: Thu Mar 01, 2007 10:42 am
Reply with quote

Hi Sachin,
for the above prg i dont think we need to use the variable I.
Also it is better to compare N1 < 0 rather than SQLCODE.
Back to top
View user's profile Send private message
sachin_star3
Warnings : 1

New User


Joined: 30 Sep 2006
Posts: 78
Location: pune

PostPosted: Sun Mar 04, 2007 3:17 am
Reply with quote

yes that can also work fine
Back to top
View user's profile Send private message
vini_srcna

Active User


Joined: 26 May 2005
Posts: 178
Location: Copenhagen, Denmark

PostPosted: Tue Mar 06, 2007 3:56 pm
Reply with quote

IF SQLCODE=-1 MOVE "NULL" TO ESAL

I dont think you will get a SQLCODE of -1. DB2 just sets the NULL indicator. In the above example it will set NI to -1. SQLCODE would be still zero. (+100 if its end of cursor ).

When DB2 retrieves a NULL value for the query it sets the indicator to -1 and it does nothing to the host variable. So it would contain the same value.

Quote:
So is that host variables will not be able to read NULL values. Do we have to use indicator variable


You cannot read witout using the indicator variable. It would through negative sql code while during fetch (or select ) mostlikely -305.
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 -> DB2

 


Similar Topics
Topic Forum Replies
No new posts Error to read log with rexx CLIST & REXX 11
No new posts INCLUDE OMIT COND for Multiple values... DFSORT/ICETOOL 5
No new posts Replace Multiple Field values to Othe... DFSORT/ICETOOL 12
No new posts Random read in ESDS file by using RBA JCL & VSAM 6
No new posts Null values are considered in Total c... DFSORT/ICETOOL 6
Search our Forums:

Back to Top