From: Ken Stratton
The AS/400 manuals say that I can use a mapped field as the key field when using Open Query File (OPNQRYF). Every time I try though, I get an error message stating that the field used for KEYFLD must exist in the physical file.
With some files, I can create a mapped field using the same name as another field that exists in the physical file?as long as that field is not referenced by any program that reads the open data path (ODP) created by the OPNQRYF. However, when a program needs to use all of the fields in the physical file, I have to create a logical file (Yuck!).
From: Ted Holt
To: Ken Stratton
Create another physical file that contains no data. This dummy file doesn't even have to have a member. It needs all the fields from the real file (or at least the ones your RPG program is using), plus the mapped field.
Write your RPG program to read the dummy file. In your CL program, override the dummy file to the real file. Be sure to tell it to share the open data path?SHARE(*YES).
In the OPNQRYF command, put the real file name in the FILE parameter and the dummy file name in the FORMAT parameter. Be sure to include the mapped field definition, just as you're already doing.
Here's an example of the CL program:
OVRDBF FILE(DUMMY) + TOFILE(REALFILE) + SHARE(*YES) OPNQRYF FILE((REALFILE)) + FORMAT(DUMMY) + KEYFLD((MF1)) + MAPFLD((MF1 '%SST( etc. ... CALL PGM(RPGPGM) CLOF OPNID(REALFILE) DLTOVR FILE(DUMMY)
The RPG program (RPGPGM) file specification references file DUMMY.