Parsing using SORT



IBM's flagship sort product DFSORT for sorting, merging, copying, data manipulation and reporting. Includes ICETOOL and ICEGENER

Parsing using SORT

Postby Bala1 » Tue Jul 06, 2010 7:45 pm

Hi ,
How to split a file containing records with different characters as delimiter in them??

If my input file is of the
REC1+137:20090901+2
would like to output like
REC1+;137;:;20090901;+;2

I tried using the below Control Card

//SYMNAMES DD * 
FLD1,1,4         
FLD2,%00
FLD3,%01
..........
..........
COL,':'
PLU,'+'
SEMI,';'
//SORTIN DD DSN=
//SORTOUT DD DSN=


//SYSIN DD *                                         
OPTION COPY                                           
* EXTRACT SECOND FIELD INTO %00.                     
INREC PARSE=(FLD2=(ABSPOS=5,ENDBEFR=(COL OR PLU)),
BUILD=(FLD1,SEMI,FLD2,SEMI,FLD3,SEMI,FLD4,SEMI
FLD6,SEMI,FLD7,SEMI,FLD8,SEMI,FLD9,SEMI,FLD10)   


I am not sure if using SORT we can split the file containing more than one delimiter. If yes can you help me with it??
_____________________
Cheers,
Bala
Bala1
 
Posts: 15
Joined: Tue Apr 06, 2010 7:07 pm
Location: London, United Kingdom
Has thanked: 0 time
Been thanked: 0 time

Re: Parsing using SORT

Postby Frank Yaeger » Tue Jul 06, 2010 10:46 pm

You can use multiple delimiters in PARSE, e.g.

%01=(ENDBEFR=C';',ENDBEFR=C'+',FIXLEN=10)

Of course, you can use symbols where applicable.

You haven't explained what you're trying to do well enough for me to show you how to do it. You need to explain in detail the exact rules for parsing the input records and creating the output records. It would also help if you showed more than one input and output record. What is the maximum number of fields in an input record? What is the RECFM and LRECL of the input file?

REC1+;137;:;20090901;+;2

Why is + part of the first field (REC1+;), but a separate field later on (;+;)? You need to explain the rules better.
Frank Yaeger - DFSORT Development Team (IBM) - yaeger@us.ibm.com
Specialties: JOINKEYS, FINDREP, WHEN=GROUP, ICETOOL, Symbols, Migration
=> DFSORT/MVS is on the Web at http://www.ibm.com/storage/dfsort
User avatar
Frank Yaeger
Global moderator
 
Posts: 1079
Joined: Sat Jun 09, 2007 8:44 pm
Has thanked: 0 time
Been thanked: 15 times

Re: Parsing using SORT

Postby Bala1 » Tue Jul 06, 2010 11:12 pm

Hi Frank,
Thanks a lot for your reply... Since the first 3 character of the file is always going to be the followed by the special character '+'. and hence thought that we I can put that in one variable.....

Input File:
REC1+137:20090901:2'
TST1+AAI+++T53+EN'
RFF1+ON:2010000843'

Output file required:
REC1+137;:;20090901;:;2'
TST1+AAI;+;+;+;T53;+;EN'
RFF1+ON;:;2010000843'


As suggested i tried to modify the SYSIN card but still i am not able to create the required file.... :(
//SYSIN DD *                                                 
 OPTION COPY                                                 
 INREC PARSE=(FLD2=(ABSPOS=5,ENDBEFR=C';',ENDBEFR=C'+'),     
 FLD3=(ENDBEFR=C';',ENDBEFR=C'+'),                           
 FLD4=(ENDBEFR=C';',ENDBEFR=C'+'),                           
 FLD5=(ENDBEFR=C';',ENDBEFR=C'+'),                           
 FLD6=(ENDBEFR=C';',ENDBEFR=C'+'),                           
 FLD7=(ENDBEFR=C';',ENDBEFR=C'+'),                           
 FLD8=(ENDBEFR=C';',ENDBEFR=C'+'),                           
 FLD9=(ENDBEFR=C';',ENDBEFR=C'+'),                           
 FLD10=(ENDBEFR=C';',ENDBEFR=C'+')),                         
 BUILD=(FLD1,SEMI,FLD2,SEMI,FLD3,SEMI,FLD4,SEMI,FLD5,SEMI,   
 FLD6,SEMI,FLD7,SEMI,FLD8,SEMI,FLD9,SEMI,FLD10)               
/*                                                           


The following error was logged
I[color=#FF0000]CE243A F PARSED FIELD DEFINITION ERROR                                         
                         ',ENDBEFR=C'+'),%02=(ENDBEFR=C';',ENDBEFR=C'+'),%03=(EN
                         BEFR=C';',ENDBEFR=C'+'),%04=(ENDBEFR=C';',ENDBEFR=C'+')
                         %05=(ENDBEFR=C';',ENDBEFR=C'+'),%06=(ENDBEFR=C';',ENDBE
                         R=C'+'),%07=(ENDBEFR=C';',ENDBEFR=C'+'),%08=(ENDBEFR=C'
                         ',ENDBEFR=C'+')),BUILD=(1,4,C';',%00,C';',%01,C';',%02,
                         ';',%03,C';',%04,C';',%05,C';',%06,C';',%07,C';',%08) [/color]


the maximum occurance of the special characters is 10 in the input file and (its gonna be a Fixed BLock of length 550). The idea behind this is to create a CSV file which would be the input for windows based application .

Hope i have brought the question in much clear manner. the problem that i face is that the length of the field between these special character is not a fixed one.

Cheers,
Bala
_____________________
Cheers,
Bala
Bala1
 
Posts: 15
Joined: Tue Apr 06, 2010 7:07 pm
Location: London, United Kingdom
Has thanked: 0 time
Been thanked: 0 time

Re: Parsing using SORT

Postby Frank Yaeger » Wed Jul 07, 2010 1:14 am

You received the error message because you didn't have FIXLEN=n which is required in each %nn operand.

the problem that i face is that the length of the field between these special character is not a fixed one.


We need a maximum length for the fields between the delimiters - I'll assume that maximum length is 29, so I'll use FIXLEN=30 to include a blank after each such field.

Here's a DFSORT job that will do what you asked for (although I'm not convinced what you asked for is the complete story of what you want, so I wouldn't be surprised if you came back and said it doesn't work for some particular input data that you didn't mention as a possibility, e.g. embedded blanks in a field):

//S1 EXEC PGM=SORT
//SYSOUT DD SYSOUT=*
//SORTIN DD DSN=... input file
//SORTOUT DD DSN=...  output file
//SYSIN DD *
 OPTION COPY
 INREC IFTHEN=(WHEN=INIT,
   PARSE=(%02=(ABSPOS=6,ENDBEFR=C':',ENDBEFR=C'+',FIXLEN=30),
    %03=(SUBPOS=1,FIXLEN=1),
    %04=(ENDBEFR=C':',ENDBEFR=C'+',FIXLEN=30),
    %05=(SUBPOS=1,FIXLEN=1),
    %06=(ENDBEFR=C':',ENDBEFR=C'+',FIXLEN=30),
    %07=(SUBPOS=1,FIXLEN=1),
    %08=(ENDBEFR=C':',ENDBEFR=C'+',FIXLEN=30),
    %09=(SUBPOS=1,FIXLEN=1),
    %10=(FIXLEN=30)),
   BUILD=(1,5,%02,%03,X,%04,%05,X,%06,%07,X,%08,%09,X,%10)),
  IFTHEN=(WHEN=INIT,
   BUILD=(1,163,SQZ=(SHIFT=LEFT,MID=C';'),550:X))
/*
Frank Yaeger - DFSORT Development Team (IBM) - yaeger@us.ibm.com
Specialties: JOINKEYS, FINDREP, WHEN=GROUP, ICETOOL, Symbols, Migration
=> DFSORT/MVS is on the Web at http://www.ibm.com/storage/dfsort
User avatar
Frank Yaeger
Global moderator
 
Posts: 1079
Joined: Sat Jun 09, 2007 8:44 pm
Has thanked: 0 time
Been thanked: 15 times

Re: Parsing using SORT

Postby Bala1 » Wed Jul 07, 2010 2:24 pm

Hi Frank,

Thanks a lot... It worked.... Now it would be easly for the windows based application to interpret the EDI files...:-)


Thanks a lot for your valuable input and it was a good lesson learned... :D
_____________________
Cheers,
Bala
Bala1
 
Posts: 15
Joined: Tue Apr 06, 2010 7:07 pm
Location: London, United Kingdom
Has thanked: 0 time
Been thanked: 0 time


Return to DFSORT/ICETOOL/ICEGENER

 


  • Related topics
    Replies
    Views
    Last post