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

Get particular entries with a string to output


IBM Mainframe Forums -> JCL & VSAM
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
ramsri

Active User


Joined: 18 Oct 2008
Posts: 380
Location: India

PostPosted: Mon Dec 23, 2013 8:57 pm
Reply with quote

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

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Mon Dec 23, 2013 9:28 pm
Reply with quote

PARSE is what you want, so you'd best show what you tried that didn't work.
Back to top
View user's profile Send private message
sureshpathi10

Active User


Joined: 03 May 2010
Posts: 158
Location: Kuala Lumpur

PostPosted: Tue Dec 24, 2013 8:20 am
Reply with quote

Hi Ramsri,

Could you give us the code you've tried?
Back to top
View user's profile Send private message
ramsri

Active User


Joined: 18 Oct 2008
Posts: 380
Location: India

PostPosted: Tue Dec 24, 2013 1:10 pm
Reply with quote

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

Active User


Joined: 05 Jan 2007
Posts: 101
Location: chennai (India)

PostPosted: Tue Dec 24, 2013 1:47 pm
Reply with quote

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

Active User


Joined: 03 May 2010
Posts: 158
Location: Kuala Lumpur

PostPosted: Tue Dec 24, 2013 2:00 pm
Reply with quote

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

Active User


Joined: 18 Oct 2008
Posts: 380
Location: India

PostPosted: Tue Dec 24, 2013 2:05 pm
Reply with quote

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 icon_confused.gif Looks like I need to try Easytrieve.

Thanks again.
Back to top
View user's profile Send private message
ramsri

Active User


Joined: 18 Oct 2008
Posts: 380
Location: India

PostPosted: Tue Dec 24, 2013 2:44 pm
Reply with quote

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

Active User


Joined: 05 Jan 2007
Posts: 101
Location: chennai (India)

PostPosted: Tue Dec 24, 2013 3:13 pm
Reply with quote

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

Active User


Joined: 05 Jan 2007
Posts: 101
Location: chennai (India)

PostPosted: Tue Dec 24, 2013 3:33 pm
Reply with quote

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

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Tue Dec 24, 2013 3:40 pm
Reply with quote

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

Active User


Joined: 18 Oct 2008
Posts: 380
Location: India

PostPosted: Tue Dec 24, 2013 3:59 pm
Reply with quote

Bill, this is the output I got with your sort card icon_confused.gif

Code:

DCGVN  DCGUN             
DCGTN  DCGT7             
DCGBN  DCG06             
DCGXN  DCG19  DCGIN       
DCGHN  DCG48  DCGON  DCGXI


Thanks.
Back to top
View user's profile Send private message
Bill Woodger

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Tue Dec 24, 2013 4:21 pm
Reply with quote

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

Active User


Joined: 18 Oct 2008
Posts: 380
Location: India

PostPosted: Tue Dec 24, 2013 6:30 pm
Reply with quote

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

New User


Joined: 06 Feb 2014
Posts: 7
Location: India

PostPosted: Thu Mar 07, 2024 9:12 pm
Reply with quote

ibmmainframes.com/viewtopic.php?t=69425&highlight=
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 -> JCL & VSAM

 


Similar Topics
Topic Forum Replies
No new posts Copy only TEXT or String from a record SYNCSORT 4
No new posts REXX/CMS How to place command console... CLIST & REXX 4
No new posts ICETOOL to SUM String DFSORT/ICETOOL 1
No new posts Reroute print output via REXX/SDSF TSO/ISPF 6
No new posts Mark Previous & next lines when a... DFSORT/ICETOOL 9
Search our Forums:

Back to Top