-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ac7333c
commit 11425db
Showing
1 changed file
with
85 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
**free | ||
//------------------------------------------------------------------------------------------- | ||
// QSHQRYTMPR - Replace SQL template parameters with actual data | ||
// values and update the selected SQL statement passed in. | ||
//------------------------------------------------------------------------------------------- | ||
|
||
// Program DS | ||
Dcl-Ds *N psds; | ||
PROGID *PROC; | ||
End-Ds; | ||
|
||
// Parameter name list passed from CL | ||
Dcl-Ds parmnames; | ||
parmcount bindec(4); | ||
parms char(100) dim(30); | ||
End-Ds; | ||
// Parameter value list passed from CL | ||
Dcl-Ds parmvalues; | ||
parmvalcount bindec(4); | ||
parmvals char(100) dim(30); | ||
End-Ds; | ||
|
||
// Program *entry parameter list prototype | ||
Dcl-pi QSHQRYTMPR; | ||
p_sql CHAR(5000); | ||
p_parms CHAR(3002); | ||
p_parmvals CHAR(3002); | ||
p_rtnerror CHAR(1); | ||
End-pi ; | ||
|
||
DCL-S curelem packed(5:0); | ||
DCL-S vparm varchar(100); | ||
DCL-S vparmval varchar(100); | ||
|
||
// Initialize parm arrays from passed in values | ||
p_rtnerror='0'; | ||
parmnames=p_parms; | ||
parmvalues=p_parmvals; | ||
|
||
// Each parm name passed must also have a value. | ||
if (parmcount <> parmvalcount); | ||
p_rtnerror='1'; | ||
*inlr=*on; | ||
return; | ||
endif; | ||
|
||
// If no parms passed, exit now. All good. Nothing to do | ||
if (parmcount=0 or parmvalcount=0); | ||
p_rtnerror='0'; | ||
*inlr=*on; | ||
return; | ||
endif; | ||
|
||
// Monitor for errors | ||
Monitor; | ||
|
||
// Loop through all parms and update current | ||
// source line if needed. | ||
for curelem = 1 to parmcount; | ||
|
||
// Extract scanfor parm and replacement value | ||
vparm=%trim(parms(curelem)); | ||
vparmval=%trim(parmvals(curelem)); | ||
|
||
// This handles mixed case, upper and lower | ||
// for the keywords | ||
// Replace parm with value if found | ||
p_sql=%scanrpl(vparm:vparmval:p_sql); | ||
// Replace uppercase with value if found | ||
p_sql=%scanrpl(%upper(vparm):vparmval:p_sql); | ||
// Replace lowercase with value if found | ||
p_sql=%scanrpl(%upper(vparm):vparmval:p_sql); | ||
|
||
endfor; | ||
|
||
// Monitor for errors | ||
On-Error; | ||
p_rtnerror='3'; | ||
*inlr=*on; | ||
return; | ||
Endmon; | ||
|
||
// Exit | ||
*inlr=*on; | ||
return; |