Q: I need a little help with Open Query File (OPNQRYF). I have a multiformat logical file built over two physical files-the invoice header and detail files. I want to select certain invoices to print. I am having no problem building the correct string for the QRYSLT parameter. My problem is in using the multiformat logical file. I get record format errors. I want to use this file because it will plug right into the current invoice run program. What do I need in the FILE parameter? What about the FORMAT parameter?
- Eric Hill
A: OPNQRYF will run over a multiformat logical file, but you have to choose one of the formats in the third part of the FILE parameter. One OPNQRYF command won't return records from different formats. These are your options:
1. Run two OPNQRYF commands: one over the header file and one over the detail file. They can reference the physical files or the correct formats of the logical file.
2. Run one OPNQRYF command over the header to select the invoices you want. In your RPG program, read the detail records for each header record with random processing (SETLL, READE). This is assuming that the detail file is keyed on field(s) from the header file, which is usually the case.
3. Join the two files with a join logical. Run the OPNQRYF command over the join logical.
4. Join the two files with one OPNQRYF command.
In my opinion, option 1 is the worst. Option 2 is OK if you don't have to sort on fields from both files. I would use option 3 only if I had an existing join logical. That is, I wouldn't create a join logical just for this. Option 4 is good, but if the files are big, performance can get pretty bad. Keep in mind that options 3 and 4 won't work if you're updating the files. In your case, since you're reprinting invoices, I'd say option 2 is probably the way to go.
- Ted Holt
LATEST COMMENTS
MC Press Online