275 pts.
 FILES
I have two physical files are PF1 & PF2 ,in that i need to copy the records from PF! file to PF2 file but tw0 files have different field names and have same attributes. Example: PF1: Name 25 A Code 10 S 0 Location 30 A PF2: LCode 10 S 0 LLocation 30 A LName 25 A plz guide me and thanks in advance...

Software/Hardware used:
AS400
ASKED: January 12, 2012  4:55 AM
UPDATED: February 28, 2012  11:54 AM

Answer Wiki:
PF1: Name 25 A Code 10 S 0 Location 30 A PF2: LCode 10 S 0 LLocation 30 A LName 25 A we can't copy pf1 to pf2, because pf1 and pf2 field are interchanged. so we can't copy.. if you try to copy your records, it ll show like this '+++++++' best you try to change field order like this.. (must change the field order PF1 or PF2) PF2: LName 25 A LCode 10 S 0 LLocation 30 A after using cpyf command... don't forget the below step to fill.... <b>Record format field mapping . . > *NOCHK</b>
Last Wiki Answer Submitted:  January 12, 2012  5:44 am  by  pdsathishkumar   3,740 pts.
All Answer Wiki Contributors:  pdsathishkumar   3,740 pts.
To see all answers submitted to the Answer Wiki: View Answer History.


Discuss This Question:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _


 

Hi,

Use the fallowing command

CPYF FROMFILE(QTEMP/PF1) TOFILE(QTEMP/PF2) MBROPT(*ADD) FMTOPT(*NOCHK)

 130 pts.

 

But Before Using this command your PF2 fiedl sequence is same as PF1 field sequence

 130 pts.

 

you can:

  1. write a program to move the data to the corresponding fields and write the PF2 records
  2. use an INSERT SQL statement to select the data from PF1 in the proper sequence for PF2
 7,185 pts.

 

Since the field names are different and the fields are in different locations, you can’t directly use simple tools like CPYF.

SQL could help though:

CREATE VIEW mylib/PF1V AS
 SELECT CODE as LCODE, LOCATION as LLOCATION, NAME as LNAME FROM mylib/PF1

Then you can do this:

CPYF FROMFILE( mylib/PF1V ) TOFILE( mylib/PF2 ) MBROPT( *ADD ) FMTOPT( *MAP )

By creating a VIEW over PF1 that presents the columns with new names, you can use the *MAP option of the CPYF command.

Tom

 108,330 pts.