AS/400: Merge same physical file from two different libraries

1465 pts.
Tags:
AS/400
Physical File
RPGLE
I have two libraries with same physical files. Now I want to merge both the physical files data in a single physical file in third library with unique records. My problem is the physical file doesn't have key fields. Solution can be in SQLRPGLE or RPGLE. Thanks in advance.
0

Answer Wiki

Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

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.
  • Splat
    Easiest method I can think of is to create a logical file over the target physical keyed on the fields you require to be unique.  When writing to the target file use SetLl to determine if the data exists in the target file prior to the write operation.
    12,915 pointsBadges:
    report
  • ToddN2000
    Easiest way is using a joined logical file. Set your unique keys there.
    If you know there is duplicate data then I'd follow Splat's suggestion.
    134,585 pointsBadges:
    report
  • pdraebel
    In case you established the Logical with the unique keys a simple CPYF will do the trick. Remember to specify ERRLVL(*NOMAX)
    7,545 pointsBadges:
    report
  • ToddN2000
    Seems like an unusual request. Can you explain the business reason for the request? There may be more efficient alternatives to the issue for the merging of the files.
    134,585 pointsBadges:
    report
  • philpl1jb

    With SQL

    Insert into lib3/myfile

    (Select * from lib1/myfile

    union

    Select * from lbi2/myfile)

    54,090 pointsBadges:
    report
  • TheRealRaven
    Something like this seems good:
    create table mylib.mergetable as ( 
        select distinct * from (
               SELECT col1, col2, col3 ... FROM table1
               union
               SELECT col1, col2, col3 ... FROM table1
                               ) t1
    ) with data 
    35,995 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.

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

Following

Share this item with your network: