IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Split rcords into 2 different files


IBM Mainframe Forums -> DFSORT/ICETOOL
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
pjnithin

Active User


Joined: 22 Dec 2005
Posts: 116

PostPosted: Tue Feb 28, 2006 2:24 am
Reply with quote

I have a requirement where I need to select a particular set of records into 1 file and remaining into another file. Can I achieve this in a single step.

Input File:
A 111111111
A 222222222
B 111111111
C 111111111
A 777777777
D 666666666

I need all records starting with 'A' in one file and remaining in another file.
Outfile 1 :
A 111111111
A 222222222
A 777777777

Outfile 2:
B 111111111
C 111111111
D 666666666

Is there a direct method instead of using select statements with 2 control cards. It'll be helpful if I can do it in one single step where I give an include condition for one case for all the records to go into output file 1 and in the same step rest of the records will go to output file 2 also. Please help.
Back to top
View user's profile Send private message
Frank Yaeger

DFSORT Developer


Joined: 15 Feb 2005
Posts: 7129
Location: San Jose, CA

PostPosted: Tue Feb 28, 2006 4:06 am
Reply with quote

You can use a DFSORT job like this to do what you asked for:

Code:

//S1    EXEC  PGM=ICEMAN
//SYSOUT    DD  SYSOUT=*
//SORTIN DD DSN=...  input file
//OUT1 DD DSN=...    output file1
//OUT2 DD DSN=...    output file2
//SYSIN    DD    *
  OPTION COPY
  OUTFIL FNAMES=OUT1,INCLUDE=(1,1,CH,EQ,C'A')
  OUTFIL FNAMES=OUT2,SAVE
/*


If you're not familiar with DFSORT and DFSORT's ICETOOL, I'd suggest reading through "z/OS DFSORT: Getting Started". It's an excellent tutorial, with lots of examples, that will show you how to use DFSORT, DFSORT's ICETOOL and DFSORT Symbols. You can access it online, along with all of the other DFSORT books, from:

Use [URL] BBCode for External Links
Back to top
View user's profile Send private message
pjnithin

Active User


Joined: 22 Dec 2005
Posts: 116

PostPosted: Wed Mar 01, 2006 12:57 am
Reply with quote

In the same step is it possible for me to sort the file based on the last 9 bytes.
Back to top
View user's profile Send private message
Frank Yaeger

DFSORT Developer


Joined: 15 Feb 2005
Posts: 7129
Location: San Jose, CA

PostPosted: Wed Mar 01, 2006 3:23 am
Reply with quote

Sure, just change:

Code:

   OPTION COPY


to:

Code:

   SORT FIELDS=(3,9,CH,A)


Use ZD instead of CH if you want to treat the key as numeric (zoned decimal).
Back to top
View user's profile Send private message
pjnithin

Active User


Joined: 22 Dec 2005
Posts: 116

PostPosted: Wed Mar 01, 2006 8:58 am
Reply with quote

But I need only the OUT1 file to be sorted. I think the above mentioned method sorts both the files.
Back to top
View user's profile Send private message
fixdoubts

New User


Joined: 21 Oct 2005
Posts: 54

PostPosted: Wed Mar 01, 2006 1:51 pm
Reply with quote

Hi,

Im not sure this optimal one but it works.
Code:

//S1    EXEC  PGM=ICETOOL
//SYSOUT    DD  SYSOUT=*
//IN1    DD DSN=...  input file
//OUT1 DD DSN=...    output file1
//OUT2 DD DSN=...    output file2
//TOOL IN DD *
   COPY FROM(IN1) TO(OUT1) USING(CPY1)
   COPY FROM(IN1) TO(OUT2) USING(CPY2)
/*
//CPY1CNTL    DD    *
  SORT FIELDS=(LAST 9)
  INCLUDE COND=(1,1,CH,EQ,C'A')
/*
//CPY2CNTL    DD    *
  OPTION COPY
  OMIT COND=(1,1,CH,EQ,C'A')
/*


This will do i think might not be an optimal one but it will do what you wanted.

Regards,
Back to top
View user's profile Send private message
Frank Yaeger

DFSORT Developer


Joined: 15 Feb 2005
Posts: 7129
Location: San Jose, CA

PostPosted: Wed Mar 01, 2006 9:26 pm
Reply with quote

Quote:
But I need only the OUT1 file to be sorted. I think the above mentioned method sorts both the files.


And was I supposed to know that by reading your mind? Please try to be more clear in your requirements in the future so we don't waste your time or mine.

If you want to sort the 'A' records, but not the 'B' records, you have to use two passes. Here are two ways to do that with DFSORT/ICETOOL:

Method 1

Code:

//S2    EXEC  PGM=ICETOOL
//TOOLMSG DD SYSOUT=*
//DFSMSG DD SYSOUT=*
//IN DD DSN=...  input file1
//T1 DD DSN=&&T1,UNIT=SYSDA,SPACE=(CYL,(5,5)),DISP=(,PASS)
//OUT1 DD DSN=...  output file1
//OUT2 DD DSN=...  output file2
//TOOLIN   DD    *
* IN->T1: 'A' records (unsorted)
* IN->OUT2: non-'A' records (unsorted)
COPY FROM(IN) USING(CTL1)
* T1->OUT1:  Sort 'A' records
SORT FROM(T1) TO(OUT1) USING(CTL2)
/*
//CTL1CNTL DD *
  OUTFIL FNAMES=T1,INCLUDE=(1,1,CH,EQ,C'A')
  OUTFIL FNAMES=OUT2,SAVE
/*
//CTL2CNTL DD *
  SORT FIELDS=(3,9,CH,A)
/*


Method 2

Code:

//S3    EXEC  PGM=ICETOOL
//TOOLMSG DD SYSOUT=*
//DFSMSG DD SYSOUT=*
//IN DD DSN=...  input file1
//OUT1 DD DSN=...  output file1
//OUT2 DD DSN=...  output file2
//TOOLIN   DD    *
* IN->OUT1:  'A' records (sorted)
SORT FROM(IN) TO(OUT1) USING(CTL1)
* IN->OUT2:  non-'A' records (unsorted)
COPY FROM(IN) TO(OUT2) USING(CTL2)
/*
//CTL1CNTL DD *
  INCLUDE COND=(1,1,CH,EQ,C'A')
  SORT FIELDS=(3,9,CH,A)
/*
//CTL2CNTL DD *
  INCLUDE COND=(1,1,CH,NE,C'A')
/*
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> DFSORT/ICETOOL

 


Similar Topics
Topic Forum Replies
No new posts Compare 2 files and retrive records f... DFSORT/ICETOOL 3
No new posts Compare 2 files(F1 & F2) and writ... JCL & VSAM 8
No new posts How to split large record length file... DFSORT/ICETOOL 10
No new posts Write line by line from two files DFSORT/ICETOOL 7
No new posts Compare only first records of the fil... SYNCSORT 7
Search our Forums:

Back to Top