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

How to initalize the SQL VARCHAR field in Cobol.


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
ramfrom84

New User


Joined: 23 Aug 2006
Posts: 93
Location: chennai

PostPosted: Mon Oct 05, 2009 3:03 pm
Reply with quote

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
View user's profile Send private message
Succor

New User


Joined: 20 Feb 2009
Posts: 96
Location: Bangalore :)

PostPosted: Mon Oct 05, 2009 4:37 pm
Reply with quote

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
View user's profile Send private message
bipinpeter

Active User


Joined: 18 Jun 2007
Posts: 213
Location: Cochin/Kerala/India

PostPosted: Mon Oct 05, 2009 4:41 pm
Reply with quote

Hi ramfrom84,
For initializing 'Move low-values to field
Back to top
View user's profile Send private message
ramfrom84

New User


Joined: 23 Aug 2006
Posts: 93
Location: chennai

PostPosted: Mon Oct 05, 2009 5:02 pm
Reply with quote

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
View user's profile Send private message
Succor

New User


Joined: 20 Feb 2009
Posts: 96
Location: Bangalore :)

PostPosted: Mon Oct 05, 2009 5:57 pm
Reply with quote

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
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Mon Oct 05, 2009 6:26 pm
Reply with quote

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
View user's profile Send private message
ramfrom84

New User


Joined: 23 Aug 2006
Posts: 93
Location: chennai

PostPosted: Mon Oct 05, 2009 7:38 pm
Reply with quote

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
View user's profile Send private message
Terry Heinze

JCL Moderator


Joined: 14 Jul 2008
Posts: 1249
Location: Richfield, MN, USA

PostPosted: Mon Oct 05, 2009 8:05 pm
Reply with quote

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
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Mon Oct 05, 2009 8:31 pm
Reply with quote

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
View user's profile Send private message
jctgf
Currently Banned

Active User


Joined: 04 Nov 2006
Posts: 109

PostPosted: Mon Oct 05, 2009 8:38 pm
Reply with quote

could you please post the piece of code that reads the db2 table?
Back to top
View user's profile Send private message
santy
Warnings : 1

New User


Joined: 19 Jul 2007
Posts: 22
Location: mumbai

PostPosted: Tue Oct 06, 2009 4:42 pm
Reply with quote

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
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 -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts Replace each space in cobol string wi... COBOL Programming 3
No new posts COBOL -Linkage Section-Case Sensitive COBOL Programming 1
No new posts COBOL ZOS Web Enablement Toolkit HTTP... COBOL Programming 0
No new posts Replace Multiple Field values to Othe... DFSORT/ICETOOL 12
No new posts Calling DFSORT from Cobol, using OUTF... DFSORT/ICETOOL 5
Search our Forums:

Back to Top