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.
Fields used in the select statement ( orderno, custno ) were not declared or the attributes are not correct.