× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



We have a program that looks like this (this one is sort of old) for each
file we want to select records using sql but process using the cycle. This
one reads the lda to get the sql statement that was built by the selection
process. We have another technique where we write the sql statement to a
file keyed by job/user/number and this program retrieves it. The only line
of code that changes in this program from file to file is the "Buffer".
Everything else stays the same. The rest could probably be a /copy. Long
ago worked for us to replace s36 ocl , #gsort and program described files
for report writing. I'm sure it could be improved upon. Don't know if
opnqryf is easier or more understandable or not. Guess I just prefer
creating sql.

The special program opens/reads/closes the file and passes the buffer to
the report program.

Program CUSTSQL

H option(*srcstmt: *nodebugio) dftactgrp(*no) actgrp(*caller)

D Buffer e ds extname(CUSTOMER)
D LDA uds dtaara(*LDA)
D SqlCommand 1 1000

C *ENTRY PLIST
C PARM OPTION 1
C PARM STATUS 1
C PARM ERROR 5 0
C PARM BUFFER
C
C/EXEC SQL
C+ set option closqlcsr=*endactgrp
C/end-exec
C
C select
C
C* file open processing
C when option = 'O'
C reset Buffer
C in lda
C
C/EXEC SQL
C+ prepare p1 from :SqlCommand
C/end-exec
C
C/EXEC SQL
C+ declare c1 cursor for p1
C/end-exec
C
C/EXEC SQL
C+ open c1
C/end-exec
C
C* file close processing
C when option = 'C'
C/exec sql
C+ close c1
C/end-exec
C eval *inlr = *on
C
C
C* file read processing
C when option = 'R'
C/exec sql
C+ fetch c1 into :Buffer
C/end-exec
C endsl
C
C select
C when sqlstt < '02000'
C eval Status = '0'
C when sqlstt = '02000'
C eval Status = '1'
C other
C eval Status = '2'
C endsl

C move sqlstt error
C return



We replaced the original fspec in the report program with

FCUSTOMER IP E SPECIAL PGMNAME('CUSTSQL')



Jim


message: 3
date: Tue, 21 Feb 2012 12:46:28 -0600
from: Scott Klement <midrange-l@xxxxxxxxxxxxxxxx>
subject: Re: Must I use OPNQRYF

Hmmm... I didn't think about using SPECIAL files. I guess that makes
sense, but... wouldn't OPNQRYF have been easier, both to code and
understand?

On 2/21/2012 9:34 AM, James Horn wrote:
I had some big level break programs I didn't want to change. I used a
"special file" to use sql to return the records to the main program.
works
great for me. Only needed to change 1 line in the program, the file spec,
and build a little rpg program to do what the opnqryf (or gsort or #gsort)
did before.

As an Amazon Associate we earn from qualifying purchases.

This thread ...


Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.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 on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.