×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Using built-in copy command without duplicate records

Using built-in copy command without duplicate records

Using built-in copy command without duplicate records

(OP)
I need to copy records from the same file but on another library. It's like copy lib1/file1 to lib2/file1, but lib2/file1 is already existing and other records from lib1/file1 are already in lib2/file1.  So what I'm hoping to do is to copy only those that are not existing in lib2/file1.  Both files have the same key fields (eg. field1, field5, field8)

I hope there's a way to do this without doing a program like CL and etc.

I would highly appreciate the help.

Thank you.

RE: Using built-in copy command without duplicate records

A simple sql stm will do the trick.

CODE

Insert into lib2/file1
( Select lib1/file1 a
    Exception Join lib2/file1 b on a.field1 = b.field1
    and a.field5 = b.field5 and a.field8 = b.field8 )

RE: Using built-in copy command without duplicate records

Can't update the previous post. Must read

CODE

Insert into lib2/file1
( Select a.* from lib1/file1 a
    Exception Join lib2/file1 b on a.field1 = b.field1
    and a.field5 = b.field5 and a.field8 = b.field8 )

RE: Using built-in copy command without duplicate records

(OP)
Thanks Mercury2, but I was hoping not to use SQL as this will make me create an object for the sql code.  I just want to make it much simplier like using CPYF(not familiar if there's an option to do the trick here).  

In a job scheduler I have a job that looks like this :

Seq    Command                                                
 10    CLRPFM FILE(PFILE1)                                  
 20    CALL PGM(PGMSQL) PARM('parmA' 'parmB')
 40    CALL PGM(PGMC) PARM('parmA' 'parmB')                 

 50    /* copy code here */

 60    CALL PGM(PGMCL)


Thanks in advance.

RE: Using built-in copy command without duplicate records

I don't think you could make it "simpler" than that.  You don't need another object.  But you would need to put the SQL code into a source member, then use RUNSQLSTM to execute it at the proper time.

Other option is to use a very simple RPG pgm.  I don't think there is any OS command to do what you want.

RE: Using built-in copy command without duplicate records

In CL. yopu can also do a CPYF with MBROPT(*UPDADD). This will replace any records with the same key values, and add the ones that don't exist. It may not be what you want, though.

Solum potestis prohibere ignes silvarum.

RE: Using built-in copy command without duplicate records

(OP)
Thanks flapeyre, actually this should work fine. But my next problem is that the master file I'm using is not using UNIQUE key fields.

Anyway, the next simplest thing to do is SQL.

Still, if incase you all guys ran across with a solution to this, please...let me know.

Many thanks.

RE: Using built-in copy command without duplicate records

Yes, I should have noted that using *UPDADD on CPYF requires unique key values. In that case, you might have to either use SQL or write a small RPG program to add your records (SETLL with the key and dont't write the new record if %FOUND).

Solum potestis prohibere ignes silvarum.

RE: Using built-in copy command without duplicate records

I've just learnt that
CPYF FROMFILE(LIB1/FILE1) TOFILE(LIB2/FILE1) MBROPT(*ADD) ERRLVL(*NOMAX)
will not insert the lines with keys already existing (duplicates) in the tofile. So maybe that one will fit your needs more .

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close