Page 1 of 1

How Parse file with more than 100 column

PostPosted: Wed Mar 30, 2011 9:51 pm
by rjambu
Hi I need to parse a CSV file that has 188 columns.

JCL Syntax i used is below giving PARSED FIELD DEFINITION ERROR. ( since the column number crossed 100.)

How to process that file that has More than 100 columns,( in this case it is 188 columns.)

Can anyone help me in this regard.

Thanks
JRS



//SORTOUT  DD  DSN=A.B.C,               
//             UNIT=DISK,SPACE=(TRK,(1,2),RLSE),       
//             DCB=(LRECL=2310,BLKSIZE=0,RECFM=FB),     
//             DISP=(NEW,CATLG,DELETE)                 
//SYSSORT  DD SYSOUT=*                                 
//SYSUDUMP DD SYSOUT=*                                 
//*                                                     
//SYSIN    DD  *                           
 SORT FIELDS=COPY                         
 INREC PARSE=(%00=(ENDBEFR=C'|',FIXLEN=30),
              %01=(ENDBEFR=C'|',FIXLEN=10),
              %02=(ENDBEFR=C'|',FIXLEN=12),
              %03=(ENDBEFR=C'|',FIXLEN=12),
              .
              .
              .
              %99=(ENDBEFR=C'|',FIXLEN=10),                             
              %100=(ENDBEFR=C'|',FIXLEN=04),                           
              %101=(ENDBEFR=C'|',FIXLEN=02),                           
              .
              .
              .
              %185=(ENDBEFR=C'|',FIXLEN=02),                           
              %186=(ENDBEFR=C'|',FIXLEN=08),                           
              %187=(ENDBEFR=C'|',FIXLEN=08)),                           
 BUILD=(%00,%01,%02,%03,...                                            X
           %99,%100,%101,..                                            X
            %185,%186,%187)
/*
//

Re: How Parse file with more than 100 column

PostPosted: Wed Mar 30, 2011 10:13 pm
by Frank Yaeger
You can only use %00-%99 in one pass for PARSE. So the solution would be to use two passes, either by having two DFSORT steps or one ICETOOL step with two COPY operators.

Re: How Parse file with more than 100 column

PostPosted: Wed Mar 30, 2011 11:45 pm
by rjambu
Hi Frank, Can you provide me skeleton code for this process.
Thanks

Re: How Parse file with more than 100 column

PostPosted: Thu Mar 31, 2011 2:18 am
by Frank Yaeger
I'll demonstrate the technique with a few fields. Say we had this as input:

ABC|DEFGHI|JKL|MNOPQ|RSTU|VW|XYZAB|CDE|     
AB|CDEFGH|IJKLMN|OPQRSTUV|W|XYZ|AB|CDEFG|   


To handle this in two parts, we would PARSE the first group with %nn variables individually and the remaining bytes with one %nn variable.
Then we would PARSE the next group starting with the remaining bytes. For example:

//S1    EXEC  PGM=ICETOOL
//TOOLMSG DD SYSOUT=*
//DFSMSG  DD SYSOUT=*
//IN DD *
ABC|DEFGHI|JKL|MNOPQ|RSTU|VW|XYZAB|CDE|
AB|CDEFGH|IJKLMN|OPQRSTUV|W|XYZ|AB|CDEFG|
//T1 DD DSN=&&T1,UNIT=SYSDA,SPACE=(CYL,(5,5)),DISP=(,PASS)
//OUT DD SYSOUT=*
//TOOLIN DD *
COPY FROM(IN) TO(T1) USING(CTL1)
COPY FROM(T1) TO(OUT) USING(CTL2)
/*
//CTL1CNTL DD *
  INREC PARSE=(%00=(ENDBEFR=C'|',FIXLEN=5),
              %01=(ENDBEFR=C'|',FIXLEN=10),
              %02=(ENDBEFR=C'|',FIXLEN=12),
              %03=(ENDBEFR=C'|',FIXLEN=12),
              %99=(FIXLEN=188)),
   BUILD=(%00,%01,%02,%03,%99)
/*
//CTL2CNTL DD *
  INREC PARSE=(%00=(ABSPOS=40,ENDBEFR=C'|',FIXLEN=9),
              %01=(ENDBEFR=C'|',FIXLEN=15),
              %02=(ENDBEFR=C'|',FIXLEN=9),
              %03=(ENDBEFR=C'|',FIXLEN=10)),
   BUILD=(1,39,%00,%01,%02,%03)
/*


Notice that I've used %01-%03 twice.

The first COPY operator would write the following in T1:

ABC  DEFGHI    JKL         MNOPQ       RSTU|VW|XYZAB|CDE|
AB   CDEFGH    IJKLMN      OPQRSTUV    W|XYZ|AB|CDEFG|


Now we can PARSE the remaining fields with the second COPY operator. Just use ABSPOS=n to start at the correct place in the T1 records.

So after the second COPY operator, OUT would have the following:

ABC  DEFGHI    JKL         MNOPQ       RSTU     VW             XYZAB    CDE     
AB   CDEFGH    IJKLMN      OPQRSTUV    W        XYZ            AB       CDEFG   


Hopefully, you can extrapolate this to the number of fields you need. Just use one COPY step with %00-%98 for the first 99 fields and %99 for the remaining fields. Then use another COPY operator with %00-%nn to handle the remaining bytes starting at the appropriate position (= the total length of the %00-%98 fields).