Merging of files in AS400

0 pts.
Tags:
DB2 Universal Database
RPG
RPGLE
What is the use of merging files in AS400? How do you do this?
ASKED: March 1, 2007  5:22 AM
UPDATED: February 23, 2010  1:11 AM

Answer Wiki

Thanks. We'll let you know when a new response is added.

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

Discuss This Question: 2  Replies

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
  • Kkgoldi
    WHAT IF YOU HAVE multiple FILES (1000'S) - WHAT IS THE BEST WAY TO DO THIS WITH OUT KEYING IN EACH FILE NAME?
    15 pointsBadges:
    report
  • TomLiotta
    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
    125,585 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following