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
 
PARSE question: finding the last occurrence of a delimiter

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

New User


Joined: 15 Nov 2007
Posts: 39
Location: New York

PostPosted: Thu Jul 22, 2010 4:25 pm    Post subject: PARSE question: finding the last occurrence of a delimiter
Reply with quote

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
View user's profile Send private message

Skolusu

Senior Member


Joined: 07 Dec 2007
Posts: 2205
Location: San Jose

PostPosted: Thu Jul 22, 2010 9:22 pm    Post subject: Reply to: PARSE question: finding the last occurrence of a d
Reply with quote

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
View user's profile Send private message
David Eisenberg

New User


Joined: 15 Nov 2007
Posts: 39
Location: New York

PostPosted: Sat Jul 24, 2010 12:30 am    Post subject: Reply to: PARSE question: finding the last occurrence of a d
Reply with quote

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
View user's profile Send private message
Skolusu

Senior Member


Joined: 07 Dec 2007
Posts: 2205
Location: San Jose

PostPosted: Sat Jul 24, 2010 2:08 am    Post subject: Re: Reply to: PARSE question: finding the last occurrence of
Reply with quote

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
View user's profile Send private message
David Eisenberg

New User


Joined: 15 Nov 2007
Posts: 39
Location: New York

PostPosted: Tue Jul 27, 2010 12:48 am    Post subject: Reply to: PARSE question: finding the last occurrence of a d
Reply with quote

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
View user's profile Send private message
Skolusu

Senior Member


Joined: 07 Dec 2007
Posts: 2205
Location: San Jose

PostPosted: Tue Jul 27, 2010 11:54 pm    Post subject: Re: Reply to: PARSE question: finding the last occurrence of
Reply with quote

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
View user's profile Send private message
David Eisenberg

New User


Joined: 15 Nov 2007
Posts: 39
Location: New York

PostPosted: Wed Jul 28, 2010 12:11 am    Post subject: Reply to: PARSE question: finding the last occurrence of a d
Reply with quote

That's beautiful, Skolusu. Thank you so much!

David
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 question about dfsms management clas... Hervey Martinez IBM Tools 0 Tue Oct 10, 2017 6:19 pm
No new posts LMINIT problem - not finding DDNAME Danielle.Filteau CLIST & REXX 7 Tue Sep 19, 2017 9:57 pm
No new posts Question related to Data dictionary f... rexx77 SYNCSORT 3 Thu Aug 31, 2017 7:23 am
No new posts How to change a string containing the... chong.zhou TSO/ISPF 6 Tue Aug 29, 2017 4:54 pm
No new posts Finding IMS resource blocker after se... Hooman24 IMS DB/DC 1 Wed Aug 16, 2017 9:17 pm

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