Posted: Tue Dec 09, 2008 9:09 am Post subject: How to Copy Record until some value is met.
Hi,
How to copy records from an input file until some value is met? We get a daily input file with a max of 20,000 total number of records. The trend of the file has had header records (ERROR - PROCESS CLOSED) anywhere between 15 to 20 at the maximum followed by their detailed records. All put together will form total of 20,000 records.
So, I want to copy records till "ERROR - PROCESS CLOSED" is occured into respective output files.
Input Data:
Code:
ERROR - PROCESS CLOSED
RET0 13 001 XXX48 001 N
RET2 13 001 XXY48 002 T
RET9 13 001 XXZ48 001 T
RET8 13 001 XBX48 002 N
RET9 13 001 XYT48 003 N
ERROR - PROCESS CLOSED
RET1 83 001 XXX48 001 N
RET5 83 001 XXY48 002 T
RET7 83 001 XXZ48 001 T
ERROR - PROCESS CLOSED
RET2 10 001 XXX48 001 N
RET6 10 001 XXY48 002 T
RET1 10 001 XBX48 002 N
RET2 10 001 XYT48 003 N
In this example, I want to create three files out of it.
File-1:
Code:
ERROR - PROCESS CLOSED
RET0 13 001 XXX48 001 N
RET2 13 001 XXY48 002 T
RET9 13 001 XXZ48 001 T
RET8 13 001 XBX48 002 N
RET9 13 001 XYT48 003 N
File-2:
Code:
ERROR - PROCESS CLOSED
RET1 83 001 XXX48 001 N
RET5 83 001 XXY48 002 T
RET7 83 001 XXZ48 001 T
File-3:
Code:
ERROR - PROCESS CLOSED
RET2 10 001 XXX48 001 N
RET6 10 001 XXY48 002 T
RET1 10 001 XBX48 002 N
RET2 10 001 XYT48 003 N
How to achieve it? Please help.
TIA. _________________ Ranga
*****
None of us is as smart as all of us - Ken Blanchard
Joined: 26 Nov 2002 Posts: 12378 Topics: 75 Location: San Jose
Posted: Tue Dec 09, 2008 6:10 pm Post subject:
Sqlcode wrote:
Hi,
Kolusu What if total number of ERROR statement and hence OUTFIL are unknown?
Is there a way to automate this process so that it will dynamically decide and create datasets?
Well you can , you can generate the JCL needed for splitting the file dynamically and submit it via INTRDR like shown below. I coded only to handle 99 output files. So if there are more than you need to change it a little bit
For SyncSort for z/OS 1.3 customers, this functionality will be available shortly. Please feel free to contact me offline if you would like to be included on the early distribution list.
Under the following assumptions the sysncsort below will work:
1). The information in positions 07,02 is known. (see profile sort)
2). The header ERROR - PROCESS CLOSED is not needed on each input file
Code:
//DAFORUM EXEC PGM=SORT,COND=(0,LT)
//*
//SORTIN DD *
ERROR - PROCESS CLOSED
RET0 13 001 XXX48 001 N
RET2 13 001 XXY48 002 T
RET9 13 001 XXZ48 001 T
RET8 13 001 XBX48 002 N
RET9 13 001 XYT48 003 N
ERROR - PROCESS CLOSED
RET1 83 001 XXX48 001 N
RET5 83 001 XXY48 002 T
RET7 83 001 XXZ48 001 T
ERROR - PROCESS CLOSED
RET2 10 001 XXX48 001 N
RET6 10 001 XXY48 002 T
RET1 10 001 XBX48 002 N
RET2 10 001 XYT48 003 N
//*
//*Output Files
//EFILE1 DD SYSOUT=*
//EFILE2 DD SYSOUT=*
//EFILE3 DD SYSOUT=*
//*
//SYSIN DD *
SORT FIELDS=COPY
OUTFIL FNAMES=EFILE1,
INCLUDE=(007,002,CH,EQ,C'13')
OUTFIL FNAMES=EFILE2,
INCLUDE=(007,002,CH,EQ,C'83')
OUTFIL FNAMES=EFILE3,
INCLUDE=(007,002,CH,EQ,C'10')
//*
//SYSPRINT DD SYSOUT=*
//SYSUDUMP DD SYSOUT=*
//SYSOUT DD SYSOUT=*
Output File 1 or EFILE1
Code:
RET0 13 001 XXX48 001 N
RET2 13 001 XXY48 002 T
RET9 13 001 XXZ48 001 T
RET8 13 001 XBX48 002 N
RET9 13 001 XYT48 003 N
Output File 2 or EFILE2
Code:
RET1 83 001 XXX48 001 N
RET5 83 001 XXY48 002 T
RET7 83 001 XXZ48 001 T
Output File 3 or EFILE3
Code:
RET2 10 001 XXX48 001 N
RET6 10 001 XXY48 002 T
RET1 10 001 XBX48 002 N
RET2 10 001 XYT48 003 N
Profile Sort - This sort will create a report of the various digits in positions 7, 2 of the input file. The information obtained here could be used to construct the previous sort include statements...
Code:
//PROFILE EXEC PGM=SORT,COND=(0,LT)
//SORTIN DD *
ERROR - PROCESS CLOSED
RET0 13 001 XXX48 001 N
RET2 13 001 XXY48 002 T
RET9 13 001 XXZ48 001 T
RET8 13 001 XBX48 002 N
RET9 13 001 XYT48 003 N
ERROR - PROCESS CLOSED
RET1 83 001 XXX48 001 N
RET5 83 001 XXY48 002 T
RET7 83 001 XXZ48 001 T
ERROR - PROCESS CLOSED
RET2 10 001 XXX48 001 N
RET6 10 001 XXY48 002 T
RET1 10 001 XBX48 002 N
RET2 10 001 XYT48 003 N
//*
//SORTOF1 DD SYSOUT=*
//SYSIN DD *
INREC FIELDS=(07,2,C'0000001')
INCLUDE COND=(008,1,CH,NE,C'-') *EXCLUDE THE '-' IN 'ERROR - PROCESS'
SORT FIELDS=(1,2,CH,A)
SUM FIELDS=(3,7,ZD)
OUTFIL FILES=1,
OUTREC=(03:1,2,
20:3,7,ZD,EDIT=(I,III,TTT),
80:C' '),
HEADER2=(10:'ERROR TOTAL '//,
01:'ERROR CODE ',
23:'OCCURENCES'/),
TRAILER1=(01/,
01:'TOTAL ERROR TYPES :',COUNT)
//*
//SYSPRINT DD SYSOUT=*
//SYSUDUMP DD SYSOUT=*
//SYSOUT DD SYSOUT=*
The previous sort would still work assuming that all of the possible combinations for positions 7,2 are defined in the includes. Because syncsort will not use the location of a record to determine which file to write to, instead, the includes will be used to determine which output file to write.
Joined: 26 Nov 2002 Posts: 12378 Topics: 75 Location: San Jose
Posted: Fri Dec 12, 2008 1:58 pm Post subject:
samlwho wrote:
The previous sort would still work assuming that all of the possible combinations for positions 7,2 are defined in the includes. Because syncsort will not use the location of a record to determine which file to write to, instead, the includes will be used to determine which output file to write.
samlwho,
NO. it would not work. ex:
Code:
//STEP0100 EXEC PGM=ICEMAN
//SYSOUT DD SYSOUT=*
//SORTIN DD *
ERROR - PROCESS CLOSED
RET0 01 001 XXX48 001 N - GOES TO OUTPUT FILE 1
RET2 02 001 XXY48 002 T - GOES TO OUTPUT FILE 1
RET9 03 001 XXZ48 001 T - GOES TO OUTPUT FILE 1
RET8 04 001 XBX48 002 N - GOES TO OUTPUT FILE 1
RET9 05 001 XYT48 003 N - GOES TO OUTPUT FILE 1
ERROR - PROCESS CLOSED
RET1 01 001 XXX48 001 N - GOES TO OUTPUT FILE 2
RET5 02 001 XXY48 002 T - GOES TO OUTPUT FILE 2
RET7 03 001 XXZ48 001 T - GOES TO OUTPUT FILE 2
ERROR - PROCESS CLOSED
RET2 01 001 XXX48 001 N - GOES TO OUTPUT FILE 3
RET6 02 001 XXY48 002 T - GOES TO OUTPUT FILE 3
RET1 03 001 XBX48 002 N - GOES TO OUTPUT FILE 3
RET2 04 001 XYT48 003 N - GOES TO OUTPUT FILE 3
//*
//*OUTPUT FILES
//EFILE1 DD SYSOUT=*
//EFILE2 DD SYSOUT=*
//EFILE3 DD SYSOUT=*
//EFILE4 DD SYSOUT=*
//EFILE5 DD SYSOUT=*
//SYSIN DD *
SORT FIELDS=COPY
OUTFIL FNAMES=EFILE1,
INCLUDE=(007,002,CH,EQ,C'01')
OUTFIL FNAMES=EFILE2,
INCLUDE=(007,002,CH,EQ,C'02')
OUTFIL FNAMES=EFILE3,
INCLUDE=(007,002,CH,EQ,C'03')
OUTFIL FNAMES=EFILE4,
INCLUDE=(007,002,CH,EQ,C'04')
OUTFIL FNAMES=EFILE5,
INCLUDE=(007,002,CH,EQ,C'05')
//*
the output files are
EFILE1
Code:
RET0 01 001 XXX48 001 N - GOES TO OUTPUT FILE 1
RET1 01 001 XXX48 001 N - GOES TO OUTPUT FILE 2
RET2 01 001 XXX48 001 N - GOES TO OUTPUT FILE 3
EFILE2
Code:
RET2 02 001 XXY48 002 T - GOES TO OUTPUT FILE 1
RET5 02 001 XXY48 002 T - GOES TO OUTPUT FILE 2
RET6 02 001 XXY48 002 T - GOES TO OUTPUT FILE 3
EFILE3
Code:
RET9 03 001 XXZ48 001 T - GOES TO OUTPUT FILE 1
RET7 03 001 XXZ48 001 T - GOES TO OUTPUT FILE 2
RET1 03 001 XBX48 002 N - GOES TO OUTPUT FILE 3
EFILE4
Code:
RET8 04 001 XBX48 002 N - GOES TO OUTPUT FILE 1
RET2 04 001 XYT48 003 N - GOES TO OUTPUT FILE 3
I am not sure why you say it would not work before proving that it does via your example. As shown in your example, regardless of the record location on the file, the result was 5 files with unique values in positions 7,2...that is what's desired, right?
Joined: 26 Nov 2002 Posts: 12378 Topics: 75 Location: San Jose
Posted: Fri Dec 12, 2008 4:02 pm Post subject:
samlwho wrote:
I am not sure why you say it would not work before proving that it does via your example. As shown in your example, regardless of the record location on the file, the result was 5 files with unique values in positions 7,2...that is what's desired, right?
Please elaborate.
*Sigh* did you read my last post clearly ? I have shown the results your job would produce and also what OP wants _________________ Kolusu
www.linkedin.com/in/kolusu
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