RPG with Dynamic SQL Problem – SQLCOD 501/312

85 pts.
Tags:
Dynamic SQL
RPG
SQL
SQLCOD
I'm trying to do simple dynamic SQL in a program to select records for a subfile but it doesn't seem to be working. sSql = 'SELECT orderno FROM ordhdr ' 'WHERE custno = :scSrchCust '; following this I have: exec SQL CLOSE @Orders; exec SQL Prepare Stmt from :sSQL; exec SQL Declare @Orders SCROLL CURSOR for Stmt; exec SQL OPEN @Orders; I debug this and after the first statement it has a SQLCOD of 501. If I continue to "Step" through it skips the DECLARE Statement and stops on the OPEN Statement with a SQLCOD of 312. What is the problem? Thanks
ASKED: February 25, 2008  12:21 PM
UPDATED: February 25, 2008  3:55 PM

Answer Wiki

Thanks. We'll let you know when a new response is added.

Hi,
please specify the sqlstate values.

<b>sqlcode of -501</b>

The cursor was specified in a CLOSE
statement, but the cursor is not open.

<b>sqlcode of -312</b>

I believe that you are getting the sqlcode of -312 due to either one of the following.

As i can see from the above code The host variable was specified in dynamic SQL. Host
variables are not valid in dynamic SQL. use parameter markers (?) in dynamic sql instead of host variables.

<b>or</b>

Fields used in the select statement ( orderno, custno ) were not declared or the attributes are not correct.
________________________________________________________________________________

[
<b>good day</b>

Discuss This Question: 2  Replies

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
  • MMAGuy
    Edit: when the "step" goes to the PREPARE Statement is when the SQLCOD shows 501.
    85 pointsBadges:
    report
  • MMAGuy
    Thanks for the help... I figured out the problem. I had the sSql incorrectly coded: Original: sSql = 'SELECT orderno FROM ordhdr ' 'WHERE custno = :scSrchCust '; New: sSql = 'SELECT orderno FROM ordhdr ' 'WHERE custno = ' + quote + scSrchCust + quote ' ORDER BY orderno'; quote = const('''')
    85 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following