Sorting with OPNQRYF on Incomplete Fields
Q. How can I sort a file by part of a field? I have the field put together on the MAPFLD parameter (concatenating a few substrings) and then it's specified in the KEYFLD parameter as *MAPFLD/name, but OPNQRYF won't accept it. I don't want to use FMTDTA. I know there has to be a simple answer, but IBM's manuals are very terse and unhelpful.
A. All key fields in OPNQRYF must exist in the record format specified in the FORMAT parameter, which defaults to the value in the FILE parameter. You'll have to create a dummy physical file which has all the fields you need from the database file(s) listed in the FILE parameter, plus the fields you want to sort on.
Let's say you're reading a file called FILEA, which has fields FLD1, FLD2 and FLD3. You want to sort on a substring of FLD2.
First, create a dummy physical file (let's call it WORKFILE) with fields FLD1, FLD2, FLD3 and SORT. Compile your high-level language program to read WORKFILE. By the way, WORKFILE doesn't even need to have a member.
The process shown in 3 should get you headed in the right direction.
The process shown in Figure 3 should get you headed in the right direction.
TechTalk: Sorting with OPNQRYF on Incomplete Fiel
Figure 3 Incomplete Key Sort
OVRDBF FILE(WORKFILE) TOFILE(FILEA) SHARE(*YES) OPNQRYF FILE((FILEA)) FORMAT(WORKFILE) + MAPFLD((SORT '%SST(FLD2 2 2)')) + KEYFLD((SORT)) CALL your program CLOF OPNID(FILEA) DLTOVR FILE(WORKFILE)
LATEST COMMENTS
MC Press Online