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)
Business users want new applications now. Market and regulatory pressures require faster application updates and delivery into production. Your IBM i developers may be approaching retirement, and you see no sure way to fill their positions with experienced developers. In addition, you may be caught between maintaining your existing applications and the uncertainty of moving to something new.
IT managers hoping to find new IBM i talent are discovering that the pool of experienced RPG programmers and operators or administrators with intimate knowledge of the operating system and the applications that run on it is small. This begs the question: How will you manage the platform that supports such a big part of your business? This guide offers strategies and software suggestions to help you plan IT staffing and resources and smooth the transition after your AS/400 talent retires. Read on to learn:
LATEST COMMENTS
MC Press Online