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

Select query in cobol db2 pgm returning INCORRECT value


IBM Mainframe Forums -> DB2
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
faizm

New User


Joined: 13 Apr 2012
Posts: 59
Location: India

PostPosted: Mon Mar 31, 2014 4:03 pm
Reply with quote

Hi All,
We have a table of around 25 columns. I have written a select query in cobol db2 pgm where in I am trying to select 14 columns. Out of these, the initial 12 columns are returning correct values, however the last 2 column values are not coming correctly and returning some junk values or sometime space. Here is the query:

EXEC SQL
SELECT col1,col2,col3,.......,col 12,col13,col14
INTO :ws-col1,:ws-col2,:ws-col3,....,:ws-col12,:ws-col13,:ws-col14
FROM table1
WHERE col1='12345'
END-EXEC


The length of working storage variable is exactly the same as corresponding column length.

Also, do we need to fetch the column in the order it is defined in table.
Please help on this. Thanks.
Back to top
View user's profile Send private message
enrico-sorichetti

Superior Member


Joined: 14 Mar 2007
Posts: 10873
Location: italy

PostPosted: Mon Mar 31, 2014 4:19 pm
Reply with quote

You did not give too much to work on...
and psychic day is wednesday icon_cool.gif

could it be that the last two columns are nullable ?
Back to top
View user's profile Send private message
faizm

New User


Joined: 13 Apr 2012
Posts: 59
Location: India

PostPosted: Mon Mar 31, 2014 4:29 pm
Reply with quote

Hi,

All the columns are NOT NULL.

When I shuffled the order of columns in select query, the value in the col13 and col 14 came correlctly however the col12 returned junk value.

EXEC SQL
SELECT col1,,col13,col14,col2,col3,.......,col 12
INTO :ws-col1,:ws-col13,:ws-col14:ws-col2,:ws-col3,....,:ws-col12
FROM table1
WHERE col1='12345'
END-EXEC
Back to top
View user's profile Send private message
Pandora-Box

Global Moderator


Joined: 07 Sep 2006
Posts: 1592
Location: Andromeda Galaxy

PostPosted: Mon Mar 31, 2014 4:32 pm
Reply with quote

What is the data type of col13,col14
What happens when you execute the same query in SPUFI and what was the result?
Back to top
View user's profile Send private message
faizm

New User


Joined: 13 Apr 2012
Posts: 59
Location: India

PostPosted: Mon Mar 31, 2014 4:36 pm
Reply with quote

All are CHAR type. When I executed the query in SPUFI it is returning correct values.
Back to top
View user's profile Send private message
Marso

REXX Moderator


Joined: 13 Mar 2006
Posts: 1353
Location: Israel

PostPosted: Mon Mar 31, 2014 6:41 pm
Reply with quote

If you say that first col13 and col14 had "junk" but after moving the columns to the beginning they are OK and col12 receive the "junk", I suspect that this "junk" is coming from somewhere else...

1. To be absolutely sure of what you receive in these fields, add a DISPLAY right after checking the SQLCODE.
2. Check the counters for any OCCURS defined before the table in WS. Maybe you're overflowing.
Back to top
View user's profile Send private message
faizm

New User


Joined: 13 Apr 2012
Posts: 59
Location: India

PostPosted: Mon Mar 31, 2014 6:49 pm
Reply with quote

Actually, I did a mistake. I defined one of the host variable as group variable. After making it an elementary variable, it worked fine and values are coming correctly. Thank you all for replies.
Back to top
View user's profile Send private message
daveporcelan

Active Member


Joined: 01 Dec 2006
Posts: 792
Location: Pennsylvania

PostPosted: Mon Mar 31, 2014 6:56 pm
Reply with quote

Please show the EXACT SQL statement using code tags.

My guess it has something to do with your syntax (going past col 72).

Try putting each colxx and :colxx on its own line (or two to a line).

Just a guess based on the limited information provided.


Edit:
NEVER MIND, I am too slow....
Back to top
View user's profile Send private message
Rohit Umarjikar

Global Moderator


Joined: 21 Sep 2010
Posts: 3053
Location: NYC,USA

PostPosted: Tue Apr 01, 2014 1:07 am
Reply with quote

Faizm,

Thanks for letting us know, However, were you not seen any warnings/errors during the compilation or in the listings?

for more ref.

publib.boulder.ibm.com/infocenter/dzichelp/v2r2/index.jsp?topic=%2Fcom.ibm.db2z10.doc.apsg%2Fsrc%2Ftpc%2Fdb2z_hostvariablecobol.htm

Note: Also a Code Tag can make the post more profressional , hence please make a use of it.
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 -> DB2

 


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 Calling DFSORT from Cobol, using OUTF... DFSORT/ICETOOL 5
No new posts Generate random number from range of ... COBOL Programming 3
Search our Forums:

Back to Top