Example 4: Copying from an open query file

 

This example shows how to create a copy of the output of a dynamic join using the Open Query File (OPNQRYF) and Copy from Query File (CPYFRMQRYF) commands. Assume that you want to create a physical file that has the format and data of the join of FILEA and FILEB, and that the files contain the following fields:

FILEA        FILEB      JOINAB Cust         Cust       Cust Name         Amt        Name Addr                    Amt
The join field is Cust, which exists in both files. To join the files and save a copy of the results in a new physical file MYLIB/FILEC, you can specify:
OPNQRYF FILE(FILEA FILEB) FORMAT(JOINAB) +
  JFLD((FILEA/CUST FILEB/CUST)) +
  MAPFLD((CUST 'FILEA/CUST')) OPNID(QRYFILE)
CPYFRMQRYF  FROMOPNID(QRYFILE) TOFILE(MYLIB/FILEC) CRTFILE(*YES)

The file MYLIB/FILEC will be created by the CPYFRMQRYF command. The file will have file attributes like those of FILEA although some file attributes might be changed. The format of the file will be like JOINAB. The file will contain the data from the join of FILEA and FILEB using the Cust field. File FILEC in library MYLIB can be processed like any other physical file with control language (CL) commands, such as the Display Physical File Member (DSPPFM) command and utilities, such as Query.

 

Parent topic:

Copying from an open query file

 

Related concepts


Database file management