Portal | Manuals | References | Downloads | Info | Programs | JCLs | Mainframe wiki | Quick Ref
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Profile Log in to check your private messages Log in
 
How to Parse the Nth column directly from a csv file

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DFSORT/ICETOOL
View previous topic :: :: View next topic  
Author Message
Chaketh Ram

New User


Joined: 16 Nov 2011
Posts: 7
Location: India

PostPosted: Thu May 03, 2012 7:18 pm    Post subject: How to Parse the Nth column directly from a csv file
Reply with quote

There is a csv file with more than 80 columns. The concerned Columns are say 10th, 15th, 70th and 78th one.


To parse the 10th col from the file,generally the following sort card is used
Code:

   SORT FIELDS=COPY
   OUTREC PARSE=(%=(ENDBEFR=C','),
   %=(ENDBEFR=C','),
   %=(ENDBEFR=C','),
   %=(ENDBEFR=C','),
   %=(ENDBEFR=C','),
   %=(ENDBEFR=C','),
   %=(ENDBEFR=C','),
   %=(ENDBEFR=C','),
   %=(ENDBEFR=C','),
   %10=(ENDBEFR=C',',FIXLEN=45)),
   BUILD=(%10)



Using this approach, to parse and get the 70th column, the keywords %=(ENDBEFR=C','), has to be repeated so many times.

Other than this approach,how to parse and get directly the 10th, 15th, 70th and 78th columns ?

Thanks - Chaketh
Back to top
View user's profile Send private message

Bill Woodger

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7314

PostPosted: Thu May 03, 2012 7:24 pm    Post subject: Reply to: How to Parse the Nth column directly from a csv fi
Reply with quote

That's what R in the prefix area is for.
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6970
Location: porcelain throne

PostPosted: Thu May 03, 2012 7:49 pm    Post subject:
Reply with quote

Bill,
are you referring to the line command "R"?
Back to top
View user's profile Send private message
Bill Woodger

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7314

PostPosted: Thu May 03, 2012 7:57 pm    Post subject: Reply to: How to Parse the Nth column directly from a csv fi
Reply with quote

Yep. Quickest way I know to get 100 identical statements and then just change four of them, or whatever the acutal numbers need to be.
Back to top
View user's profile Send private message
Chaketh Ram

New User


Joined: 16 Nov 2011
Posts: 7
Location: India

PostPosted: Thu May 03, 2012 8:01 pm    Post subject:
Reply with quote

Bill,
Replicating %=(ENDBEFR=C','), for n times and changing the required 4/5 lines could be done.

Just wanted to know is there any smarter way of doing this other than replicating...
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6970
Location: porcelain throne

PostPosted: Thu May 03, 2012 8:16 pm    Post subject:
Reply with quote

PARSE uses a pointer to address the record,
and this pointer needs to be incremented.

i can not think if any language,
which would allow you to address the 80th something of a variable record
without either employing
  • loop-logic for an index (pointer)
  • data definitions for the 1-79th occurance


while DFSORT is pretty flexible,
it does not provide the looping capabilities to bump a pointer x-number of times.
Back to top
View user's profile Send private message
Bill Woodger

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7314

PostPosted: Thu May 03, 2012 8:22 pm    Post subject: Reply to: How to Parse the Nth column directly from a csv fi
Reply with quote

I don't know if it is "smart" to try this. To pick out J, O and Z:

Code:
//PARSEIT  EXEC PGM=SORT
//SYSOUT   DD SYSOUT=*
//SORTOUT  DD SYSOUT=*
//SYSIN DD *
  OPTION COPY
  INREC IFTHEN=(WHEN=INIT,
                FINDREP=(IN=C',',OUT=C' ',DO=8)),
        IFTHEN=(WHEN=INIT,
                PARSE=(%01=(STARTAFT=C',',ENDBEFR=C',',FIXLEN=1))),
        IFTHEN=(WHEN=INIT,
                FINDREP=(IN=C',',OUT=C' ',DO=5)),
        IFTHEN=(WHEN=INIT,
                PARSE=(%02=(STARTAFT=C',',ENDBEFR=C',',FIXLEN=1))),
        IFTHEN=(WHEN=INIT,
                FINDREP=(IN=C',',OUT=C' ',DO=11)),
        IFTHEN=(WHEN=INIT,
                PARSE=(%03=(STARTAFT=C',',ENDBEFR=C',',FIXLEN=1))),
        IFTHEN=(WHEN=INIT,
         BUILD=(C'>',%01,C'<>',%02,C'<>',%03,C'<'))
//SORTIN DD *
A,B,C,D,E,F,G,R,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z


Code:
>J<>O<>Z<


Not going to work with commas embedded within quotes (not directly).

For 80 fields, I'm not sure I'd use it. To extend PARSE beyond one hundred delimited fields, maybe worth a go.
Back to top
View user's profile Send private message
sqlcode1

Active Member


Joined: 08 Apr 2010
Posts: 578
Location: USA

PostPosted: Thu May 03, 2012 8:47 pm    Post subject:
Reply with quote

Chaketh Ram,
I don't think there is an easy way to achieve this.
Quote:

%
Specifies a parsed field to be ignored. No data is extracted, but the starting point for the next parsed field advances according to the suboperands specified. Use % when you don't need the data from a particular field, but you do need to get to the next field. For example, if we had the four CSV fields shown earlier as input, but we only wanted to extract the first and fourth fields, we could use this OUTFIL statement: OUTFIL PARSE=(%01=(ENDBEFR=C',',FIXLEN=5),
%=(ENDBEFR=C','),
%=(ENDBEFR=C','),
%04=(FIXLEN=5)),
BUILD=(1:%01,11:%04,21:%01,HEX)


Data is extracted for %01 (first field) and %04 (fourth field), but not for % (second and third fields).


I am thinking, your best bet (if you don't want to code),looks like is to build PARSE statement dynamically.

Thanks,
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6970
Location: porcelain throne

PostPosted: Thu May 03, 2012 8:50 pm    Post subject:
Reply with quote

MF,
stepped in it that time:
Code:
,DO=8)),
Back to top
View user's profile Send private message
Bill Woodger

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7314

PostPosted: Fri May 04, 2012 8:48 pm    Post subject: Reply to: How to Parse the Nth column directly from a csv fi
Reply with quote

I had another little dabble with this. The only benefits so far seems to be few lines of code vs many lines of code, and with the numbers easier to know which field rather than "counting" the %s. I've only tested with one-byte fields and only up to 130. The % easily extends that far anyway, still leaving 100 numbered parsed variables available. The parsing is faster, though not hugely.
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DFSORT/ICETOOL All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts Moving a PS file as body of a mail! Vignesh Sid JCL & VSAM 1 Tue Nov 21, 2017 9:23 pm
No new posts unable to set RC = 4 when empty file migusd SYNCSORT 1 Tue Nov 21, 2017 1:21 am
No new posts VBS and VB, COBOL syntax is the same ... natt.sut COBOL Programming 3 Sun Nov 12, 2017 6:36 am
No new posts Updating data from one file to other!!! Vignesh Sid SYNCSORT 1 Mon Nov 06, 2017 2:42 pm
This topic is locked: you cannot edit posts or make replies. Need help how to pass the ESP variabl... Venkichaitu JCL & VSAM 12 Thu Nov 02, 2017 3:53 am

Facebook
Back to Top
 
Job Vacancies | Forum Rules | Bookmarks | Subscriptions | FAQ | Polls | Contact Us