05 Multiple SQL commands with EXECUTE IMMEDIATES
**FREE
dcl-s UpdLib char(10);
dcl-s x zoned(3:0);
dcl-s msg char(50);
dcl-s SQLStmt char(200);
// -------------------------------------------------------------
// File PFDATA was created by doing a DSPOBJD to an outfile
// -------------------------------------------------------------
dcl-s SQLMain char(100) inz('Update pfdata set odssze = ');
dcl-s SQLWhere char(50) inz(' where odlbnm = ');
dcl-s LibNames char(10) dim(3) perrcd(1) ctdata;
dcl-pi *n;
parm1 char(5);
end-pi;
for x = 1 to 3;
updLib = libnames(x);
// Build the complete SQL statement
SQLStmt = %trim(SQLMain) + parm1 + %trim(SQLWhere) + '''' + %trim(updlib) + '''';
exec sql execute immediate :SQLStmt;
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; // other errors
msg = 'Error ' + sqlstt + ' trying to update ' + updlib;
dsply msg;
endsl;
endfor;
*inlr = *on;
** CTDATA LibNames
LibA
LibB
Mylib
dcl-s UpdLib char(10);
dcl-s x zoned(3:0);
dcl-s msg char(50);
dcl-s SQLStmt char(200);
// -------------------------------------------------------------
// File PFDATA was created by doing a DSPOBJD to an outfile
// -------------------------------------------------------------
dcl-s SQLMain char(100) inz('Update pfdata set odssze = ');
dcl-s SQLWhere char(50) inz(' where odlbnm = ');
dcl-s LibNames char(10) dim(3) perrcd(1) ctdata;
dcl-pi *n;
parm1 char(5);
end-pi;
for x = 1 to 3;
updLib = libnames(x);
// Build the complete SQL statement
SQLStmt = %trim(SQLMain) + parm1 + %trim(SQLWhere) + '''' + %trim(updlib) + '''';
exec sql execute immediate :SQLStmt;
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; // other errors
msg = 'Error ' + sqlstt + ' trying to update ' + updlib;
dsply msg;
endsl;
endfor;
*inlr = *on;
** CTDATA LibNames
LibA
LibB
Mylib
Comments
Post a Comment