More Than One User Running the Operation at the Same Time
After the RPG program is called, the table MYLIB/FILE1 is still open and having more than one
user call the same operation could result in an “In Use” error for the other users. One possible
solution is to have the original RPG program only populate the result table. Then define a
second “wrapper” program to call the first program, copy the table to QTEMP and then return
the results set from the QTEMP version of the table. Below is an example of a wrapper program
written in RPG Free:
HDFTACTGRP(*NO)
DReportPgm Pr Extpgm('MYPGM')
*
D Run Pr ExtPgm('QCMDEXC')
D Cmd 200A CONST
D len 15P 5 CONST
*
/Free
//Create the file in QTEMP
Monitor;
run('DLTF FILE(QTEMP/FILE1)':200);
On-Error;
EndMon;
//Create empty file in QTEMP
run('CRTDUPOBJ OBJ(FILE1) FROMLIB(MYLIB) +
OBJTYPE(*FILE) TOLIB(QTEMP)':200);
run('OVRDBF FILE(FILE1) TOFILE(QTEMP/FILE1)':200);
run('CLRPFM emppfbk':200);
//Call the program that populates FILE1.
// The override ensure that the QTEMP file is populated.
ReportPgm();
run('DLTOVR *ALL':200);
//Open the cursor for Stored Proc
Exsr Resultset;
return;
/End-Free
C*******************************************************
C* Opens the cursor for Stored Proc *
C*******************************************************
C Resultset Begsr
*
C/EXEC SQL
C+ DECLARE C1 CURSOR FOR SELECT * FROM QTEMP/EMPPFBK
C/END-EXEC
C/EXEC SQL
C+ Open C1
C/END-EXEC
C/EXEC SQL
C+ set result sets cursor c1
C/END-EXEC
C Resultset endsr