75 pts.
 AS400, SQL and COBOL anomalies
I coded an update query in COBOL and included COMMIT=NONE so the update could go through. When the COBOL program executed it returned nulls, and coalesced the value to the default. When the query was executed either through qmqry or on-line on the sql screen it worked fine and updated the field properly.

I also tried calling a cl program that executed the QMQRY from within the COBOL program and I also got bad results. When I called the CL from within another CL or called the CL program directly I got expected results.

Here is the query:

EXEC SQL UPDATE FILEA A SET A.ITMID = COALESCE((SELECT DISTINCT B.ITMID FROM FILEB B WHERE A.FLDA = B.FLDA AND A.FLDB = B.FLDB AND A.FLDC = B.FLDC),:NO-ITM) END-EXEC.



Software/Hardware used:
as400 cobol iseries embedded sql
ASKED: September 23, 2009  5:31 PM
UPDATED: October 28, 2009  2:25 PM

Answer Wiki:
Are you sure the library list is the same? Is the COBOL program doing any overrides? I'd do a CHGJOB LOG(4 00 *SECLVL) and run the COBOL program again. Then check your joblog to see what shows up there.
Last Wiki Answer Submitted:  October 28, 2009  2:25 pm  by  CharlieBrowne   32,785 pts.
All Answer Wiki Contributors:  CharlieBrowne   32,785 pts.
To see all answers submitted to the Answer Wiki: View Answer History.


Discuss This Question:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _


 

Hard to answer for multiple reasons. Please describe the COBOL — ILE or OPM? Is it a module in a larger program? What options were specified on the CRTxxx command(s)? What was the SET OPTION statement in the compile module/program? What PROCESS statement was used?

Also:

  • UPDATE FILEA A SET A.ITMID = COALESCE((SELECT DISTINCT B.ITMID FROM FILEB B WHERE A.FLDA = B.FLDA AND A.FLDB = B.FLDB AND A.FLDC = B.FLDC),:NO-ITM)

Since that statement contains a host variable — NO-ITM — it wouldn’t run in QMQRY nor in interactive SQL. You had to use a different UPDATE statement. What was it? And what is the COBOL definition of NO-ITM? (NO-ITM probably doesn’t matter, but it might help in understanding.)

Did the COBOL execution actually update rows causing A.ITMID to become null when it previously had a value or was A.ITMID already null?

 107,695 pts.