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
 
Extract 1 record before and 1 record after match found

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

New User


Joined: 17 Feb 2007
Posts: 52
Location: USA

PostPosted: Sat Oct 29, 2011 1:00 am    Post subject: Extract 1 record before and 1 record after match found
Reply with quote

I have a file with FB 404 and if a condition is met I need to extract 1 record before and 1 record after that condition.

Example Input file has value TENT at 14th position. When this match is found I need to extract 1 record before and 1 record after.

Please let me know if this can be done using SORT.

INPUT:

Code:

=COLS> ----+----1----+----2----+----3----+----4----+----5----+----6----+----7-
****** ***************************** Top of Data *****************************
000001 P0666   1109011644S  ABCSAMPLEDEFANOTHERSAMPLE 999999999999999999999996
000002 P0666   1109011644S  ABCSAMPLEDEFANOTHERSAMPLE 999999999999999999999996
000003  0666  G     TENT S  ABCSAMPLEDEFANOTHERSAMPLE 999999999999999999999993
000004  0666  G     TENT S  ABCSAMPLEDEFANOTHERSAMPLE 888888888888888888888883
000005 P0666  W 1109011644  ABCSAMPLEDEFANOTHERSAMPLE 999999999999999999999993
000006 P0666  W 1109011644  ABCSAMPLEDEFANOTHERSAMPLE 999999999999999999999993
000007 P0666    1109011644TFABCSAMPLEDEFANOTHERSAMPLE 999999999999999999999952
000008 P0666   1109011644S  ABCSAMPLEDEFANOTHERSAMPLE KKKKKKKKKKKKKKKKKKKKKKK3
000009 P0666    1109011644  ABCSAMPLEDEFANOTHERSAMPLE IIIIIIIIIIIIIIIIIIIIII93
000010  0666  G     TENT S  ABCSAMPLEDEFANOTHERSAMPLE UUUUUUUUUUUUUUUUUUUUUU43
000011 P0666    1109011644TFABCSAMPLEDEFANOTHERSAMPLE PPPPPPPPPPPPPPPPPPPPPP92
000012 P0666    1109011644  ABCSAMPLEDEFANOTHERSAMPLE RRRRRRRRRRRRRRRRRRRRRRR3


OUTPUT:

Code:

=COLS> ----+----1----+----2----+----3----+----4----+----5----+----6----+----7-
****** ***************************** Top of Data *****************************
000001 P0666   1109011644S  ABCSAMPLEDEFANOTHERSAMPLE 999999999999999999999996
000002  0666  G     TENT S  ABCSAMPLEDEFANOTHERSAMPLE 999999999999999999999993
000003  0666  G     TENT S  ABCSAMPLEDEFANOTHERSAMPLE 888888888888888888888883
000004 P0666  W 1109011644  ABCSAMPLEDEFANOTHERSAMPLE 999999999999999999999993
000005 P0666    1109011644  ABCSAMPLEDEFANOTHERSAMPLE IIIIIIIIIIIIIIIIIIIIII93
000006  0666  G     TENT S  ABCSAMPLEDEFANOTHERSAMPLE UUUUUUUUUUUUUUUUUUUUUU43
000007 P0666    1109011644TFABCSAMPLEDEFANOTHERSAMPLE PPPPPPPPPPPPPPPPPPPPPP92


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

Bill Woodger

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7314

PostPosted: Sat Oct 29, 2011 2:41 am    Post subject: Reply to: Extract 1 record before and 1 record after match f
Reply with quote

In your example you have a TENT followed by a TENT. In the output you only have one record before the first TENT and one record after the second TENT.

Are you saying you want one before and after unless after/before is TENT as well? So if you had three TENTs consecutively, the output would be non-TENT, TENT, TENT, TENT, non-TENT?
Back to top
View user's profile Send private message
AJAYREDDY

New User


Joined: 17 Feb 2007
Posts: 52
Location: USA

PostPosted: Sat Oct 29, 2011 3:15 am    Post subject: Reply to: Extract 1 record before and 1 record after match f
Reply with quote

Quote:

Are you saying you want one before and after unless after/before is TENT as well? So if you had three TENTs consecutively, the output would be non-TENT, TENT, TENT, TENT, non-TENT?


Exactly. Sorry I should have given more details. I want to check these records (1 before TENT and 1 after TENT). One more thing. In the INPUT file there will not be more than 2 TENTS consecutively.
Back to top
View user's profile Send private message
sqlcode1

Active Member


Joined: 08 Apr 2010
Posts: 578
Location: USA

PostPosted: Wed Nov 02, 2011 12:21 am    Post subject:
Reply with quote

AJAYREDDY,
See if below helps...
Code:
//STEP0001 EXEC PGM=ICETOOL                                             
//TOOLMSG  DD  SYSOUT=*                                                 
//DFSMSG   DD  SYSOUT=*                                                 
//IN       DD  *                                                       
P0666   1109011644S  ABCSAMPLEDEFANOTHERSAMPLE 999999999999999999999996
P0666   1109011644S  ABCSAMPLEDEFANOTHERSAMPLE 999999999999999999999996
 0666  G     TENT S  ABCSAMPLEDEFANOTHERSAMPLE 999999999999999999999993
 0666  G     TENT S  ABCSAMPLEDEFANOTHERSAMPLE 888888888888888888888883
P0666  W 1109011644  ABCSAMPLEDEFANOTHERSAMPLE 999999999999999999999993
P0666  W 1109011644  ABCSAMPLEDEFANOTHERSAMPLE 999999999999999999999993
P0666    1109011644TFABCSAMPLEDEFANOTHERSAMPLE 999999999999999999999952
P0666   1109011644S  ABCSAMPLEDEFANOTHERSAMPLE KKKKKKKKKKKKKKKKKKKKKKK3
P0666    1109011644  ABCSAMPLEDEFANOTHERSAMPLE IIIIIIIIIIIIIIIIIIIIII93
 0666  G     TENT S  ABCSAMPLEDEFANOTHERSAMPLE UUUUUUUUUUUUUUUUUUUUUU43
P0666    1109011644TFABCSAMPLEDEFANOTHERSAMPLE PPPPPPPPPPPPPPPPPPPPPP92
P0666    1109011644  ABCSAMPLEDEFANOTHERSAMPLE RRRRRRRRRRRRRRRRRRRRRRR3
//OUT      DD  SYSOUT=*                                                 
//TOOLIN   DD  *                                                       
 SELECT FROM(IN) TO(OUT) ON(413,8,ZD) HIGHER(1) USING(CTL1)             
/*                                                                     
//CTL1CNTL DD  *                                                       
 INREC IFTHEN=(WHEN=INIT,OVERLAY=(405:8C'0')),                         
       IFTHEN=(WHEN=GROUP,RECORDS=2,BEGIN=(14,4,CH,EQ,C'TENT'),         
                          PUSH=(405:SEQ=8)),                           
       IFTHEN=(WHEN=GROUP,BEGIN=(405,8,ZD,EQ,0),                       
                             END=(405,8,ZD,EQ,2),PUSH=(413:ID=8))       
 OUTFIL FNAMES=OUT,BUILD=(1,404)                                       
/*                                                                     
//SYSOUT   DD  SYSOUT=*                                                 
//*                                                                     

OUTPUT
Code:
P0666   1109011644S  ABCSAMPLEDEFANOTHERSAMPLE 999999999999999999999996
 0666  G     TENT S  ABCSAMPLEDEFANOTHERSAMPLE 999999999999999999999993
 0666  G     TENT S  ABCSAMPLEDEFANOTHERSAMPLE 888888888888888888888883
P0666  W 1109011644  ABCSAMPLEDEFANOTHERSAMPLE 999999999999999999999993
P0666    1109011644  ABCSAMPLEDEFANOTHERSAMPLE IIIIIIIIIIIIIIIIIIIIII93
 0666  G     TENT S  ABCSAMPLEDEFANOTHERSAMPLE UUUUUUUUUUUUUUUUUUUUUU43
P0666    1109011644TFABCSAMPLEDEFANOTHERSAMPLE PPPPPPPPPPPPPPPPPPPPPP92

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

New User


Joined: 17 Feb 2007
Posts: 52
Location: USA

PostPosted: Wed Nov 02, 2011 6:52 pm    Post subject:
Reply with quote

sqlcode1 Thanks for the code. It worked. icon_biggrin.gif
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 How to Count a particular record in a... Mounika Nemani DFSORT/ICETOOL 5 Tue May 29, 2018 1:07 pm
No new posts TRAILER3 is creating blank record in ... kodeesm DFSORT/ICETOOL 3 Fri May 18, 2018 5:45 pm
No new posts VSAM file NOT Found error while proce... SumaReva CICS 5 Wed Apr 11, 2018 9:54 pm
No new posts VSAM - Accessing beyond record size Benchwarmer JCL & VSAM 6 Wed Apr 11, 2018 9:20 pm
No new posts Extract the records with a PD field's... sudhakar84 DFSORT/ICETOOL 11 Mon Apr 02, 2018 7:26 pm

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