How do I copy a Data Set or a Data Set member? - IBA-mainframe-dev/Global-Repository-for-Mainframe-Developers GitHub Wiki

How do I copy a Data Set or a Data Set member?

This document contains various operation for copying of a Data Set or a Data Set member

How to copy a PDS member to new Sequential Data Set and vice versa?

Copy a member to new Sequential Data Set

Note: It is good practice to use Referback (Backward Reference) in DCB parameter. You will ensure data set compatibility this way.

//JCLLIB06 JOB NOTIFY=&SYSUID,MSGLEVEL=(1,1)         
//COPYMEM  EXEC PGM=IEBGENER                         
//SYSPRINT DD SYSOUT=*                               
//SYSIN    DD DUMMY                                  
//SYSUT1   DD DSN=[Data set name]([Member name]),DISP=SHR    
//SYSUT2   DD DSN=[Data set name],DISP=(NEW,CATLG),  
//         DCB=*.SYSUT1,SPACE=(TRK,(1,1))            

Copy a Sequential Data Set into member of newly created PDS

//JCLLIB07 JOB NOTIFY=&SYSUID,MSGLEVEL=(1,1)                  
//COPYMEM  EXEC PGM=IEBGENER                                  
//SYSPRINT DD SYSOUT=*                                        
//SYSIN    DD DUMMY                                           
//SYSUT1   DD DSN=[Data set name],DISP=SHR                    
//SYSUT2   DD DSN=[Data set name]([Member name]),DISP=(NEW,CATLG),     
//         DCB=*.SYSUT1,SPACE=(TRK,(1,1,5))                   

How to copy a Partitioned Data Set PDS?

To a new PDS

Specify values for #input_pds,#output_pds, #unit and #volume; change SPACE and DCB if needed;

//STEP1    EXEC PGM=IEBCOPY
//SYSPRINT DD   SYSOUT=*                          
//SYSIN    DD   DUMMY                             
//SYSUT1   DD   DSN=#input_pds,DISP=SHR
//SYSUT2   DD   DSN=#output_pds,DISP=(NEW,CATLG),
//           DCB=(LRECL=80,RECFM=FB,BLKSIZE=6160),
//           SPACE=(CYL,(5,5,5)),
//           UNIT=#unit,
//           VOL=SER=#volume

Note: the original #input_pdse dataset will not be removed.

To an already existing PDS without members replacement

Specify values for #input_pds,#output_pds.

//STEP1    EXEC PGM=IEBCOPY
//SYSPRINT DD   SYSOUT=*                          
//SYSUT1   DD   DSN=#input_pds,DISP=SHR
//SYSUT2   DD   DSN=#output_pds,DISP=OLD
//SYSIN    DD   *
  COPY INDD=SYSUT1,OUTDD=SYSUT2
/*

Note: the original #input_pdse dataset will not be removed.

To an already existing PDS with members replacement

Specify values for #input_pds,#output_pds.

//STEP1    EXEC PGM=IEBCOPY
//SYSPRINT DD   SYSOUT=*                          
//SYSUT1   DD   DSN=#input_pds,DISP=SHR
//SYSUT2   DD   DSN=#output_pds,DISP=OLD
//SYSIN    DD   *
  COPY INDD=((SYSUT1,R)),OUTDD=SYSUT2,LIST=YES
/*

Note: the original #input_pdse dataset will not be removed.

How to copy selected members from partitioned data set PDS?

Specify values for #input_pds,#output_pds and member names.

With SELECT operator

Copy selected members

//STEP1    EXEC PGM=IEBCOPY                                             
//SYSPRINT DD   SYSOUT=*                                                
//SYSUT1   DD   DSN=#input_pds,DISP=SHR                      
//SYSUT2   DD   DSN=#output_pds,DISP=OLD                      
//SYSIN    DD *                                                         
 COPY OUTDD=SYSUT2,INDD=SYSUT1                                          
    SELECT MEMBER=(#mem_name1,#mem_name2,                              -
     #mem_name3)
/*                                                                      

Note: be careful with the line continuation operator -

With EXCLUDE operator

Copy everything except these members

//STEP1    EXEC PGM=IEBCOPY                                             
//SYSPRINT DD   SYSOUT=*                                                
//SYSUT1   DD   DSN=#input_pds,DISP=SHR                      
//SYSUT2   DD   DSN=#output_pds,DISP=OLD                      
//SYSIN    DD *                                                         
 COPY OUTDD=SYSUT2,INDD=SYSUT1                                          
    EXCLUDE MEMBER=(#mem_name1,#mem_name2)           
/*

Note: be careful with the line continuation operator -

How to join several Partitioned Data Sets PDSs into one Partitioned Data Set PDS?

Suppose you have 3 PDSs and you want to join them into one PDS.

Specify values for #input_pds* and #output_pds; change SPACE and DCB if needed.

//STEP1    EXEC PGM=IEBCOPY                                
//SYSPRINT DD   SYSOUT=*                                   
//IN1      DD   DSN=#input_pds1,DISP=SHR         
//IN2      DD   DSN=#input_pds2,DISP=SHR         
//IN3      DD   DSN=#input_pds3,DISP=SHR         
//*you can add more IN* here
//OUT      DD   DSN=#output_pds,DISP=(NEW,CATLG,DELETE),
//             DCB=*.IN1,SPACE=(CYL,(5,5,5))              
//SYSIN    DD   *                                          
  COPY OUTDD=OUT,INDD=(IN1,IN2,IN3)
/*                                                         

How to join multiple Sequential Data Sets into one?

Specify values for #input_ds* and #output_ds; change SPACE and DCB if needed.

//STEP1  EXEC PGM=IEBGENER
//SYSUT1 DD DISP=SHR,DSN=#input_ds1
//       DD DISP=SHR,DSN=#input_ds2
//       DD DISP=SHR,DSN=#input_ds3
//*
//* append more datasets if needed 
//*
//SYSUT2 DD DISP=(NEW,CATLG,DELETE),
//          SPACE=(CYL,(500,500),RLSE),
//          DCB=*.SYSUT1,
//          DSN=#output_ds
//SYSPRINT DD SYSOUT=*
//SYSOUT   DD SYSOUT=*
//SYSIN DD DUMMY