If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > What Value goes into a host vairable....

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 01-23-07, 14:59
Brett Kaiser Brett Kaiser is offline
Window Washer
 
Join Date: Nov 2002
Location: Jersey
Posts: 10,303
What Value goes into a host vairable....

When the column is NULL

OS/390 DB2 7.2 or 8
__________________
Brett
8-)

It's a Great Day for America everybody!

dbforums Yak CorralRadio 'Rita
dbForums Member List
I'm Good Once as I ever was

The physical order of data in a database has no meaning.
Reply With Quote
  #2 (permalink)  
Old 01-23-07, 15:17
Marcus_A Marcus_A is offline
Registered User
 
Join Date: May 2003
Location: USA
Posts: 5,196
You put a negative 1 (-1) in the indicator variable. It does not matter what goes in the host variable if the indicator variable is -1.
__________________
M. A. Feldman
IBM Certified DBA on DB2 for Linux, UNIX, and Windows
IBM Certified DBA on DB2 for z/OS and OS/390
Reply With Quote
  #3 (permalink)  
Old 01-23-07, 15:35
Brett Kaiser Brett Kaiser is offline
Window Washer
 
Join Date: Nov 2002
Location: Jersey
Posts: 10,303
i though the null indicator was a '?'

is -1 a unix installation thing?

OK, so I know you interogate the null indicator, but what is in the host variable? And it does matter if Developer doesn't know what they are doing

I thought it was low values HEX('00')

Someone else is saying what ever is in the register at the time

Anyone?
__________________
Brett
8-)

It's a Great Day for America everybody!

dbforums Yak CorralRadio 'Rita
dbForums Member List
I'm Good Once as I ever was

The physical order of data in a database has no meaning.
Reply With Quote
  #4 (permalink)  
Old 01-23-07, 16:40
Brett Kaiser Brett Kaiser is offline
Window Washer
 
Join Date: Nov 2002
Location: Jersey
Posts: 10,303
Also this is COBOL we are talking about
__________________
Brett
8-)

It's a Great Day for America everybody!

dbforums Yak CorralRadio 'Rita
dbForums Member List
I'm Good Once as I ever was

The physical order of data in a database has no meaning.
Reply With Quote
  #5 (permalink)  
Old 01-23-07, 18:38
Marcus_A Marcus_A is offline
Registered User
 
Join Date: May 2003
Location: USA
Posts: 5,196
SELECT COL1 INTO :HOST_VAR:IND_VAR FROM table-name WHERE COL1 = :KEY_VAR;

Above is a Select statement that would be used in a COBOL program. Becasue COL1 is nullable, the INTO clause reference two variables in WORKING-STORAGE, the first being where DB2 will put the value of COL1 and the second being the indicator variable that DB2 will set. The two variables can be named whatever you want in WORKING STORAGE, but the indicator variable should be a half work binary which is COMP S9(4)..

If the indicator variable (in this case IND_VAR) in WORKING STORAGE is a -1, then the column is null.

Same applies to updates of the column (the program sets the indicator variable to tell DB2 whether it is null). A zero means not null, and -1 is null.
__________________
M. A. Feldman
IBM Certified DBA on DB2 for Linux, UNIX, and Windows
IBM Certified DBA on DB2 for z/OS and OS/390
Reply With Quote
  #6 (permalink)  
Old 01-24-07, 00:18
Brett Kaiser Brett Kaiser is offline
Window Washer
 
Join Date: Nov 2002
Location: Jersey
Posts: 10,303
great, got it it, understand, so what's in the host variable?

Label me an idiot
__________________
Brett
8-)

It's a Great Day for America everybody!

dbforums Yak CorralRadio 'Rita
dbForums Member List
I'm Good Once as I ever was

The physical order of data in a database has no meaning.
Reply With Quote
  #7 (permalink)  
Old 01-24-07, 00:48
Marcus_A Marcus_A is offline
Registered User
 
Join Date: May 2003
Location: USA
Posts: 5,196
Quote:
Originally Posted by Brett Kaiser
great, got it it, understand, so what's in the host variable?

Label me an idiot
OK, you are an idiot. But I made some mistakes in the above post since COBOL variables cannot have underscores, and I have changed a few other things in the query.

In the select statement:
SELECT COL2 INTO :HOST-VAR:IND-VAR FROM table-name WHERE COL1 = :KEY-VAR
assume that COL2 is defined as CHAR(4) in DB2, and COL1 is the Primary Key and is INTEGER in DB2.

You would need 3 variables in WORKING STORAGE;

01 HOST-VAR PIC X(4).
01 IND-VAR PIC S9(4) COMP.
01 KEY-VAR PIC S9(9) COMP.

MOVE 456 to KEY-VAR.

EXEC SQL.
SELECT COL2 INTO :HOST-VAR:IND-VAR FROM table-name WHERE COL1 = :KEY-VAR
END-EXEC.


The above statement has retrieved a row with Primary Key = 456 and put the value for COL2 in the COBOL variable HOST-VAR. To determine if the value of HOST-VAR is null, test IND-VAR for -1.
__________________
M. A. Feldman
IBM Certified DBA on DB2 for Linux, UNIX, and Windows
IBM Certified DBA on DB2 for z/OS and OS/390
Reply With Quote
  #8 (permalink)  
Old 01-24-07, 01:43
vini_srcna vini_srcna is offline
Registered User
 
Join Date: May 2006
Posts: 82
Guys, here we go.

CREATE TABLE VINAYTM.REXXTEST
( USERID CHAR(8) NOT NULL WITH DEFAULT,
ROW_NO INTEGER NOT NULL,
NAME CHAR(20));

Inserted 3 rows

SELECT * FROM REXXTEST
(here my userid is VINAYTM, so no need of table owner)

ROW
USERID NO NAME
-------- ----------- --------------------
1 -
vinay1 2 first
vinay2 3 -


** END ***

I wrote one simple db2 PL1 program for you.

TESTPGM:PROC OPTIONS(MAIN);
DCL IND FIXED BIN(15) INIT(0); -- for NULL INDICATOR
DCL MYNAME CHAR(20) INIT('VINAY KUMAR');
DCL ROWNO FIXED BIN(31) INIT(0); --> didnt use this one
EXEC SQL INCLUDE SQLCA;
PUT SKIP LIST ('BEFORE, NAME = '||MYNAME);
PUT SKIP LIST ('BEFORE, INDICATOR = '||IND);
EXEC SQL
SELECT NAME INTO :MYNAME:IND FROM VINAYTM.REXXTEST
WHERE ROW_NO = 1;

IF SQLCA.SQLCODE = 0 THEN
DO;
PUT SKIP LIST ('AFTER , NAME = '||MYNAME);
PUT SKIP LIST ('AFTER , INDICATOR = '||IND);
END;
ELSE
DO;
PUT SKIP LIST ('FAILED');
PUT SKIP LIST ('SQLCODE IS '||SQLCA.SQLCODE);
END;

END TESTPGM;

Here is the execution results:

BEFORE, NAME = VINAY KUMAR
BEFORE, INDICATOR = 0
AFTER , NAME = VINAY KUMAR
AFTER , INDICATOR = -1
***
So the conclusion part is, If DB2 encounters a null vaue then it doest touch the HOST variable, it just sets the value of NULL INDICATOR variable. Here we can see indicator variable is changed from 0 to -1 but the name is untouched.

Quote:
Originally Posted by Brett Kaiser
great, got it it, understand, so what's in the host variable?

Label me an idiot
So the host variable would still contain the value it was having earlier to this statement execution. I realise this concept from one of the manuals but wanted to confirm it today. By the way you are not an Idiot -) cheers
Reply With Quote
  #9 (permalink)  
Old 01-24-07, 01:46
vini_srcna vini_srcna is offline
Registered User
 
Join Date: May 2006
Posts: 82
Result set is not displayes correctly. it would look like
1 -
vinay1 2 first
vinay2 3 -
Reply With Quote
  #10 (permalink)  
Old 01-24-07, 01:46
vini_srcna vini_srcna is offline
Registered User
 
Join Date: May 2006
Posts: 82
my gosh. still the same

<blank> 1 -
vinay1 2 first
vinay2 3 -
Reply With Quote
  #11 (permalink)  
Old 01-25-07, 12:06
Brett Kaiser Brett Kaiser is offline
Window Washer
 
Join Date: Nov 2002
Location: Jersey
Posts: 10,303
So the answer is it does nothing, and if the host variable is referenced, it was whatever was there before?
__________________
Brett
8-)

It's a Great Day for America everybody!

dbforums Yak CorralRadio 'Rita
dbForums Member List
I'm Good Once as I ever was

The physical order of data in a database has no meaning.
Reply With Quote
  #12 (permalink)  
Old 01-25-07, 17:48
stolze stolze is offline
Registered User
 
Join Date: Jan 2007
Location: Jena, Germany
Posts: 2,662
You have a good chance that this is the behavior. However, you cannot and must not rely on it. Only the null indicator is useful. Treat the actual host variable as being not initialized.
__________________
Knut Stolze
IBM DB2 Analytics Accelerator
IBM Germany Research & Development
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On