This example shows the use of derived fields.
Assume that you have the Price and Qty fields in the record format. You can multiply one field by the other by using the Open Query File (OPNQRYF) command to create the derived Exten field. You want FILEA to be processed, and you have already created FILEAA. Assume that the record formats for the files contain the following fields:
|
The Exten field is a mapped field. Its value is determined by multiplying Qty times Price. It is not necessary to have either the Qty or Price field in the new format, but they can exist in that format, too, if you want. The Brfdsc field is a brief description of the Descrp field (it uses the first 10 characters).
OVRDBF FILE(FILEAA) TOFILE(FILEA) SHARE(*YES) OPNQRYF FILE(FILEA) FORMAT(FILEAA) + MAPFLD((EXTEN 'PRICE * QTY') + (BRFDSC 'DESCRP')) CALL PGM(PGMF) /* Created using file FILEAA as input */ CLOF OPNID(FILEA) DLTOVR FILE(FILEAA)
Notice that the attributes of the Exten field are those defined in the record format for FILEAA. If the value calculated for the field is too large, an exception is sent to the program.
It is not necessary to use the substring function to map to the Brfdsc field if you only want the characters from the beginning of the field. The length of the Brfdsc field is defined in the FILEAA record format.
MAPFLD((FLDC ' " " ')(FLDN 0))
Notice quotation marks enclose a blank value. By using a constant for the definition of an unused field, you avoid having to create a unique format for each use of the OPNQRYF command.