Skip to main content

The following program has two db2 insert statements, the first using scalars as indicator variables and the second using an array as indicator variables.

TDB2PLI: PROC;
EXEC SQL INCLUDE SQLCA;
EXEC SQL DECLARE TTEST TABLE
( C1 CHAR(10),
C2 CHAR(10));
/*********************************************************************/
/* PLI DECLARATION FOR TABLE VKONTAKTHIST */
/* GENERATION DATE 22.06.2018 */
/*********************************************************************/
DCL 1 STEST,
5 C1 CHAR(10),
5 C2 CHAR(10);
DCL ITEST(2) BIN FIXED(15) init((*)-1);
DCL (I1,I2) BIN FIXED(15) INIT(-1);

EXEC SQL INSERT INTO TTEST VALUES(
:STEST.C1:I1,
:STEST.C2:I2
);

EXEC SQL INSERT INTO TTEST VALUES(:STEST:ITEST);
END TDB2PLI;

If a db2 preprocess is performed using 

mfexecpp -optsql "db=dtcor03 bind=tdb2pli.bnd validate=run NOACCESS " -sql db2 -ppsql tdb2pli.pps tdb2pli.pli

the preprocessor output tdb2pli.pps shows "strange" behavior

- For the first insert statement one assignment per indicator variable to convert it from little endian to big endian, which is correct.
- For the second insert statement, however there are 2 loops (as many loops as indicator variables), and in every loop all indicator variable are endian-converted.
  The second loop is not only unnecessary but also contradicts the intention.: all indicator variables are again in little endian format after the second loop.

Full article: https://portal.microfocus.com/s/article/KM000011375


#EnterpriseDeveloper
#SupportTips/KnowledgeDocs