CPYTOIMPF and multiple record formats

55 pts.
Tags:
Alternating Record Formats
CPYTOIMPF
I have four different files with four different record formats which need to be copied into one file with alternating record formats, (rec fmt #1, rec fmt#2, rec fmt#3 rec fmt #4 in that order). The file also has to be field delimited with pipes, and so I thought CPYTOIMPF would work, but I am having trouble since CPYTOIMPF doesn't allow a mult-format logical to be used. How do I get around this?

Answer Wiki

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

Copy each file using CPYTOIMPF with pipe delimited to a work files — FILE1, FILE2, FILE3, FILE4

Then either
an RPG program would read first record from each and write to FILE5 in the order you want until eof

or

CL uses CPYF fromRec &wrkRec# toRec &wrkRec# add to member from FILE1 to FILE5
from FILE2 to FILE5

add 1 to &wrkRec# and continue copy until all records are copied.

Discuss This Question: 6  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
  • Gilly400
    Hi, Can you try using the CPYTOIMPF on the four individual physicals to create four new physicals with the pipe delimiters, then build your logical file over the four new (delimited) files. Then you should be able to do a CPYF to create a physical file in the order that you want with the pipe delimiters. You can then use CPYTOSTMF to get the file into the IFS if necessary. Somewhat more complicated, but should get the job done. Regards, Martin Gilbert.
    23,730 pointsBadges:
    report
  • Gilly400
    Hi, Just an extra bit - you can use substringed fields in logicals to get the required result from the delimited files. Regards, Martin Gilbert.
    23,730 pointsBadges:
    report
  • philpl1jb
    It's going to be tricky to make that logical since the pipe delimited trims trailing blanks
    49,960 pointsBadges:
    report
  • Gilly400
    Hi, You're right - I hadn't thought about the trimming. Although - if the first few fields are fixed length and used to identify which type of record you need, then you could just substring the fields that you need for identification and have one substring for "the rest". Regards, Martin Gilbert.
    23,730 pointsBadges:
    report
  • Mattheus
    Thanks guys, I finally did this by creating a separate file, and using the whole record as the key field. This is the to file for the CPYTOIMPF. Then I had to change my File1 through File4 specs to make the ordering correct. The record type (1, 2, 3, or 4) had to be placed after account number so that all the records for the account number would be correct. After my program wrote to the FileX files, I used CPYTOIMPF leaving the blanks in the fields so that I knew exactly where to find the key. I wrote another program to switch the order of the key fields, (move back the record type in the first position), and write to another file. There were detail as well as header records so I had to make sure that all of the records stayed together for each account. Martin, I will probably try your multiformat logical / substring method. I believe this will eliminate a bunch of unneccessary code in the program that writes the final output. My solution was not so elegant, but I don't know if my boss will want me to revisit the issue.
    55 pointsBadges:
    report
  • Mattheus
    Don't kill me, but after I discussed with my boss what I did, he wants me to just add extra fields with a default value '|' to delimit the other fields, and then use a multi-format logical on those files to just write to the final file without using the CPYTOIMPF command! Thanks again for your input, Martin and Philpl1jb !
    55 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