IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Copying only first and last word from a record


IBM Mainframe Forums -> SYNCSORT
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
chandan.inst

Active User


Joined: 03 Nov 2005
Posts: 275
Location: Mumbai

PostPosted: Wed Jan 31, 2018 4:19 pm
Reply with quote

Hi All,

I tries to search on forum for this requirement but could not find appropriate post.

My input file is as below

Code:
TestA, testA1 testA2 testA3
TestB, testB1 testB2
TestC, testC1 testC2 testC3 TestC4


And I need output file as below
Code:

TestA testA3
TestB testB2
TestC TestC4


Basically I want to copy only first and last word from records. Its FB file of length 40.

is it possible to do with Syncsort?

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

Active User


Joined: 20 Dec 2014
Posts: 446
Location: USA

PostPosted: Wed Jan 31, 2018 10:51 pm
Reply with quote

It should Not be too difficult with PARSE considering the LRECL is only 40 bytes so you can fit in only a few words:
Code:
 INREC IFTHEN=(WHEN=INIT,PARSE=(%00=(ENDBEFR=C', ',FIXLEN=10),
              %01=(ENDBEFR=C' ',FIXLEN=10),
              %02=(ENDBEFR=C' ',FIXLEN=10),
              %03=(ENDBEFR=C' ',FIXLEN=10),
              %04=(FIXLEN=10)),BUILD=(%00,%01,%02,%03,%04)),
      IFTHEN=(WHEN=(41,1,CH,NE,C' '),
      BUILD=(%00,C' ',%04)),
      IFTHEN=(WHEN=(31,1,CH,NE,C' '),
      BUILD=(%00,C' ',%03)),
      IFTHEN=(WHEN=(21,1,CH,NE,C' '),
      BUILD=(%00,C' ',%02)),
      IFTHEN=(WHEN=(11,1,CH,NE,C' '),
      BUILD=(%00,C' ',%01))
 OPTION COPY


It may Not be the best solution but you can work from here.

If you are concerned about the spaces then you may use FINDREP=(INOUT=(C' ',C'~') and JFY=(SHIFT=RIGHT) and SQZ=(SHIFT=LEFT) wherever needed.

.
Back to top
View user's profile Send private message
sergeyken

Active Member


Joined: 29 Apr 2008
Posts: 924
Location: Maryland

PostPosted: Thu Feb 01, 2018 12:22 am
Reply with quote

Can be enhanced, to make the code more flexible, to handle free-text input.
RahulG31 wrote:
Code:
 INREC IFTHEN=(WHEN=INIT,
         PARSE=(%00=(STARTAT=NONBLANK,ENDBEFR=C',',ENDBEFR=BLANKS,FIXLEN=10),
                %01=(STARTAT=NONBLANK,ENDBEFR=C',',ENDBEFR=BLANKS,FIXLEN=10),
                %02=(STARTAT=NONBLANK,ENDBEFR=C',',ENDBEFR=BLANKS,FIXLEN=10),
                %03=(STARTAT=NONBLANK,ENDBEFR=C',',ENDBEFR=BLANKS,FIXLEN=10),
                %04=(STARTAT=NONBLANK,ENDBEFR=C',',ENDBEFR=BLANKS,FIXLEN=10)),
         BUILD=(%00,%01,%02,%03,%04)),
      IFTHEN=(WHEN=(41,1,CH,NE,C' '),
         BUILD=(%00,C' ',%04)),
      IFTHEN=(WHEN=(31,1,CH,NE,C' '),
         BUILD=(%00,C' ',%03)),
      IFTHEN=(WHEN=(21,1,CH,NE,C' '),
         BUILD=(%00,C' ',%02)),
      IFTHEN=(WHEN=(11,1,CH,NE,C' '),
         BUILD=(%00,C' ',%01))
 OPTION COPY
 END

Back to top
View user's profile Send private message
chandan.inst

Active User


Joined: 03 Nov 2005
Posts: 275
Location: Mumbai

PostPosted: Thu Feb 01, 2018 3:48 pm
Reply with quote

Thanks for the reply guys.

I will try this. Only issue I didn't highlight in original post is my input words can be of different length.

But I will check with these solutions. it should work
Back to top
View user's profile Send private message
sergeyken

Active Member


Joined: 29 Apr 2008
Posts: 924
Location: Maryland

PostPosted: Fri Feb 02, 2018 3:22 am
Reply with quote

chandan.inst wrote:
Only issue I didn't highlight in original post is my input words can be of different length.

PARSE= will handle different length. Furthermore, STARTAFT=BLANKS,ENDBEFR=BLANKS will take care of any number of separating blanks.

You may need to set FIXLEN= to the maximum possible word length.

In the output record, you can use parameters JFY= and/or SQZ= to truncate unneeded blanks in output record.
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> SYNCSORT

 


Similar Topics
Topic Forum Replies
No new posts Record count of RECFM=U tape file DFSORT/ICETOOL 17
No new posts Checking the total counts inside a re... JCL & VSAM 5
This topic is locked: you cannot edit posts or make replies. Splice JCL into one record for DD sta... SYNCSORT 2
No new posts Copying data from prev record using SORT SYNCSORT 19
No new posts Break a record into fields, each fiel... SYNCSORT 2
Search our Forums:

Back to Top