MVSFORUMS.com Forum Index MVSFORUMS.com
A Community of and for MVS Professionals
 
 FAQFAQ   SearchSearch   Quick Manuals   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Copying columns from one file to other using TSO cmds
Goto page 1, 2  Next
 
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> TSO and ISPF
View previous topic :: View next topic  
Author Message
MFdigger
Beginner


Joined: 09 Sep 2005
Posts: 124
Topics: 52
Location: Chicago

PostPosted: Wed Nov 17, 2010 4:58 pm    Post subject: Copying columns from one file to other using TSO cmds Reply with quote

Hi All,

I tried searching the forum about this but was not successful.

Is there any way we can copy particular columns from a data set into another data set using TSO commands on the command line

For Eg: if I want only to copy col2 and col5 from file 1 to file2

File 1 - col1 col2 col3 col4 col5 col6
file 2 - col2 col5

Appreciate your help Smile

Thank you Rolling Eyes
_________________
Tx
Digger
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12380
Topics: 75
Location: San Jose

PostPosted: Wed Nov 17, 2010 6:27 pm    Post subject: Reply with quote

MFdigger,

I am not sure if there is an easier way but here is something you can work on.

Make sure to type CANCEL after the last step 4 to avoid changes to file 1

step 1:

Code:

****** ***************************** Top of Data ***
=COLS> ----+----1----+----2----+----3----+----4----+
((5    COL1 COL2 COL3 COL4 COL5 COL6               
00((5  BLAH PICK BLAH BLAH PICK BLAH               


step 2:
[code:1:91dedbf4d1]
Command ===> c p'
Back to top
View user's profile Send private message Send e-mail Visit poster's website
papadi
Supermod


Joined: 20 Oct 2009
Posts: 594
Topics: 1

PostPosted: Thu Nov 18, 2010 1:36 pm    Post subject: Reply with quote

Suggest you make a copy of the file before mucking about with a "real" file.

fwiw. . .
_________________
All the best,

di
Back to top
View user's profile Send private message
Dibakar
Advanced


Joined: 02 Dec 2002
Posts: 700
Topics: 63
Location: USA

PostPosted: Thu Nov 18, 2010 1:37 pm    Post subject: Reply with quote

Quote:

[code:1:9ff59eb23b]c p'
_________________
Regards,
Diba
Back to top
View user's profile Send private message Send e-mail
prino
Banned


Joined: 01 Feb 2007
Posts: 45
Topics: 5
Location: Oostende

PostPosted: Thu Nov 18, 2010 5:06 pm    Post subject: Reply with quote

papadi wrote:
Suggest you make a copy of the file before mucking about with a "real" file.


That's why sensible people would use View rather than Edit...
Back to top
View user's profile Send private message
papadi
Supermod


Joined: 20 Oct 2009
Posts: 594
Topics: 1

PostPosted: Thu Nov 18, 2010 5:14 pm    Post subject: Reply with quote

Agreed Smile

Unfortunately, lots of (newer) people are not being taught what is sensible. . .

di
Back to top
View user's profile Send private message
warp5
Intermediate


Joined: 02 Dec 2002
Posts: 429
Topics: 18
Location: Germany

PostPosted: Fri Nov 19, 2010 2:15 am    Post subject: Reply with quote

It seems to me they do not even know what sensible means. Rolling Eyes
Back to top
View user's profile Send private message Visit poster's website
Anuj Dhawan
Intermediate


Joined: 19 Jul 2007
Posts: 298
Topics: 7
Location: Mumbai,India

PostPosted: Fri Nov 19, 2010 6:05 am    Post subject: Reply with quote

prino wrote:
papadi wrote:
Suggest you make a copy of the file before mucking about with a "real" file.


That's why sensible people would use View rather than Edit...
And once, one of my team-mate used "view" intelligently but then used a local in-house command "VSAVE" - which is used to save the data when in view-mode! Very Happy
_________________
Regards,
Anuj
Back to top
View user's profile Send private message
Dibakar
Advanced


Joined: 02 Dec 2002
Posts: 700
Topics: 63
Location: USA

PostPosted: Fri Nov 19, 2010 12:51 pm    Post subject: Reply with quote

prino wrote:
papadi wrote:
Suggest you make a copy of the file before mucking about with a "real" file.


That's why sensible people would use View rather than Edit...


Why not make changes on the copied file!
_________________
Regards,
Diba
Back to top
View user's profile Send private message Send e-mail
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12380
Topics: 75
Location: San Jose

PostPosted: Fri Nov 19, 2010 1:21 pm    Post subject: Reply with quote

I think this whole exercise is for bragging rights of doing things easily using TSO commands. On the other hand I think people should get burned at least once when doing things like this and later on they will be careful and make sure to have a copy before messing with it.


Dibakar, I just gave an example and p'
_________________
Kolusu
www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
misi01
Advanced


Joined: 02 Dec 2002
Posts: 629
Topics: 176
Location: Stockholm, Sweden

PostPosted: Mon Nov 22, 2010 5:36 am    Post subject: Reply with quote

FWIW - I have a macro that I call BACKUP. Simply put, you edit a file (or PDS member), enter the command BACKUP on the command line and it'll make a copy of it with a naming convention along the lines of

USERID.FRED.BTSIN.M7413ALL.D081126.T102909

where (in this example), I was obviously editing member M7413ALL in PDS USERID.FRED.BTSIN and entered the command backup on the 26 Nov 2008 at 10:29:09.

If anyone's interested, I'd be quite happy to post the code here (as long as I don't get any grief on my coding style Wink )
Back to top
View user's profile Send private message Send e-mail
Nic Clouston
Advanced


Joined: 01 Feb 2007
Posts: 1075
Topics: 7
Location: At Home

PostPosted: Mon Nov 22, 2010 11:15 am    Post subject: Reply with quote

1) create an edit format (option 3.11) which specifies which columns you want to expose.
2) edit the data set you want to copy the columns from - specifiying the format name on the dataset entry panel
3) You will now only see the columns that you are interested in
4) c999999 line comand
5) create a new file or go into the file you want the columns pasted to
6) paste
7) remove the fromat name from the edit entry panel and cleanup.
_________________
Utility and Program control cards are NOT, repeat NOT, JCL.
Back to top
View user's profile Send private message
Nic Clouston
Advanced


Joined: 01 Feb 2007
Posts: 1075
Topics: 7
Location: At Home

PostPosted: Mon Nov 22, 2010 11:17 am    Post subject: Reply with quote

8) - forget it copies even the hidden columns - didn't follow my own advice about cleaning up!!
_________________
Utility and Program control cards are NOT, repeat NOT, JCL.
Back to top
View user's profile Send private message
chandra
Beginner


Joined: 26 Sep 2003
Posts: 130
Topics: 36

PostPosted: Mon Nov 22, 2010 1:05 pm    Post subject: Reply with quote

Hi Misi01,

Can you post your code.

Hi Nic Clouston - Thank you very much for your post. I learnt new thing today.

Thank you.
Chandra.
_________________
Regards,
Chandra
Back to top
View user's profile Send private message
misi01
Advanced


Joined: 02 Dec 2002
Posts: 629
Topics: 176
Location: Stockholm, Sweden

PostPosted: Tue Nov 23, 2010 2:13 am    Post subject: Reply with quote

Here's the code
Code:

/*REXX*****************************************************************/
/* EXEC can be used to create a backup of a sequential or PDS file
   member. You must be in EDIT mode to run this code. Simply edit
   the file/PDS member  you want to create a backup for and enter
   the command BACKUP from the command line - a file will be created
   automatically. If the file being copied is a simple SEQ file
   called A.B.C
   then the resulting backup file will be
          A.B.C.Dyymmdd.Thhmmss
   If the file is a PDS member called
          A.B.C(E)
   then the resulting backup file will be
          A.B.C.E.Dyymmdd.Thhmmss

   You can also call the exec with a parameter of TRACE which will
   then trace you through the exec one line at a time

   Copyright Michael Simpson 2003
*/
/**********************************************************************/
/* trace ?a */
rname = 'BACKUP'
'isredit macro (parms) NOPROCESS'
upper parms
if PARMS = 'TRACE' then trace ?a

curr_date = date('S')
if rc = 20 then
  do
    rc = NON_EDIT_ENV()
  end

curr_time = time()
curr_time = 'T'!!substr(curr_time,1,2)!!substr(curr_time,4,2),
               !!substr(curr_time,7,2)   /* THHMMSS    */

curr_date = 'D'!!substr(curr_date,3) /* In form DYYMMDD  */
date_time = curr_date!!'.'!!curr_time

Address ISPEXEC 'CONTROL ERRORS RETURN'  /* We handle any errors      */
Address ISREDIT                          /* Pass all cmd to EDIT      */

'(MEMB) = MEMBER'                       /* WHICH member?             */
'(DS)   = DATASET'                      /* Which dataset             */
PDS = 0
if length(memb) > 0 then
  pds = 1

rc = check_backup_libray()
rc = write_to_backup()
rc = free_files()
rc = file_copied_ok(tempdsn)
exit
/**********************************************************************

**********************************************************************/
ALLOCATE_FILE:
/* say 'In ALLOCATE_FILE in 'rname ; trace ?a */
address 'TSO'
x = OUTTRAP(alloc.)
"alloc dd(backup) da('"tempdsn"') new release",
   " blksize("sysblksize") SPACE("sysused",1) "sysunits,
   " lrecl("syslrecl") recfm("recfm")"
if rc <> 0 then
  do
    /* Failed to allocate */
    rc = allocate_failure(tempdsn)
  end
x = OUTTRAP('OFF')
return 0
/**********************************************************************
 Check if the backup library exists (it shouldn't)
**********************************************************************/
check_backup_libray:

if PDS = 0 then
  tempdsn = ds!!'.'!!date_time
else
  tempdsn = ds'.'memb'.'date_time

if length(tempdsn) > 44 then
  rc =filename_too_long(tempdsn)

koll = sysdsn("'"tempdsn"'")
if koll = 'OK' then
  rc = file_already_exists(tempdsn)
else
  do
    rc = get_attributes()
    rc = allocate_file()
  end

return 0
/**********************************************************************

**********************************************************************/
write_to_backup:

address 'TSO'
x = OUTTRAP(alloc.)

"alloc dd(infile) da('"ds"') shr reuse"
if rc <> 0 then
  do
    /* Failed to allocate */
    rc = allocate_failure(ds)
  end

"alloc dd(utfile) da('"tempdsn"') old    "
if rc <> 0 then
  do
    /* Failed to allocate */
    rc = allocate_failure(tempdsn)
  end

x = OUTTRAP('OFF')

address 'ISPEXEC'
"lminit dataid(infile) dataset('"ds"') enq(shr)"
rc = check_lm_call()
"lminit dataid(utfile) dataset('"tempdsn"') enq(mod)"
rc = check_lm_call()
if PDS = 1 then
  "lmcopy fromid(&infile) frommem("memb") todataid(&utfile)",
             " replace"
else
  "lmcopy fromid(&infile) todataid(&utfile)"
rc = check_lm_call()

return 0
/**********************************************************************
 Check that the LM call worked
**********************************************************************/
check_lm_call:

if rc > 0 then
  do
    ZEDSMSG = zerrsm
    ZEDLMSG = zerrlm
    Call ISPFMSG
  end

return 0
/**********************************************************************
 Always free the LM files and those allocated (possibly)
**********************************************************************/
free_files:

address 'ISPEXEC'
'lmfree  dataid(&infile)'
'lmfree  dataid(&utfile)'
address TSO "FREE F(infile)"
address TSO "FREE F(utfile)"
address TSO "FREE F(backup)"

return 0
/**********************************************************************
 Get the attributes for the file/member being copied
**********************************************************************/
get_attributes:

file = ds
if PDS = 1 then
  file = file!!"("memb!!")"

file = "'"!!file!!"'"
x =LISTDSI(file)
if x <> 0 then
  do
    call listdsi_failed
  end
recfm = sysrecfm
if length(sysrecfm) > 1 then
  do
    /* Insert a comma between individual characters, otherwise
       the allocate fails                              */
    recfm = ''
    do i=1 to length(sysrecfm)
      recfm = recfm!!substr(sysrecfm,i,1)!!','
    end
    recfm = substr(recfm,1,length(recfm) - 1) /* Throw last comma */
  end

/* Next line is from the TSO manual

   From the BLKSIZE operand, if BLOCK is not specified

   If the sysunits value is BLOCK, then the allocate command
   will expect a value for BLOCK (eg BLOCK(200) ). Since we have
   no idea what to specify, it's easier to blank out sysunits
   and let the allocate command figure out the sysunit based on
   the blksize instead
*/
if sysunits = 'BLOCK' then
  sysunits = ''

return 0
/**********************************************************************

**********************************************************************/
filename_too_long:
 arg filename           /* Will be filename */
 zedsmsg = "Filename error"
 zedlmsg = "Filename "filename" is more than 44 characters",
           "- cannot create backup"
 Call ISPFMSG
return 0
/**********************************************************************

**********************************************************************/
file_copied_ok:
 arg filename           /* Will be filename */
 zedsmsg = "File copied"
 zedlmsg = "File has been copied successfully to '"filename"'"
 Call ISPFMSG
return 0
/**********************************************************************

**********************************************************************/
file_already_exists:
 arg filename           /* Will be filename */
 zedsmsg = "COPY file exists"
 zedlmsg = "File "filename" already exists - investigate"
 Call ISPFMSG
return 0
/**********************************************************************

**********************************************************************/
listdsi_failed:
 arg filename           /* Will be filename */
 zedsmsg = "LISTDSI RC ="rc
 zedlmsg = "LISTDSI failed - cannot retrieve file attributes"
 Call ISPFMSG
return 0
/**********************************************************************

**********************************************************************/
allocate_failure:
 arg filename           /* Will be filename */
 zedsmsg = "Allocate failed"
 zedlmsg = "Failed in allocating "filename" - investigate"
 Call ISPFMSG
return 0
/**********************************************************************
 User isn't in EDIT mode
**********************************************************************/
NON_EDIT_ENV:
 zedsmsg = "Non EDIT env"
 zedlmsg = "Edit a file or file member before running BACKUP"
 Call ISPFMSG
return 0
/**********************************************************************
 Show info/error messages to user
**********************************************************************/
ISPFMSG:
zcmd = ''
Address ISPEXEC
'VPUT (ZCMD,ZEDSMSG,ZEDLMSG)'
'SETMSG MSG(ISRZ001)'
rc = free_files()
exit
Back to top
View user's profile Send private message Send e-mail
Display posts from previous:   
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> TSO and ISPF All times are GMT - 5 Hours
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


MVSFORUMS
Powered by phpBB © 2001, 2005 phpBB Group