|
View previous topic :: View next topic
|
| Author |
Message |
David Eisenberg
New User
Joined: 15 Nov 2007 Posts: 39 Location: New York
|
|
|
|
Anyone,
I would like to use DFSORT to find the last occurrence of a particular delimiter ("\") within a record, throw everything away prior to that point in the record, and PARSE only the remainder of the record. The remainder needs to be parsed based on a different delimiter ("-"). The number of occurrences of the first delimiter are unpredictable. For example:
Input:
| Code: |
\aaa\bbbb\cc\1111-22-33-4444
\aaaa\bb\cccc\dd\11-2222-33-444
\aa\1-222-33-44 |
Desired parsed variables:
| Code: |
%01=1111, %02=22, %03=33, %04=4444
%01=11, %02=2222, %03=33, %04=444
%01=1, %02=222, %03=33, %04=44 |
These would be VB records, max LRECL 255. I do not know how many backslashes will appear prior to the last one; it may vary from record to record. If necessary, we could assume a maximum number of backslashes; say, 10. The number of hyphens is fixed at 4 in each record, and I would parse each subfield into its own fixed-length parsed variable.
I think I know how to do PARSE once I get past the last backslash; what I can't figure out is how to get that far (i.e. how to ignore everything up to the last backslash when I don't know how many backslashes there will be). Is this doable in DFSORT?
Thanks so much,
David |
|
| Back to top |
|
 |
Skolusu
Senior Member
Joined: 07 Dec 2007 Posts: 2205 Location: San Jose
|
|
|
|
David Eisenberg,
| Code: |
//STEP0200 EXEC PGM=SORT
//SYSOUT DD SYSOUT=*
//SORTIN DD DSN=Your input VB 255 byte file,DISP=SHR
//SORTOUT DD SYSOUT=*
//SYSIN DD *
SORT FIELDS=COPY
INREC IFTHEN=(WHEN=INIT,
PARSE=(%=(ENDAT=C'-'),
%01=(SUBPOS=5,FIXLEN=4),
%=(ENDAT=C'-'),
%02=(ENDBEFR=C'-',FIXLEN=2),
%03=(ENDBEFR=C'-',FIXLEN=2),
%04=(FIXLEN=4)),
BUILD=(1,4,%01,C',',%02,C',',%03,C',',%04)),
IFTHEN=(WHEN=(5,4,SS,EQ,C'\'),OVERLAY=(5:5,4,UFF,EDIT=(IIIT)))
OUTFIL VTOF,BUILD=(5,15,JFY=(SHIFT=LEFT))
//* |
The output is a 15 byte FB file which looks like this
| Code: |
1111,22,33,4444
11,22,33,444
1,22,33,44
|
|
|
| Back to top |
|
 |
David Eisenberg
New User
Joined: 15 Nov 2007 Posts: 39 Location: New York
|
|
|
|
Skolusu,
Thank you very much for this solution!
I do have an issue remaining, however. In my original example data, the fields to the right of the backslash are all numeric. In reality, the data will be alphanumeric; I'm sorry that my examples led you to assume otherwise.
When I subsitute alpha characters in place of the numbers, the first extracted field is incorrect using your solution (unless the number of characters is exactly four). Can your code be generalized to handle any alphanumeric characters (other than the delimiter characters, of course)?
Thank you,
David |
|
| Back to top |
|
 |
Skolusu
Senior Member
Joined: 07 Dec 2007 Posts: 2205 Location: San Jose
|
|
|
|
| David Eisenberg wrote: |
Skolusu,
Thank you very much for this solution!
I do have an issue remaining, however. In my original example data, the fields to the right of the backslash are all numeric. In reality, the data will be alphanumeric; I'm sorry that my examples led you to assume otherwise.
When I subsitute alpha characters in place of the numbers, the first extracted field is incorrect using your solution (unless the number of characters is exactly four). Can your code be generalized to handle any alphanumeric characters (other than the delimiter characters, of course)?
Thank you,
David |
Use the following DFSORT control cards. You just need to change the second IFTHEN to have another parse.
| Code: |
//SYSIN DD *
SORT FIELDS=COPY
INREC IFTHEN=(WHEN=INIT,
PARSE=(%=(ENDAT=C'-'),
%01=(SUBPOS=5,FIXLEN=4),
%=(ENDAT=C'-'),
%02=(ENDBEFR=C'-',FIXLEN=2),
%03=(ENDBEFR=C'-',FIXLEN=2),
%04=(FIXLEN=4)),
BUILD=(1,4,%01,C',',%02,C',',%03,C',',%04)),
IFTHEN=(WHEN=(5,4,SS,EQ,C'\'),PARSE=(%05=(STARTAFT=C'\',FIXLEN=4)),
OVERLAY=(5:%05))
OUTFIL VTOF,BUILD=(5,15,JFY=(SHIFT=LEFT))
//* |
I used the following input
| Code: |
\AAA\BBBB\CC\1111-22-33-4444
\AAAA\BB\CCCC\DD\11-2222-33-444
\AA\1-222-33-44
\AA\A-222-33-44
\AA\BB-222-33-44
\AA\CCC-222-33-44
\AA\DDDD-222-33-44
|
the output will be
| Code: |
1111,22,33,4444
11,2,22,33,444
1,22,22,33,44
A,22,22,33,44
BB,2,22,33,44
CCC,,22,33,44
DDDD,22,33,44
|
|
|
| Back to top |
|
 |
David Eisenberg
New User
Joined: 15 Nov 2007 Posts: 39 Location: New York
|
|
|
|
Skolusu,
Something is wrong; given your sample input, the output from your updated version doesn't appear to be correct. Here's what the output should be:
| Code: |
1111,22,33,4444
11,2222,33,444
1,222,33,44
A,222,33,44
BB,222,33,44
CCC,222,33,44
DDDD,222,33,44 |
I hope I'm not missing something!
David |
|
| Back to top |
|
 |
Skolusu
Senior Member
Joined: 07 Dec 2007 Posts: 2205 Location: San Jose
|
|
|
|
| David Eisenberg wrote: |
Skolusu,
Something is wrong; given your sample input, the output from your updated version doesn't appear to be correct. |
I assumed your field2 length to be 2 bytes instead of 4 bytes. My mistake. Try these control cards
| Code: |
//SYSIN DD *
SORT FIELDS=COPY
INREC IFTHEN=(WHEN=INIT,
PARSE=(%=(ENDAT=C'-'),
%01=(SUBPOS=5,FIXLEN=4),
%=(ENDAT=C'-'),
%02=(ENDBEFR=C'-',FIXLEN=4),
%03=(ENDBEFR=C'-',FIXLEN=2),
%04=(FIXLEN=4)),
BUILD=(1,4,%01,C',',%02,C',',%03,C',',%04)),
IFTHEN=(WHEN=(5,4,SS,EQ,C'\'),
PARSE=(%05=(STARTAFT=C'\',ENDBEFR=C',',FIXLEN=4)),
OVERLAY=(5:%05))
OUTFIL VTOF,BUILD=(5,17,SQZ=(SHIFT=LEFT))
//*
|
|
|
| Back to top |
|
 |
David Eisenberg
New User
Joined: 15 Nov 2007 Posts: 39 Location: New York
|
|
|
|
That's beautiful, Skolusu. Thank you so much!
David |
|
| Back to top |
|
 |
|
|
 |
All times are GMT + 6 Hours |
|