Larry Pinsky · Feb 28, 2020

SQLCODE Error -400

I have a code block in a BPL.  I have the below SQL and code.  All variables have been declared and set.  When I run the SQL, if there are no values returned, I get 100 for the value of SQLCODE when I perform the FETCH, which is correct.  If values are returned, I get a -400 error when I perform the first FETCH.  I've investigated, but cannot find the reason for a -400 error.  Hoping someone out here understands this and knows what's wrong.

   &sql(DECLARE D1 CURSOR FOR SELECT A.SHIPMENTTRACKINGNO, A.SERIALNO, A.CDWACCNO, A.CDWINVOICENO, A.CDWORDERNO, A.CDWPARTNO INTO :context.ShipmentTrackingNo, :context.SerialNo, :context.CDWAccNo, :context.CDWInvoiceNo, :context.CDWOrderNo, :context.PartNo FROM CDWTRACKING."UCH.CDWTRACKING" as A WHERE CUSTOMERPO=:context.CurrentPO and CDWPartNO=:context.CurrentPartNo)
    &sql(OPEN D1)
    set context.C1 = SQLCODE
    &sql(FETCH D1)
    set context.C1 = context.C1_SQLCODE
    set context.test1 = context.test1_"SerialNo"_context.SerialNo
    &sql(FETCH D1)
    set context.C1 = context.C1_SQLCODE
    &sql(CLOSE D1)

0 1,124
Discussion (2)0
Log in or sign up to continue

error -400 means there is an internal error

It might be caused by using object properties as  :context.anyname inside embedded SQL

give it a try and use "simple variables"  as :%myanyname , :%myShipmentTrackingNo 
and fill the context object outside the embedded SQL
as you do with SQLCODE

That was the problem.  Many thanks, Robert.  Who would have thought you cannot put context variables in the SQL?