MIDRANGE dot COM Mailing List Archive

Home » MIDRANGE-L » March 2013

Re: RUNSQL syntax


On 12 Mar 2013 12:07, fbocch2595@xxxxxxx wrote:
Any idea how to get details of how many records were deleted when
using RUNSQL in batch in a CLP? That would be nice.

As noted in a prior discussion, write a program [even a very dynamic REXX would do] to get the SQLERRD(3) of the SQLCA to identify the number of rows deleted, instead of using such a generic SQL utility.

What I usually do is DSPFD before and after the RUNSQL.

If knowing what the upcoming DELETE statement would delete is considered to be sufficiently accurate, then by using the CREATE VIEW method, the CLP can have a DCLF to read the VIEW to learn the answer. And to review just the count of rows to be deleted instead of the actual rows to be deleted, that is easily done by creating another VIEW over the first. For example:

DCLF DLT_COUNT /* create table qtemp/dlt_count (dlt_count dec(10) not null ; or whatever required to get rcdfmt lvlid to match the VIEW */
RUNSQL SQL('create view qtemp/dlt_from as ( select * from t18pf where joentt = ''CA'' and jojob = ''QZLSFILET'' and jopgm = ''QLESPI'' )' ) COMMIT(*NONE)
RUNSQL SQL('create view qtemp/dlt_count as ( select dec(count(*), 10) as dlt_count from qtemp/dlt_from)')
RCVF /* CL var &DLT_COUNT will now have the value of the number of rows matching the WHERE clause of the upcoming DELETE; i.e. the where-clause encapsulated in the SELECT of the first CREATE VIEW */
RUNSQL SQL('delete from qtemp/dlt_from') COMMIT(*NONE)
RCVF /* force the DLT_COUNT file to close */
MONMSG CPF0864 EXEC(rcvmsg (*same (*)) *pgmq *excp *none 0 rmv(*yes))
RUNSQL SQL('drop view qtemp/dlt_from cascade)')

Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2014 by MIDRANGE dot COM and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available here. If you have questions about this, please contact