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 write this query in cobol prg?

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2
View previous topic :: :: View next topic  
Author Message
i_suman

New User


Joined: 01 Mar 2005
Posts: 20

PostPosted: Thu Oct 09, 2008 8:14 am    Post subject: how to write this query in cobol prg?
Reply with quote

I have following query which is giving output. But the same when implemented as embedded sql in Cobol is not working. Its giving SqlCode = 100.

Select value(count(*),0) from incdt_1141 A, incdt_1147 B
where A.del_ts is null
and A.ir_no = 1234
and A.incdt_type = B.incdt_type
and B.incdt_grp_cd in ('A1','CA','CB','K1')
and Date(A.cre_ts) between '1998-01-01' and '2002-12-31'
order by B.incdt_grp_cd;

Output when run thru spufi:
Count
4
3
3

The same above query when embedded in cobol prog is giving me an sqlcode =100.

Is there any difference or differnt way to implement the same query in cobol program? Please let me know.

Note: I used host variables where ever required in the cobol prog.
Back to top
View user's profile Send private message

Arun Raj

Moderator


Joined: 17 Oct 2006
Posts: 2180
Location: @my desk

PostPosted: Thu Oct 09, 2008 8:27 am    Post subject:
Reply with quote

Quote:
Is there any difference or differnt way to implement the same query in cobol program?

Yes. you need to declare a cursor. But since you're not getting SQLCODE=-811, I guess you've already declared that. Can you post your cursor DECLAREation and FETCH statements.
Back to top
View user's profile Send private message
i_suman

New User


Joined: 01 Mar 2005
Posts: 20

PostPosted: Thu Oct 09, 2008 5:43 pm    Post subject:
Reply with quote

exec sql
declare incdt_csr cursor for
Select value(count(*),0) from incdt_1141 A, incdt_1147 B
where A.del_ts is null
and A.ir_no = 1234
and A.incdt_type = B.incdt_type
and B.incdt_grp_cd in ('A1','CA','CB','K1')
and Date(A.cre_ts) between '1998-01-01' and '2002-12-31'
order by B.incdt_grp_cd
end-exec.

I am fetching the records.
Exec sql
Fetch incdt_csr into :incdts-cnt
end-exec.

incdts-cnt is defined as s9(4) comp.
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: Thu Oct 09, 2008 10:00 pm    Post subject:
Reply with quote

Hello,

Quote:
Its giving SqlCode = 100.
The +100 is expected - it is how the code should test for the end of the result set.

In your code, there will be multiple iterations. In SPUFI, it all happens on a single "click".

The bit of code you posted does not show the process flow within your code.
Back to top
View user's profile Send private message
i_suman

New User


Joined: 01 Mar 2005
Posts: 20

PostPosted: Tue Oct 14, 2008 8:41 am    Post subject:
Reply with quote

thanks. I got it.
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: Tue Oct 14, 2008 9:02 am    Post subject: Reply to: how to write this query in cobol prg?
Reply with quote

You're welcome - Good to hear it is working icon_smile.gif

It you post your solution, it will maybe help someone else later when they have a similar problem.

d
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 -> DB2 All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
This topic is locked: you cannot edit posts or make replies. Full Time COBOL Software Development ... shally Mainframe Jobs 0 Fri Jan 20, 2017 5:24 am
This topic is locked: you cannot edit posts or make replies. COBOL Software Development Lead at Fi... shally Mainframe Jobs 0 Fri Jan 20, 2017 5:21 am
No new posts Join in SQL Query vickey_dw DB2 2 Tue Jan 17, 2017 12:15 am
No new posts Executing OO COBOL program invoking J... Virendra Shambharkar COBOL Programming 2 Tue Jan 10, 2017 6:37 pm
No new posts OO COBOL compile error Virendra Shambharkar COBOL Programming 3 Tue Jan 10, 2017 6:05 pm


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