Skip to content

Commit 5f39d2e

Browse files
Create QSHQRYSR2R.RPGLE
1 parent bfc2c3e commit 5f39d2e

File tree

1 file changed

+115
-0
lines changed

1 file changed

+115
-0
lines changed

QSHQRYSR2R.RPGLE

+115
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
**free
2+
//-------------------------------------------------------------------------------------------
3+
// QSHQRYSR2R - Replace SQL template parameters with actual data
4+
// values and update the selected temporary source member.
5+
//-------------------------------------------------------------------------------------------
6+
DCL-F TMPQRYSRC DISK(*EXT)
7+
Usage(*UPDATE) RENAME(TMPQRYSRC:TMPSRCR);
8+
9+
// Program DS
10+
Dcl-Ds *N psds;
11+
PROGID *PROC;
12+
End-Ds;
13+
14+
// Parameter name list passed from CL
15+
Dcl-Ds parmnames;
16+
parmcount bindec(4);
17+
parms char(100) dim(30);
18+
End-Ds;
19+
// Parameter value list passed from CL
20+
Dcl-Ds parmvalues;
21+
parmvalcount bindec(4);
22+
parmvals char(100) dim(30);
23+
End-Ds;
24+
25+
// Program *entry parameter list prototype
26+
Dcl-pi QSHQRYSR2R;
27+
p_parms CHAR(3002);
28+
p_parmvals CHAR(3002);
29+
p_rtnerror CHAR(1);
30+
End-pi ;
31+
32+
DCL-S curelem packed(5:0);
33+
DCL-S vparm varchar(100);
34+
DCL-S vparmval varchar(100);
35+
36+
// Initialize parm arrays from passed in values
37+
p_rtnerror='0';
38+
parmnames=p_parms;
39+
parmvalues=p_parmvals;
40+
41+
// Each parm name passed must also have a value.
42+
if (parmcount <> parmvalcount);
43+
p_rtnerror='1';
44+
*inlr=*on;
45+
return;
46+
endif;
47+
48+
// If no parms passed, exit now. All good. Nothing to do
49+
if (parmcount=0 or parmvalcount=0);
50+
p_rtnerror='0';
51+
*inlr=*on;
52+
return;
53+
endif;
54+
55+
// Monitor for errors
56+
Monitor;
57+
58+
// Set to beginning of file
59+
setll *start tmpqrysrc;
60+
61+
// Read all records in source member and scan/replace
62+
// keyword values if not a comment line starting with: --
63+
dou %eof(tmpqrysrc);
64+
65+
// Read next record
66+
read tmpqrysrc;
67+
68+
// If end of file, exit process loop
69+
if %eof(tmpqrysrc);
70+
leave;
71+
endif;
72+
73+
74+
// Scan and replace parm values into SQL statement.
75+
if %trim(srcdta) <> '';
76+
77+
// Only process non-comment records
78+
if %subst(srcdta:1:2) <> '--';
79+
80+
// Loop through all parms and update current
81+
// source line if needed.
82+
for curelem = 1 to parmcount;
83+
84+
// Extract scanfor parm and replacement value
85+
vparm=%trim(parms(curelem));
86+
vparmval=%trim(parmvals(curelem));
87+
88+
// This handles mixed case, upper and lower
89+
// for the keywords
90+
// Replace parm with value if found
91+
srcdta=%scanrpl(vparm:vparmval:srcdta);
92+
// Replace uppercase with value if found
93+
srcdta=%scanrpl(%upper(vparm):vparmval:srcdta);
94+
// Replace lowercase with value if found
95+
srcdta=%scanrpl(%upper(vparm):vparmval:srcdta);
96+
97+
endfor;
98+
99+
// Update temporary SQL source member with changes
100+
update tmpsrcr;
101+
102+
endif;
103+
endif;
104+
105+
enddo;
106+
// Monitor for errors
107+
On-Error;
108+
p_rtnerror='3';
109+
*inlr=*on;
110+
return;
111+
Endmon;
112+
113+
// Exit
114+
*inlr=*on;
115+
return;

0 commit comments

Comments
 (0)