04 Multiple SQL commands with Single PREPARE multiple EXECUTES
**FREE
dcl-s UpdLib char(10);
dcl-s x zoned(3:0);
dcl-s msg char(50);
dcl-s SQLStmt char(100) inz('Update FILEA set FIELDA = ');
dcl-s SQLWhere char(50) inz(' where FIELDA = ?');
dcl-s LibNames char(10) dim(3) perrcd(1) ctdata;
dcl-pi *n;
parm1 char(5);
end-pi;
SQLStmt = %trim(SQLStmt) + ' ' + parm1 + ' ' + %trim(SQLWhere);
exec sql prepare SQLString from :SQLStmt;
for x = 1 to 3;
updLib = libnames(x);
exec sql
execute SQLString using :updlib;
select;
when sqlstt = '00000'; // completed normally
msg = %char(sqler3) + ' records found for ' + updlib;
dsply msg;
when sqlstt = '02000'; // no records found
msg = 'No records found for ' + updlib;
dsply msg;
other; // some other error
msg = 'Error ' + sqlstt + ' trying to update ' + updlib;
dsply msg;
endsl;
endfor;
*inlr = *on;
** CTDATA LibNames
LibA
LibB
LIBC
dcl-s UpdLib char(10);
dcl-s x zoned(3:0);
dcl-s msg char(50);
dcl-s SQLStmt char(100) inz('Update FILEA set FIELDA = ');
dcl-s SQLWhere char(50) inz(' where FIELDA = ?');
dcl-s LibNames char(10) dim(3) perrcd(1) ctdata;
dcl-pi *n;
parm1 char(5);
end-pi;
SQLStmt = %trim(SQLStmt) + ' ' + parm1 + ' ' + %trim(SQLWhere);
exec sql prepare SQLString from :SQLStmt;
for x = 1 to 3;
updLib = libnames(x);
exec sql
execute SQLString using :updlib;
select;
when sqlstt = '00000'; // completed normally
msg = %char(sqler3) + ' records found for ' + updlib;
dsply msg;
when sqlstt = '02000'; // no records found
msg = 'No records found for ' + updlib;
dsply msg;
other; // some other error
msg = 'Error ' + sqlstt + ' trying to update ' + updlib;
dsply msg;
endsl;
endfor;
*inlr = *on;
** CTDATA LibNames
LibA
LibB
LIBC
Comments
Post a Comment