Home > Tools > Tools – COPYMBR

Tools – COPYMBR

During my daily work I often need to copy members from one PDS to another. The Partitioned data sets are always the same ones, just different members. I could use the ISPF Move/Copy Utility screens but it quickly gets tiresome to have to keep entering the data set and member information into the screens.

Since I’ve got my REXX library allocated to SYSPROC so that I can run execs from it directly using the TSO execname command on the ISPF command line I put together the following exec called COPYMBR to automate the process:

/* rexx                                              */
/* exec to copy a member from one pds to another     */

parse arg frommbr tombr '/' repl
tombr = strip(tombr)
upper repl
if frommbr = '' then do
   say "Syntax is COPYMBR from_mbr [to_mbr] [/r]"
   say "Specify to_mbr name to rename the copied member"
   say "Specify /r to replace the member in the target PDS"
   return 0
end
if tombr='' then tombr=frommbr

if length(frommbr) > 8 then do
   say "Source member name greater than 8 chars"
   return 0
end
if length(tombr) > 8 then do
   say "Target member name greater than 8 chars"
   return 0
end

address ispexec
"CONTROL ERRORS RETURN"
indsn="'"userid()||".LOAD'"     /* Source PDS */
outdsn="'"userid()||".LOAD2'"   /* Target PDS */
"LMINIT DATAID(IN) DATASET("indsn") ENQ(SHR)"
"LMINIT DATAID(OUT) DATASET("outdsn") ENQ(SHR)"

opt=''
if repl = 'R' then opt = "REPLACE'
"LMCOPY FROMID("in") FROMMEM("frommbr") TODATAID("out") ",
       "TOMEM("tombr") "opt
lastcc=rc
ins=''
if lastcc = 0 then nop
else if lastcc=12 then do
   if frommbr <> tombr then ins = 'as '||tombr
   say frommbr' not copied'||ins
   say tombr' already exists on target library.'
   end
else if lastcc=8 then do
   say frommbr' not found in source library.'
   end
else do
   say 'rc from LMCOPY='lastcc
   end

"LMFREE DATAID("in")"
"LMFREE DATAID("out")"
return 0

You can edit the lines marked “Source PDS” and “Target PDS” to specify any compatible load libraries. I just used my LOAD and LOAD2 libraries as an example.

The general syntax of the COPYMBR command on the ISPF command line is then:

TSO COPYMBR member_name [new_name] [/r]

Where:

member_name is the name of the member to copy from the source PDS

new_name is optional and is the new name to assign to the member on the target PDS. If not specified it defaults to the same name as the source member.

/r tells the exec to replace the member (or new member name if renaming) on the target PDS.

Note that when the copy is successful, the exec does NOT output any messages so there’s no need to press the enter key to clear a message except when there is something wrong.

Examples:

TSO COPYMBR MYPROG1 /r

Copy MYPROG1 from the source PDS to the target PDS and replace any existing version.

TSO COPYMBR MYPROG1 MYPROG2

Copy MYPROG1 from the source PDS to the target PDS and rename it to MYPROG2. Do not do the copy if MYPROG2 already exists on the target PDS.

TSO COPYMBR MYPROG1 MYPROG2 /r

Copy MYPROG1 from the source PDS to the target PDS and rename it to MYPROG2. Replace any existing version of MYPROG2 on the target PDS.

Advertisements
Categories: Tools Tags:
  1. Jeffrey
    July 22, 2015 at 3:24 pm

    Thanks for sharing… written clear and concise so others can update as they see fit.

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: