Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups 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: 47
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: 7315

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: 47
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: 47
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 Check if any Detail records and extra... V S Amarendra Reddy SYNCSORT 19 Mon May 08, 2017 8:54 pm
No new posts Adding big TEXT lines to each record ... bshkris SYNCSORT 4 Sat May 06, 2017 1:40 am
This topic is locked: you cannot edit posts or make replies. Merge two files and update Trailer re... Yashashri JCL & VSAM 1 Thu May 04, 2017 12:54 pm
No new posts Sort Large record length cmsmoon DFSORT/ICETOOL 14 Tue Apr 11, 2017 5:49 pm
No new posts Format record to remove Leading zeroes Learncoholic DFSORT/ICETOOL 14 Wed Apr 05, 2017 2:43 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us