Application/example using OPNQRYF

pts.
Tags:
Programming Languages
RPG
Can somebody give me an example where they felt that using OPNQRYF would be an optimized solution rather than creating a logical file?

Answer Wiki

Thanks. We'll let you know when a new response is added.

OPNQRYF is appropriate when you want complex dynamic selection outside of the application. You may have a standard report that runs for all salesmen or all customers. Someone asks for the report only for their customers or for a specific date range or both. Instead of creating a new report with the limited criteria, you create a CL with OPNQRYF to select the records to pass to the Report. The CL could have a command front end to let the user fill in the values for any number of fields, then build the selection parameter for the OPNQRYF.

This is an example CL to build the selection criteria:

PGM PARM(&INVDATE &SALE) /* Select Invoice Date +
Range */

DCL VAR(&INVDATE) TYPE(*CHAR) LEN(7)
DCL VAR(&IHIDAT) TYPE(*CHAR) LEN(8)
DCL VAR(&SALE) TYPE(*CHAR) LEN(3)
DCL VAR(&QRYSLT) TYPE(*CHAR) LEN(50)

CVTDAT DATE(&INVDATE) TOVAR(&IHIDAT) FROMFMT(*CYMD) +
TOFMT(*YYMD) TOSEP(*NONE) /* Convert date */

CHGVAR VAR(&QRYSLT) VALUE(‘IHIDAT *GE’ |> &IHIDAT +
|> ‘*AND IHSALE = ”’ |< &SALE |< ””)

OVRDBF FILE(SE1ISH) SHARE(*YES)
OPNQRYF FILE((SE1ISH)) OPTION(*ALL) QRYSLT(&QRYSLT) +
KEYFLD(*FILE)
CALL UPDSALE
DLTOVR SE1ISH
ENDPGM

======================================================================

I had to create a selection function that required an index built over a compound key that was built from fields that came from two different files. OPNQRYF is the only way to generate such an index.

Tom

Discuss This Question: 1  Reply

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
  • WoodEngineer
    OPNQRYF is a very powerful tool with tons of features. It can summarize data and make it available to your program without requiring you to write code to perform the summary yourself. It can also calc temporary values that can then be used to index a file. Using a format file it can hand you a subset of fields from one file or a set of joined files. As I said, it has tons of features. At a user group meeting an IBM'er told us that it is impossible to write an application program that could select records faster than OPNQRYF. Of course, if you have a logical that has already selected the records you want that would probably still be faster. You asked about using OPNQRYF instead of using a logical. If the logical will be used infrequently we tend to use OPNQRYF to save system resources. By that I mean a program that runs once a week or once a month. With all that said, I'd recommend using SQL instead of OPNQRYF if that option is available to you. Coding OPNQRYF statements can be a bit tedious. Good luck!
    6,305 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following