Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

How to initalize the SQL VARCHAR field in Cobol.

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
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    Post subject: How to initalize the SQL VARCHAR field in Cobol.
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    Post subject: Reply to: How to initalize the SQL VARCHAR field in Cobol.
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: 208
Location: Cochin/Kerala/India

PostPosted: Mon Oct 05, 2009 4:41 pm    Post subject:
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    Post subject: Reply to: How to initalize the SQL VARCHAR field in Cobol.
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    Post subject: Reply to: How to initalize the SQL VARCHAR field in Cobol.
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    Post subject:
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    Post subject:
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    Post subject:
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

Site Director


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

PostPosted: Mon Oct 05, 2009 8:31 pm    Post subject:
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    Post subject:
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    Post subject:
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    IBMMAINFRAMES.com Support Forums -> COBOL Programming All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts Splitting a report based on a field abdulrafi DFSORT/ICETOOL 6 Thu Mar 23, 2017 6:56 pm
No new posts SORT VSAM file with each field one by... maxsubrat DFSORT/ICETOOL 6 Tue Mar 14, 2017 1:07 pm
No new posts IMS DB-How to update a record (a sing... Nic Clouston IMS DB/DC 9 Thu Mar 09, 2017 4:38 pm
No new posts outrec field outside range Danielle.Filteau SYNCSORT 10 Sat Mar 04, 2017 2:37 am
No new posts SQL query not working in Cobol program. CuriousMainframer COBOL Programming 14 Wed Feb 22, 2017 5:56 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us