Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

-301 on open cursor using varying list dynamic SQL

Status
Not open for further replies.

nxm150

Programmer
May 22, 2002
78
US
My code looks like -

01 IN-SQLDA.
05 IN-SQLDAID PIC X(8) VALUE ' '.
05 IN-SQLDABC PIC S9(9) COMP.
05 IN-SQLN PIC S9(4) COMP.
05 IN-SQLD PIC S9(4) COMP.
05 IN-SQLVAR OCCURS 1 TIMES.
10 IN-SQLTYPE PIC S9(4) COMP.
10 IN-SQLLEN PIC S9(4) COMP.
10 IN-SQLDATA USAGE IS POINTER.
10 IN-SQLIND USAGE IS POINTER.
10 IN-SQLNAME.
15 IN-SQLNAMEL PIC S9(4) COMP.
15 IN-SQLNAMEC PIC X(30).
**************************************************************************************
My code for the open looks like

MOVE 1 TO IN-SQLN.
MOVE 1 TO IN-SQLD
COMPUTE IN-SQLDABC = 16 + (44 * IN-SQLD)
MOVE 452 TO IN-SQLTYPE (1)
MOVE 1 TO IN-SQLLEN (1)
SET IN-SQLDATA(1) TO ADDRESS OF DATA-RQST-ID.
MOVE WS-IN-REQUEST-ID TO DATA-RQST-ID.

EXEC SQL
OPEN RQSTID USING DESCRIPTOR :IN-SQLDA
END-EXEC.


Any help on resolving this would be appreciated. Thanks!
 
Try with the definition of the sqlda below. all the examples I have seen have an sqlda defined as below. Yours is slightly different.

01 io-sqlda sync.
05 io-sqldaid pic x(8) value "IN-DA ".
05 io-sqldabc pic s9(9) comp-5.
05 io-sqln pic s9(4) comp-5.
05 io-sqld pic s9(4) comp-5.
05 io-sqlvar-entries occurs 0 to 99 times
depending on io-sqld.
10 io-sqlvar.
15 io-sqltype pic s9(4) comp-5.
15 io-sqllen pic s9(4) comp-5.
15 io-sqldata usage is pointer.
15 io-sqlind usage is pointer.
15 io-sqlname.
20 io-sqlnamel pic s9(4) comp-5.
20 io-sqlnamec pic x(30).


If your on a mainframe I'd leave the definition as comp but ensure you have TRUNC(BIN) compiler option in place.

Help from command prompt is


SQL0301N The value of a host variable in the EXECUTE or OPEN
statement cannot be used because of its data type.

Explanation: A host variable could not be used as specified in
the statement because its data type is incompatible with the
intended use of its value.

This error can occur as a result of specifying an incorrect host
variable or an incorrect SQLTYPE value in a SQLDA on an EXECUTE
or OPEN statement. In the case of a user-defined structured type,
the associated built-in type of the host variable or SQLTYPE
might not be compatible with the parameter of the TO SQL
transform function defined in the transform group for the
statement.

The statement cannot be processed.

User Response: Verify that the data types of all host variables
in the statement are compatible with the manner in which they are
used.

sqlcode: -301

sqlstate: 07006

db2 =>
 
OK, I changed the definition to OCCURS depending instead of hard coding a value of 1. Now I am getting a -804 with a reason code of 4. Hereis what a -804 is

-804 AN ERROR WAS FOUND IN THE APPLICATION PROGRAM INPUT PARAMETERS FOR THE SQL STATEMENT, REASON reason

04 Statement is not recognized.
 
Sorry, I am still getting the -301. I changed my open cursor yesterday to something else. I have now changed my open cursor back to using a descriptor and am still getting the same error. I set up my IN-SQLDA as you have mentioned above.
 
Hey Greg, after further research with a co worker, it was determined that the '452' in MOVE 452 TO IN-SQLTYPE (1) is indicating that I will be using a char data type. My where clause was referencing a integer, thus I should have been moving 496 to IN-SQLTYPE. The example program that I was basing my program off of used 452. I did not know what that value meant but now I do. Thanks for your help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top