View previous topic :: View next topic
Author
Message
amaran18 New User Joined: 22 Mar 2022Posts: 2 Location: US
Good day!!
Looking to see if SORT can be used to split a file into multiple files based on certain data characteristics. Appreciate any pointers if this can be done using Sort. Pls let me know if you need any additional information.
Input File
1234567890X’01’Name1X’02’Address1X’03’Phone1
2345678901X’01’Name2X’01’Name3X’03’Phone2
3456789012X’01’Name4X’02’Address2X’02’Address3X’03’Phone3X’03’Phone4
The Hex values determine what information follows –
X’01’ the information following this has the Name with Total Length of 20 Chars
X’02’ the information following this has the Address with total of 30 Chars
X’03’ the information following this has the Phone with total of 10 Chars
The output should be as below.
File 01 – Name details
1234567890X’01’Name1
2345678901X’01’Name2
2345678901X’01’Name3
3456789012X’01’Name4
File 02 – Address Details
1234567890X’02’Address1
3456789012X’02’Address2
3456789012X’02’Address3
File 03 – Phone Details
1234567890X’03’Phone1
2345678901X’03’Phone2
3456789012X’03’Phone3
3456789012X’03’Phone4
Regards & thanks
Amar
Back to top
sergeyken Senior Member Joined: 29 Apr 2008Posts: 2012 Location: USA
Please, use the Code button to present ANY sample of your code and/or your data.
Back to top
amaran18 New User Joined: 22 Mar 2022Posts: 2 Location: US
Code:
Input File
1234567890X’01’Name1X’02’Address1X’03’Phone1
2345678901X’01’Name2X’01’Name3X’03’Phone2
3456789012X’01’Name4X’02’Address2X’02’Address3X’03’Phone3X’03’Phone4
The Hex values determine what information follows –
X’01’ the information following this has the Name with Total Length of 20 Chars
X’02’ the information following this has the Address with total of 30 Chars
X’03’ the information following this has the Phone with total of 10 Chars
The output should be as below.
File 01 – Name details
1234567890X’01’Name1
2345678901X’01’Name2
2345678901X’01’Name3
3456789012X’01’Name4
File 02 – Address Details
1234567890X’02’Address1
3456789012X’02’Address2
3456789012X’02’Address3
File 03 – Phone Details
1234567890X’03’Phone1
2345678901X’03’Phone2
3456789012X’03’Phone3
3456789012X’03’Phone4
Back to top
sergeyken Senior Member Joined: 29 Apr 2008Posts: 2012 Location: USA
Is each of your separators - X’01’, etc. - really a 5-bytes character string???!!!
Either C’X’’01’’’ or X’01’?
Do you understand the difference?
P.S.
Your own comments to your code ARE NOT part of the code itself. They are not supposed to be enclosed into Code tags.
Back to top
sergeyken Senior Member Joined: 29 Apr 2008Posts: 2012 Location: USA
You need to resolve several different and independent issues:
0. How to use the Code button, to make your samples clear to others
1. How to consider your field separators: either as 5-bytes character strings, or 1-byte hexadecimal ones?
2. How to perform parsing of variable length fields in a record?
3. How to split various fixed-length fields into several output “files”=DDNAMES?
You can start to train yourself in each of those steps separately.
Back to top
sergeyken Senior Member Joined: 29 Apr 2008Posts: 2012 Location: USA
I do not expect to get clear answers to my simple questions from the TS…
I suppose the field separators are X’01’, X’02’, X’03’, but not C’X’’01’’’ etc.
Code:
//*==============================================================
//SPLIT EXEC PGM=ICETOOL
//DFMSG DD SYSOUT=*
//TOOLMSG DD SYSOUT=*
//SORTIN DD *
1234567890 Name1 Address1 Phone1
2345678901 Name2 Name3 Phone2
3456789012 Name4 Address2 Address3 Phone3 Phone4
//*
//SPLIT DD SPACE=(TRK,(20,20))
//*
//NAME DD SYSOUT=*
//ADDRESS DD SYSOUT=*
//PHONE DD SYSOUT=*
//*
//TOOLIN DD *
COPY FROM(SORTIN) TO(SPLIT) USING(PARS)
SORT FROM(SPLIT) TO(NAME,ADDRESS,PHONE) USING(SPLT)
//*
//PARSCNTL DD *
INREC FINDREP=(INOUT=(X'01',X'0001',
X'02',X'0002',
X'03',X'0003'))
SORT FIELDS=COPY
OUTFIL FNAMES=SPLIT,
PARSE=(%=(ENDAT=X'00',
ENDAT=C' '),
%1=(ENDBEFR=X'00',
ENDBEFR=C' ',
FIXLEN=20,
REPEAT=10)),
BUILD=(1,10,%1,
/,1,10,%2,
/,1,10,%3,
/,1,10,%4,
/,1,10,%5,
/,1,10,%6,
/,1,10,%7,
/,1,10,%8,
/,1,10,%9,
/,1,10,%10)
//*
//SPLTCNTL DD *
SORT FIELDS=(1,10,CH,A),EQUALS
OUTFIL FNAMES=NAME,INCLUDE=(11,1,CH,EQ,X'01')
OUTFIL FNAMES=ADDRESS,INCLUDE=(11,1,CH,EQ,X'02')
OUTFIL FNAMES=PHONE,INCLUDE=(11,1,CH,EQ,X'03')
//*
//*============================================================
P.S.
I also do not expect any thank you…
Back to top
Joerg.Findeisen Senior Member Joined: 15 Aug 2015Posts: 1231 Location: Bamberg, Germany
TOOLIN can be shortened:
Code:
COPY FROM(SORTIN) USING(PARS)
SORT FROM(SPLIT) USING(SPLT)
Back to top
sergeyken Senior Member Joined: 29 Apr 2008Posts: 2012 Location: USA
Joerg.Findeisen wrote:
TOOLIN can be shortened:
Code:
COPY FROM(SORTIN) USING(PARS)
SORT FROM(SPLIT) USING(SPLT)
Yes, but:
1) the first step for the clarity to become degraded
2) not related to the initial issue raised by TS...
Back to top
Please enable JavaScript!