How to copy tables between two libraries without repeat CPYF command using script?

5 pts.
iSeries v7r1
I need to copy tables from library to another on the same iSeries v7.1. Is there a script to copy multible tables without repeat CPYF command?

Software/Hardware used:
as 400,

Answer Wiki

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

We’ve created a generic CL program which accepts 2 parameters. The first parameter is the “From” Library and the 2nd parm is the “TO” Library. The “TO” library is the library that you want to copy the data to and of course the “From” is where it’s coming from. We do a chkobj to verify that both libraries exist then we do a display object description DSPOBJD of all files in that library to an outfile. We do an ovrdbf to that outfile and then rcvf. We then check the object attribute and if it’s not a type PF we just skip it and read the next one. We continue doing this and when we get to a PF we do a cpyf. We have monitor message for empty files and we count the number of files read in and the number of files copied and log this at the end. It’s pretty simple but works well when you are trying to refresh data from one environment to another for testing or QA.

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.
  • WoodEngineer
    You could put the library names in a data base file, then ready that file in a CL program and issue a CPYF for each record.
    8,225 pointsBadges:
  • WoodEngineer
    My apologies . . . that shoud have said "put the table names in a data base file".
    8,225 pointsBadges:
  • TomLiotta there a script to copy multible tables without repeat cpyf command? First, you can create any "script" you want. It's likely that no one has ever created a script that would copy your files, though. Copying files from one library to another can take some work because there are many types of files. Different types may need different handling. However, under some lucky circumstances, you can use a single command:
    CPY OBJ( '/qsys.lib/mylib.lib/abc*.file' )
        TODIR( '/qsys.lib/newlib.lib' )
    That will copy all files with names beginning "ABC" in library MYLIB to a library named NEWLIB. At least, it will copy many such files -- some file types don't copy easily. I strongly suggest that you run a series of tests of the CPY command before trying to copy sets of files with it. It might teach a lot about things that might trip up any "script". Tom
    125,585 pointsBadges:
  • carlosir
    The CPY does not copy the logical files. Thanks.
    75 pointsBadges:
  • aceofdelts
    If you set up these tables in there own library then you might be able to CRTDUPOBJ *ALL to create to the target library.
    2,550 pointsBadges:
  • GregManzo
    Or you could do a SAVLIB & RSTLIB into a *SAVF (or if you don't want everything SAVOBJ <list of files>, RSTOBJ). This has the advantage that LF indexes can be saved & restored instead of re-built. You don't even necessarily need a script 'cos it's only two commands and you're done.
    2,960 pointsBadges:

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.


Share this item with your network: