0 pts.
 Merging of files in AS400
What is the use of merging files in AS400? How do you do this?

Software/Hardware used:
ASKED: March 1, 2007  5:22 AM
UPDATED: February 23, 2010  1:11 AM

Answer Wiki:
The merging of files is done by using the CPYF (Copy File) command and specifying the *ADD option to append the data from one file to another: CPYF FROMFILE(A) TOFILE(B) MBROPT(*ADD) FMTOPT(xxx) The FMTOPT parameter tells the system how to do the copy, for example: FMTOPT(*NOCHK) means copy left to right, character by character. FMTOPT(*MAP) means only copy fields with the same names in both files. Any fields in the TOFILE that aren't in the FROMFILE are initialised with default values. There are many other parameters for the command which allow you to only copy a selection of records, etc, but this should get you started. All the best Jonathan ============================================================ Or merging files is done with the MRGSRC command (or PDM option 55). Normal help text for the command describes a main use -- merging updates into source members. Tom
Last Wiki Answer Submitted:  January 3, 2010  10:39 am  by  astradyne   370 pts.
All Answer Wiki Contributors:  astradyne   370 pts.
To see all answers submitted to the Answer Wiki: View Answer History.


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


 

WHAT IF YOU HAVE multiple FILES (1000′S) – WHAT IS THE BEST WAY TO DO THIS WITH OUT KEYING IN EACH FILE NAME?

 15 pts.

 

IMO, the “best” way is to create an ILE CL procedure that lists the files, then processes the list against a CPYF command. The list might be in a user space or in a file. I suspect that you’re learning this kind of thing, so the DSPFD command might be a good start:

DSPFD FILE( MyLib/*ALL ) TYPE(*MBRLIST) OUTPUT(*OUTFILE) FILEATR(*PF) OUTFILE( QTEMP/MyMbrList )

Your proc should then start RCVF in a loop to process each row in the file.

Two things you might want to stay aware of — it lists members not files and it gives no indication of file (or members) that exist in one library but not the other.

The reason for listing members is to give the capability of handling files with more than one member. CPYF actually copies members, not files. The output file from the command lets you tailor your CPYF appropriately. Each row also tells the total number of members in the file, so you could have coding that skips those records for later review. If no rows should a member count other than “1″, there’s no problem.

For the second point, you might also want to run a similar command against the second library. Use the two outfiles for a comparison before you actually decide how to proceed. If you find zero differences, then there’s no problem.

For any exceptions, you might edit a copy the outfile to delete exception rows. That would make your proc simpler. You wouldn’t need extensive error handling. Run your proc against the editted copy. Handle exceptions manually if there are only a couple.

In any case. my answer is simply to automate the process. Technically, I think it might be possible with an absolute minimum of seven or eight CL statements.

Tom

 107,845 pts.