View previous topic :: View next topic
|
Author |
Message |
ramfrom84
New User
Joined: 23 Aug 2006 Posts: 93 Location: chennai
|
|
|
|
Hi All,
Problem:
While fetch the record with VARCHAR field from the table, the OLD value remains in the Host variable instead of moving spaces.
Ex:In the table.
Record 1
Field - XXXXX-DATA , length - 10 Value -AAAAAAAAAAA
Record 2
Field - XXXXX-DATA , length - 0 Value -Spaces
I tried initalize using below command while populating . But it is not working.
INITIALIZE XXXXX-DATA.
It moved Zero to the length field and spaces to the text field but while fetching the record host remains unchanged.
Code: |
//*SQL DEFINITION:
XXXX_DATA VARCHAR(2000) NOT NULL
//*Cobol Definition :
01 XXXXX-DATA.
49 XXXXX-DATA-LEN PIC S9(4) USAGE COMP VALUE ZEROS.
49 XXXXX-DATA-TEXT PIC X(2000) VALUE SPACES.
|
Please let me know what is the correct method to initalize the VARCHAR field
Thanks
Raman |
|
Back to top |
|
|
Succor
New User
Joined: 20 Feb 2009 Posts: 96 Location: Bangalore :)
|
|
|
|
Raman, when fetch operation successfully gets executed (i.e. SQLCODE Zero) the data from the table moves to the field XXXX_DATA as per your where clause definition (moreover it is a Not Null field, it should have some valid data).
There can be two possibilities I can think of right now.
Either you are not using the correct variable while fetching or your interpretation of data coming to that field from the table is not correct (i.e. the DB2 is sending the correct data as per the where clause defined but you are expecting something different). |
|
Back to top |
|
|
bipinpeter
Active User
Joined: 18 Jun 2007 Posts: 213 Location: Cochin/Kerala/India
|
|
|
|
Hi ramfrom84,
For initializing 'Move low-values to field |
|
Back to top |
|
|
ramfrom84
New User
Joined: 23 Aug 2006 Posts: 93 Location: chennai
|
|
|
|
Hi,
All the Db2 fields are correctly populated. if it incorrect then how can i see my old values ? and also i verify record in table .
It is Db2 table,How can i move LOW values when we Insert the record to the table ?
Thanks
Raman |
|
Back to top |
|
|
Succor
New User
Joined: 20 Feb 2009 Posts: 96 Location: Bangalore :)
|
|
|
|
Raman, I believe we are mixing two things over here. Your earlier post talks about the FETCH operation and the new one about the INSERT.
I never doubted on the data present in Db2.Please provide your DECALRE and FTECH queries. Is the data for the field XXXX_DATA remains static for all the Fetch instances? Are you putting displays to view the field values just after the Fetch ?
I reckon bipinpeter pointed put a way to initialize and prepare field XXXX_DATA for the FETCH opreation.You can move spaces to variable before inserting the same in the table. |
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
Often I wonder why people are sooooo stupid as to initialize fields prior to population by a service CALL (in this case DB2).
If the return code from the service indicates success, then check the null inidicator first to see if non-NULL data was transfered, then check the variable length inidicator of the varchar to see if there is any data.
bad return code - no data
null ind = -1, no data
49-level data-len = 0, no data
if you need to know the value of the previously FETCHed row,
maintain a previous-column-value.
what is your problem? |
|
Back to top |
|
|
ramfrom84
New User
Joined: 23 Aug 2006 Posts: 93 Location: chennai
|
|
|
|
Hi,
Read the first post which it my correct question , intermediate post answering to the previous post question.
I have trace the whole fetch statement, we are getting null ind as zero but no value in the variable.
My question is simple, How to initalize the VARCHAR sql field in COBOL.
Bye,, |
|
Back to top |
|
|
Terry Heinze
JCL Moderator
Joined: 14 Jul 2008 Posts: 1249 Location: Richfield, MN, USA
|
|
|
|
You are initializing the variable correctly, but as previously stated, there is no need to since the fetch will populate the variable anyway either with a value or with the null indicator set on. |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hello,
If i understand, DB2 will probably not be changed to do what you want. . .
Suggest you make sure that DB2 actually returned something before the code tries to use it (as DBZ mentioned). . . |
|
Back to top |
|
|
jctgf Currently Banned Active User
Joined: 04 Nov 2006 Posts: 109
|
|
|
|
could you please post the piece of code that reads the db2 table? |
|
Back to top |
|
|
santy Warnings : 1 New User
Joined: 19 Jul 2007 Posts: 22 Location: mumbai
|
|
|
|
Hi Ram,
As oer my suggestion, you have to initialise the you variable before doing the fetch operation wo that you can get the value which u moved from DB2. |
|
Back to top |
|
|
|