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

SQLCODE=-311 in Cobol SP-DB2.


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

New User


Joined: 14 Jul 2024
Posts: 1
Location: India

PostPosted: Thu Jul 18, 2024 4:17 pm
Reply with quote

The dynamic SQL should be built in a Cobol SP-DB2, which doesn't have fixed number of host variable in WHERE clause and also moreover SQL is dynamic for each SP call.

For example, the below SQL returns multiple rows. My requirement is to use parameter marker.

SQL: select * from employee where emp_no = &var1 and &var1 not in ('')

Length of emp-no variable is 15. Length of its attribute/value is 9.

Below steps followed:
1) Replacing &var1 in the SQL with the parameter marker ?.
2) DECLARE CURSOR
3) PREPARE
4) DESCRIBE INPUT sqlstmt INTO SQLDA
4) Set the address of EMP-NO to SQLDATA (1) and SQLDATA (2)
5) OPEN cursor USING DESCRIPTOR :SQLDA.

Here OPEN statement failing with SQLCODE=-311. While checking the DESCRIBE INPUT, the second &var1 is identified with SQLTYPE (2) as '+0449' (variable character) and with SQLLEN (2) as '+0000', Where as the first &var1 is identified with SQLTYPE (1) as '+0453' and with SQLLEN (1) as '+0015'.

I have tried populating the SQLLEN (2) for the second &var1 in the application program with length =+0009 (which has the emp no with length of the value as 9), and also with length = +0015, but that doesn't resolve.

How to resolve this issue in the COBOL SP-DB2 program?
Back to top
View user's profile Send private message
sergeyken

Senior Member


Joined: 29 Apr 2008
Posts: 2141
Location: USA

PostPosted: Thu Jul 18, 2024 5:27 pm
Reply with quote

You need to present THE DETAILED CODE (within Code tags), plus ALL AVAILABLE intermediate results, AFTER EACH of your described steps.

Theoretical discussion here is useless.
It is equivalent to: "I do everything right, but my results are wrong. Why?!"
Back to top
View user's profile Send private message
Rohit Umarjikar

Global Moderator


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

PostPosted: Fri Jul 19, 2024 1:14 pm
Reply with quote

Welcome !

The terms used are not accurate one ..

When you say about dynamic sql then it innvolvew prepare and execute statements followed after open ..

Also it’s best to store your dynamic where condition and / or select in another db2 table tagging against unique id .

Frontend/ caller will pass the unique id based on what’s selected and then you would query the table for that id to prepare your query to execute .

Is that what’s done ?
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 COBOL sorting, with input GDG base COBOL Programming 7
No new posts Need help with ADABAS query (COBOL-AD... All Other Mainframe Topics 0
No new posts Replacing FILLER with FILLER<SeqNu... DFSORT/ICETOOL 2
No new posts Compile Sp Cobol base COBOL Programming 1
No new posts COBOL 6.4 - User Defined Function nee... COBOL Programming 6
Search our Forums:

Back to Top