|
View previous topic :: View next topic
|
| Author |
Message |
AJAYREDDY
New User
Joined: 17 Feb 2007 Posts: 52 Location: USA
|
|
|
|
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 |
|
 |
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
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 |
|
 |
AJAYREDDY
New User
Joined: 17 Feb 2007 Posts: 52 Location: USA
|
|
|
|
| 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 |
|
 |
sqlcode1
Active Member
Joined: 08 Apr 2010 Posts: 577 Location: USA
|
|
|
|
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 |
|
 |
AJAYREDDY
New User
Joined: 17 Feb 2007 Posts: 52 Location: USA
|
|
|
|
sqlcode1 Thanks for the code. It worked.  |
|
| Back to top |
|
 |
|
|
 |
All times are GMT + 6 Hours |
|