View previous topic :: View next topic
Author
Message
ramsri Active User Joined: 18 Oct 2008Posts: 380 Location: India
Hi,
I have a file (LRECL=80,RECFM=FB) as shown below -
Input:-
Code:
AB123 CD12C GX139 DCGVN DCG98 XY22Y DCGUN
CD12C DCGTN UB153 DCGT7 DCGMN
DCGBN AB123 DCG06 CD12C DHGON XY22Y GX139
XY22Y DCGXN AB123 DCG19 CD12C DCGIN
DCGHN AB123 DCG48 CD12C DCGON MERBL HENRY DCGXI
I would like to pull all the strings that start with "DCG" to output file.
Expected Output:
Code:
DCGVN DCG98 DCGUN
DCGTN DCGT7 DCGMN
DCGBN DCG06
DCGXN DCG19 DCGIN
DCGHN DCG48 DCGON DCGXI
I have tried INREC PARSE with substring search but getting first occurence only. Please help.
Thanks.
Back to top
Bill Woodger Moderator Emeritus Joined: 09 Mar 2011Posts: 7309 Location: Inside the Matrix
PARSE is what you want, so you'd best show what you tried that didn't work.
Back to top
sureshpathi10 Active User Joined: 03 May 2010Posts: 158 Location: Kuala Lumpur
Hi Ramsri,
Could you give us the code you've tried?
Back to top
ramsri Active User Joined: 18 Oct 2008Posts: 380 Location: India
This is what I tried and its output -
Sort Card :
Code:
//STEP0001 EXEC PGM=SORT
//SORTIN DD *
AB123 CD12C GX139 DCGVN DCG98 XY22Y DCGUN
CD12C DCGTN UB153 DCGT7 DCGMN
DCGBN AB123 DCG06 CD12C DHGON XY22Y GX139
XY22Y DCGXN AB123 DCG19 CD12C DCGIN
DCGHN AB123 DCG48 CD12C DCGON MERBL HENRY DCGXI
//SORTOUT DD SYSOUT=*
//SYSOUT DD SYSOUT=*
//SYSIN DD *
SORT FIELDS=COPY
INREC IFTHEN=(WHEN=(1,80,SS,EQ,C'DCG'),
PARSE=(%01=(ABSPOS=1,STARTAT=C'DCG',FIXLEN=5)),
BUILD=(%01))
Output :-
Code:
DCGVN
DCGTN
DCGBN
DCGXN
DCGHN
Expected Output :-
Code:
DCGVN DCG98 DCGUN
DCGTN DCGT7 DCGMN
DCGBN DCG06
DCGXN DCG19 DCGIN
DCGHN DCG48 DCGON DCGXI
What should I change in sort card to get expected results?
Thanks.
Back to top
bodatrinadh Active User Joined: 05 Jan 2007Posts: 101 Location: chennai (India)
Ramsri,
You can try this code -
Code:
//SORT1 EXEC PGM=SORT
//SPRINT DD SYSOUT=*
//SYSOUT DD SYSOUT=*
//SORTIN DD *
AB123 CD12C GX139 DCGVN DCG98 XY22Y DCGUN
CD12C DCGTN UB153 DCGT7 DCGMN
DCGBN AB123 DCG06 CD12C DHGON XY22Y GX139
XY22Y DCGXN AB123 DCG19 CD12C DCGIN
DCGHN AB123 DCG48 CD12C DCGON MERBL HENRY DCGXI
//SORTOUT DD SYSOUT=*
//SYSIN DD *
INREC IFTHEN=(WHEN=(37,3,CH,NE,C'DCG'),
BUILD=(1,36,37:43,5,43:5X),HIT=NEXT),
IFTHEN=(WHEN=(31,3,CH,NE,C'DCG'),
BUILD=(1,30,31:37,5,37:43,5),HIT=NEXT),
IFTHEN=(WHEN=(25,3,CH,NE,C'DCG'),
BUILD=(1,24,25:31,5,31:37,5,37:43,5),HIT=NEXT),
IFTHEN=(WHEN=(19,3,CH,NE,C'DCG'),
BUILD=(1,18,19:25,5,25:31,5,31:37,5),HIT=NEXT),
IFTHEN=(WHEN=(13,3,CH,NE,C'DCG'),
BUILD=(1,12,13:19,5,19:25,5,25:31,5),HIT=NEXT),
IFTHEN=(WHEN=(07,3,CH,NE,C'DCG'),
BUILD=(1,6,7:13,5,13:19,5,19:25,5),HIT=NEXT),
IFTHEN=(WHEN=(01,3,CH,NE,C'DCG'),
BUILD=(1:7,5,7:13,5,13:19,5,19:25,5))
SORT FIELDS=COPY
Output :-
Code:
DCGVN DCG98 DCGUN
DCGTN DCGT7 DCGMN
DCGBN DCG06
DCGXN DCG19 DCGIN
DCGHN DCG48 DCGON DCGXI
Regards,
-3nadh
Back to top
sureshpathi10 Active User Joined: 03 May 2010Posts: 158 Location: Kuala Lumpur
Ramsri,
Alternatively, you can use this as well.
Code:
//STEP0001 EXEC PGM=SORT
//SORTIN DD *
AB123 CD12C GX139 DCGVN DCG98 XY22Y DCGUN
CD12C DCGTN UB153 DCGT7 DCGMN
DCGBN AB123 DCG06 CD12C DHGON XY22Y GX139
XY22Y DCGXN AB123 DCG19 CD12C DCGIN
DCGHN AB123 DCG48 CD12C DCGON MERBL HENRY DCGXI
//SORTOUT DD SYSOUT=*
//SYSOUT DD SYSOUT=*
//SYSIN DD *
SORT FIELDS=COPY
OUTREC PARSE=(%01=(STARTAT=C'DCG',FIXLEN=6),
%02=(STARTAT=C'DCG',FIXLEN=6),
%03=(STARTAT=C'DCG',FIXLEN=6),
%04=(STARTAT=C'DCG',FIXLEN=6),
%05=(STARTAT=C'DCG',FIXLEN=6),
%06=(STARTAT=C'DCG',FIXLEN=6),
%07=(STARTAT=C'DCG',FIXLEN=6),
%08=(STARTAT=C'DCG',FIXLEN=6)),
BUILD=(%01,%02,%03,%04,%05,%06,%07,%08)
output:
Code:
DCGVN DCG98 DCGUN
DCGTN DCGT7 DCGMN
DCGBN DCG06
DCGXN DCG19 DCGIN
DCGHN DCG48 DCGON DCGXI
Back to top
ramsri Active User Joined: 18 Oct 2008Posts: 380 Location: India
3nadh and Suresh, thanks for the solutions. I wonder how to work it out if an input records has got more than 30 "DCG" coming in !! I thought SORT could provide a simpler solution Looks like I need to try Easytrieve.
Thanks again.
Back to top
ramsri Active User Joined: 18 Oct 2008Posts: 380 Location: India
3nadh, based on your idea, I have written below code but does not get SQZ working......can you please help?
Code:
SORT FIELDS=COPY
INREC IFTHEN=(WHEN=(1,3,CH,EQ,C'DCG'),OVERLAY=(50:1,5),HIT=NEXT),
IFTHEN=(WHEN=(7,3,CH,EQ,C'DCG'),OVERLAY=(56:7,5),HIT=NEXT),
IFTHEN=(WHEN=(13,3,CH,EQ,C'DCG'),OVERLAY=(62:13,5),HIT=NEXT),
IFTHEN=(WHEN=(19,3,CH,EQ,C'DCG'),OVERLAY=(68:19,5),HIT=NEXT),
IFTHEN=(WHEN=(25,3,CH,EQ,C'DCG'),OVERLAY=(74:25,5),HIT=NEXT),
IFTHEN=(WHEN=(31,3,CH,EQ,C'DCG'),OVERLAY=(80:31,5),HIT=NEXT),
IFTHEN=(WHEN=(37,3,CH,EQ,C'DCG'),OVERLAY=(86:37,5),HIT=NEXT),
IFTHEN=(WHEN=(43,3,CH,EQ,C'DCG'),OVERLAY=(92:43,5),HIT=NEXT)
OUTREC BUILD=(50,5,X,56,5,X,62,5,X,68,5,X,74,5,X,80,5,X,86,
5,X,92,5,SQZ=(SHIFT=LEFT))
Output with above card:-
Code:
DCGVN DCG98 DCGUN
DCGTN DCGT7 DCGMN
DCGBN DCG06
DCGXN DCG19 DCGIN
DCGHN DCG48 DCGON DCGXI
Thanks.
Back to top
bodatrinadh Active User Joined: 05 Jan 2007Posts: 101 Location: chennai (India)
Ramsri,
Quote:
I wonder how to work it out if an input records has got more than 30 "DCG" coming in !! I thought SORT could provide a simpler solution Looks like I need to try Easytrieve.
If your input contains 30 "DCG" then you can try Suresh's code which is pretty simple than mine.
Thanks
-3nadh
Back to top
bodatrinadh Active User Joined: 05 Jan 2007Posts: 101 Location: chennai (India)
Ramsri,
And i observed that your sort card doing manipulation from left to Right where as mine it is doing from Right to Left...
My Code -
Code:
//SYSIN DD *
INREC IFTHEN=(WHEN=(37,3,CH,NE,C'DCG'),
BUILD=(1,36,37:43,5,43:5X),HIT=NEXT),
IFTHEN=(WHEN=(31,3,CH,NE,C'DCG'),
BUILD=(1,30,31:37,5,37:43,5),HIT=NEXT),
IFTHEN=(WHEN=(25,3,CH,NE,C'DCG'),
BUILD=(1,24,25:31,5,31:37,5,37:43,5),HIT=NEXT),
-
-
-
Your code -
Code:
SORT FIELDS=COPY
INREC IFTHEN=(WHEN=(1,3,CH,EQ,C'DCG'),OVERLAY=(50:1,5),HIT=NEXT),
IFTHEN=(WHEN=(7,3,CH,EQ,C'DCG'),OVERLAY=(56:7,5),HIT=NEXT),
IFTHEN=(WHEN=(13,3,CH,EQ,C'DCG'),OVERLAY=(62:13,5),HIT=NEXT),
IFTHEN=(WHEN=(19,3,CH,EQ,C'DCG'),OVERLAY=(68:19,5),HIT=NEXT),
-
-
-
-
So, please change accordingly and Check again...
Thanks
-3nadh
Back to top
Bill Woodger Moderator Emeritus Joined: 09 Mar 2011Posts: 7309 Location: Inside the Matrix
The problem with the existing PARSE suggestions is that they will pick up "embedded" DCGs (have some in your test data, your test data is for testing, so it should actually test things).
Code:
SORT FIELDS=COPY
INREC IFTHEN=(WHEN=INIT,BUILD=(X,1,80),
IFTHEN=(WHEN=INIT,
PARSE=(%01=(STARTAT=C' DCG',FIXLEN=7),
%02=(STARTAT=C' DCG',FIXLEN=7),
%03=(STARTAT=C' DCG',FIXLEN=7),
%04=(STARTAT=C' DCG',FIXLEN=7),
%05=(STARTAT=C' DCG',FIXLEN=7),
%06=(STARTAT=C' DCG',FIXLEN=7),
%07=(STARTAT=C' DCG',FIXLEN=7),
%08=(STARTAT=C' DCG',FIXLEN=7)),
IFTHEN=(WHEN=INIT,
BUILD=(%01,%02,%03,%04,%05,%06,%07,%08,82:X)),
IFTHEN=(WHEN=INIT,
BUILD=(2,80)),
Inserts a blank at the start of the record. Starts a PARSEd field only with " DCG". Puts line back together with only extracted data, and ensuring blank-padding up to and including 82 if necessary (you can get up to 11 fields into your 80-byte records ramsri, not 30). Removes the leading blank. Untested, but you should get the picture.
Back to top
ramsri Active User Joined: 18 Oct 2008Posts: 380 Location: India
Bill, this is the output I got with your sort card
Code:
DCGVN DCGUN
DCGTN DCGT7
DCGBN DCG06
DCGXN DCG19 DCGIN
DCGHN DCG48 DCGON DCGXI
Thanks.
Back to top
Bill Woodger Moderator Emeritus Joined: 09 Mar 2011Posts: 7309 Location: Inside the Matrix
Are you complaining about the spacing? If so, I'd have hoped that was something you could cope with yourself. I erroneously changed the lengths from 6 to 7, not realising the text was in groups of five so there was a trailing blank already (which I make leading, and keep the trailing one).
If you think PARSE isn't working you'd best show your input data.
Back to top
ramsri Active User Joined: 18 Oct 2008Posts: 380 Location: India
Bill, your idea has worked.....I got errors with your code thus modified it and it has worked.......no issues.
Thanks a lot.
Back to top
Piyush Jadhav New User Joined: 06 Feb 2014Posts: 7 Location: India
Back to top
Please enable JavaScript!