NULL and SQLCODE -305.

RDBMS from IBM and IBM's Hierarchical DBMS and Transaction Manager (IMS DC).
Post Reply
Krishna singh
New Member
Posts: 7
Joined: Wed Jan 20, 2016 12:26 am

NULL and SQLCODE -305.

Post by Krishna singh »

Hi,

In my program Ihave a select statemnet. In that select I am using a a null column. How can I know that I am selecting a null column. If I check only SQLCODE -305, will that be fine. If it is not, why it is not coded this way...
zprogrammer
Global Moderator
Global Moderator
Posts: 588
Joined: Wed Nov 20, 2013 11:53 am
Location: Mars

Re: NULL and SQLCODE -305.

Post by zprogrammer »

You might also need to follow your company standard procedure for all the validations that needs to be done.. Talk to your team or check the existing programs and that should answer your question
zprogrammer
nicc
Global Moderator
Global Moderator
Posts: 691
Joined: Wed Apr 23, 2014 8:45 pm

Re: NULL and SQLCODE -305.

Post by nicc »

If NULL can be returned instead of a column value then you should be coding a Null indicator variable alongside the variable that would have the value returned in it if there was a value to return.
Regards
Nic
User avatar
Anuj Dhawan
Founder
Posts: 2799
Joined: Sun Apr 21, 2013 7:40 pm
Location: Mumbai, India
Contact:
India

Re: NULL and SQLCODE -305.

Post by Anuj Dhawan »

Krishna singh wrote:Hi,

In my program Ihave a select statemnet. In that select I am using a a null column. How can I know that I am selecting a null column. If I check only SQLCODE -305, will that be fine. If it is not, why it is not coded this way...
The short answer is - you can do that.

The long answer is - it depends and it depends on multiple inputs; one of which is - does the short answer suffice to your needs? By definition SQLCODE -305 is:
-305
THE NULL VALUE CANNOT BE ASSIGNED TO OUTPUT HOST VARIABLE NUMBER position-number BECAUSE NO INDICATOR VARIABLE IS SPECIFIED
Explanation

A FETCH, SELECT, VALUES INTO, or SET assignment statement resulted in the retrieval of a null value to be inserted into the output host variable, designated by entry number 'position-number' of the output SQLDA, for which no indicator variable was provided. An indicator variable must be supplied if a column returns a null value.

System action

The statement cannot be processed. No data was retrieved.

Programmer response

Examine the definition of the table that is the object of the statement and correct the application program to provide indicator variables for all host variables into which null values can be retrieved. This includes host variables for columns which can contain null values and host variables which receive the results of aggregate functions whose result table could be empty.
Per the definition - if you consider this "the null value cannot be assigned to output host variable number position-number because no indicator variable is specified" and acceptable test-condition, well, you can show an appropriate message and terminate the program. However, in other world and the one which has been accepted by the larger group of programmer, we tend to take action based on the NULL indicator as nicc and Pandora-Box has also indicated to.
Thanks,
Anuj

Disclaimer: My comments on this website are my own and do not represent the opinions or suggestions of any other person or business entity, in any way.
Krishna singh
New Member
Posts: 7
Joined: Wed Jan 20, 2016 12:26 am

Re: NULL and SQLCODE -305.

Post by Krishna singh »

Thanks a lot all for your explnation. It has helped.
User avatar
Anuj Dhawan
Founder
Posts: 2799
Joined: Sun Apr 21, 2013 7:40 pm
Location: Mumbai, India
Contact:
India

Re: NULL and SQLCODE -305.

Post by Anuj Dhawan »

Glad, we were helpful.
Thanks,
Anuj

Disclaimer: My comments on this website are my own and do not represent the opinions or suggestions of any other person or business entity, in any way.
Post Reply

Create an account or sign in to join the discussion

You need to be a member in order to post a reply

Create an account

Not a member? register to join our community
Members can start their own topics & subscribe to topics
It’s free and only takes a minute

Register

Sign in

Return to “IBM DB2 and IMS DB/DC”