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

Extract 1 record before and 1 record after match found


IBM Mainframe Forums -> DFSORT/ICETOOL
Post new topic   Reply to topic
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
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

Moderator Emeritus


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

PostPosted: Sat Oct 29, 2011 2:41 am
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
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: 577
Location: USA

PostPosted: Wed Nov 02, 2011 12:21 am
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
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 View Bookmarks
All times are GMT + 6 Hours
Forum Index -> DFSORT/ICETOOL

 


Similar Topics
Topic Forum Replies
No new posts Extract the file name from another fi... DFSORT/ICETOOL 6
No new posts How to split large record length file... DFSORT/ICETOOL 10
No new posts How I Found a Bug in a FORTRAN Compiler All Other Mainframe Topics 4
No new posts SFTP Issue - destination file record ... All Other Mainframe Topics 2
No new posts FINDREP - Only first record from give... DFSORT/ICETOOL 3
Search our Forums:

Back to Top