|
View previous topic :: View next topic
|
| Author |
Message |
rmd3003
New User
Joined: 03 Jul 2006 Posts: 55
|
|
|
|
Hello.
After trying GROUP, IFTEN and being completely lost I would like to ask members here if anybody has sample code that will do the following. Find specific header and write output for that header and details to output. In case below it's BMW only header and details that needed.
Input file:
| Code: |
2023-10-10 HEADER - AUDI
00000000000001 DETAIL
00000000000001 DETAIL
00000000000001 DETAIL
00000000000001 DETAIL
2023-10-10 HEADER - BMW
00000000000002 DETAIL
00000000000002 DETAIL
00000000000002 DETAIL
2023-10-10 HEADER - MERCEDES
00000000000003 DETAIL
00000000000003 DETAIL
00000000000003 DETAIL
00000000000003 DETAIL
00000000000003 DETAIL
|
Output file:
| Code: |
2023-10-10 HEADER - BMW
00000000000002 DETAIL
00000000000002 DETAIL
00000000000002 DETAIL
|
Thanks a lot in advance. |
|
| Back to top |
|
 |
Joerg.Findeisen
Senior Member

Joined: 15 Aug 2015 Posts: 1436 Location: Bamberg, Germany
|
|
|
|
| And the problem is to do so? |
|
| Back to top |
|
 |
sergeyken
Senior Member

Joined: 29 Apr 2008 Posts: 2276 Location: USA
|
|
|
|
| rmd3003 wrote: |
After trying GROUP, IFTEN and being completely lost |
Where is what you have tried so far? |
|
| Back to top |
|
 |
rmd3003
New User
Joined: 03 Jul 2006 Posts: 55
|
|
|
|
Well, problem is that I pick up everything after BMW header. So GROUP works but doesn;t stop processing.
| Code: |
//SYSIN DD *
OPTION COPY
INREC IFTHEN=(WHEN=GROUP,BEGIN=(21,8,CH,EQ,C'BMW '),
PUSH=(61:21,8))
OUTFIL INCLUDE=(61,8,CH,EQ,C'BMW '),
BUILD=(1,60)
|
Output looks like this:
| Code: |
2023-10-10 HEADER - BMW
00000000000002 DETAIL
00000000000002 DETAIL
00000000000002 DETAIL
2023-10-10 HEADER - MERCEDES
00000000000003 DETAIL
00000000000003 DETAIL
00000000000003 DETAIL
00000000000003 DETAIL
00000000000003 DETAIL |
Tried adding second IFTHEN '21,8,CH,NE,C'BMW ' but it produces nothing. |
|
| Back to top |
|
 |
sergeyken
Senior Member

Joined: 29 Apr 2008 Posts: 2276 Location: USA
|
|
|
|
| rmd3003 wrote: |
Well, problem is that I pick up everything after BMW header. So GROUP works but doesn;t stop processing.
| Code: |
//SYSIN DD *
OPTION COPY
INREC IFTHEN=(WHEN=GROUP,BEGIN=(21,8,CH,EQ,C'BMW '),
PUSH=(61:21,8))
OUTFIL INCLUDE=(61,8,CH,EQ,C'BMW '),
BUILD=(1,60)
|
Output looks like this:
| Code: |
2023-10-10 HEADER - BMW
00000000000002 DETAIL
00000000000002 DETAIL
00000000000002 DETAIL
2023-10-10 HEADER - MERCEDES
00000000000003 DETAIL
00000000000003 DETAIL
00000000000003 DETAIL
00000000000003 DETAIL
00000000000003 DETAIL |
Tried adding second IFTHEN '21,8,CH,NE,C'BMW ' but it produces nothing. |
You MUST specify the condition to END THE CURRENT GROUP. Otherwise the group once started continues to the very end of the dataset.
OR
You must specify the beginning of ANY GROUP, not only BMW. But for your OUTFIL you can select only BMW. |
|
| Back to top |
|
 |
Joerg.Findeisen
Senior Member

Joined: 15 Aug 2015 Posts: 1436 Location: Bamberg, Germany
|
|
|
|
As @sergeyken has pointed out, this basically is easy to solve.
| Code: |
OPTION COPY
INREC IFTHEN=(WHEN=GROUP,BEGIN=(1,4,FS,EQ,NUM),PUSH=(60:21,8))
OUTFIL INCLUDE=(60,8,CH,EQ,C'BMW')
END |
| Code: |
****** **************************** Datenanfang ***********************
000001 2023-10-10 HEADER - BMW BMW
000002 00000000000002 DETAIL BMW
000003 00000000000002 DETAIL BMW
000004 00000000000002 DETAIL BMW
****** **************************** Datenende ************************* |
|
|
| Back to top |
|
 |
sergeyken
Senior Member

Joined: 29 Apr 2008 Posts: 2276 Location: USA
|
|
|
|
| Joerg.Findeisen wrote: |
As @sergeyken has pointed out, this basically is easy to solve.
| Code: |
OPTION COPY
INREC IFTHEN=(WHEN=GROUP,BEGIN=(1,4,FS,EQ,NUM),PUSH=(60:21,8))
OUTFIL INCLUDE=(60,8,CH,EQ,C'BMW')
END |
| Code: |
****** **************************** Datenanfang ***********************
000001 2023-10-10 HEADER - BMW BMW
000002 00000000000002 DETAIL BMW
000003 00000000000002 DETAIL BMW
000004 00000000000002 DETAIL BMW
****** **************************** Datenende ************************* |
|
I suggest to better detect groups not by NUM value, but by C'HEADER' value. |
|
| Back to top |
|
 |
Joerg.Findeisen
Senior Member

Joined: 15 Aug 2015 Posts: 1436 Location: Bamberg, Germany
|
|
|
|
It was a quick hack at this time. It's 0325 am here  |
|
| Back to top |
|
 |
|
|
 |
All times are GMT + 6 Hours |
|