|
View previous topic :: View next topic
|
| Author |
Message |
abby.qiong.zhang
New User
Joined: 07 Jun 2012 Posts: 26 Location: China
|
|
|
|
I would like to seek help for how to update count of group records into the trailer.
LRECL of my input file is 512, FB.
Here's my input looks like:
| Code: |
@xxxxxxxxx
Axxxxxxxxx
Bxxxxxxxxx
Cxxxxxxxxx
Dxxxxxxxxx
Exxxxxxxxx
Bxxxxxxxxx
Cxxxxxxxxx
Dxxxxxxxxx
Exxxxxxxxx
Bxxxxxxxxx
Cxxxxxxxxx
Dxxxxxxxxx
Exxxxxxxxx
#yyyyyyyyy
|
I would like to add the counts of B or C or D or E “3” into the trailer. They have the same count.
| Code: |
@xxxxxxxxx
Axxxxxxxxx
Bxxxxxxxxx
Cxxxxxxxxx
Dxxxxxxxxx
Exxxxxxxxx
Bxxxxxxxxx
Cxxxxxxxxx
Dxxxxxxxxx
Exxxxxxxxx
Bxxxxxxxxx
Cxxxxxxxxx
Dxxxxxxxxx
Exxxxxxxxx
#yyyyyyyyy00000003
|
I know we can use the IFTRAIL statement to count all detail records and update to the trailer, if use this, i will have 13 in the trailer.
| Code: |
IFTRAIL=(HD=YES,TRLID=(1,1,CH,EQ,C'#'),
TRLUPD=(13:COUNT=(M11,LENGTH=8)))
|
Anyone can help? Much appreciated~ |
|
| Back to top |
|
 |
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
If you want a count of groups, and groups start with a B, identify the group in the usual way (BEGIN looks for B) and PUSH ID. ID is a sequence number at group level. First group is one, second is two, third is... you get the picture already.
Then you have something for your IFTRAIL (or a simple IFTHEN) to identify the trailer record, put in the extended ID and it should be about there. Cut the record back down to size, dropping off the now unwanted extra bytes. |
|
| Back to top |
|
 |
abby.qiong.zhang
New User
Joined: 07 Jun 2012 Posts: 26 Location: China
|
|
|
|
| Bill Woodger wrote: |
If you want a count of groups, and groups start with a B, identify the group in the usual way (BEGIN looks for B) and PUSH ID. ID is a sequence number at group level. First group is one, second is two, third is... you get the picture already.
Then you have something for your IFTRAIL (or a simple IFTHEN) to identify the trailer record, put in the extended ID and it should be about there. Cut the record back down to size, dropping off the now unwanted extra bytes. |
Hi Bill,
Yes, I know the WHEN=GROUP and PUSH function, how to put the extended ID into the IFTRAIL to only display the count of groups?
I tried with the below code, it returns the count 12 which is all records of BCDE.
| Code: |
OPTION COPY
INREC IFTHEN=(WHEN=GROUP,
BEGIN=(1,1,CH,EQ,C'B'),PUSH=(513:ID=8))
OUTFIL BUILD=(1,512),
IFTRAIL=(HD=YES,TRLID=(1,1,CH,EQ,C'#'),
TRLUPD=(13:COUNT-1=(M11,LENGTH=8)))
|
|
|
| Back to top |
|
 |
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
OK, it is a little clearer. You mentioned the other record-tyes and TRLUPD, so I thought there may be a need already to use it.
If all you want on the trailer is a count of the groups, this is a count of the B records.
You can use the GROUP, ID and a simple IFTHEN to identify your trailer, and re-arrange the ID to where you want it.
Or you can extend a single-byte field, which is zero for non-B records (including header) and one for B records, then use TOTAL/TOT on TRLUPD. |
|
| Back to top |
|
 |
abby.qiong.zhang
New User
Joined: 07 Jun 2012 Posts: 26 Location: China
|
|
|
|
| Bill Woodger wrote: |
OK, it is a little clearer. You mentioned the other record-tyes and TRLUPD, so I thought there may be a need already to use it.
If all you want on the trailer is a count of the groups, this is a count of the B records.
You can use the GROUP, ID and a simple IFTHEN to identify your trailer, and re-arrange the ID to where you want it.
Or you can extend a single-byte field, which is zero for non-B records (including header) and one for B records, then use TOTAL/TOT on TRLUPD. |
Hi Bill,
May I know how to re-arrange the ID? I used the below code and received syntax error.
| Code: |
OPTION COPY
INREC IFTHEN=(WHEN=GROUP,
BEGIN=(1,1,CH,EQ,C'B'),END=(1,1,CH,EQ,C'D'),
PUSH=(513:ID=8)),
IFTHEN=(WHEN=(1,1,CH,EQ,C'#'),OVERLAY=(13:ID))
OUTFIL BUILD=(1,512)
|
|
|
| Back to top |
|
 |
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
| Code: |
OPTION COPY
INREC IFOUTLEN=512,
IFTHEN=(WHEN=GROUP,
BEGIN=(1,1,CH,EQ,C'B'),END=(1,1,CH,EQ,C'D'),
PUSH=(513:ID=8)),
IFTHEN=(WHEN=(1,1,CH,EQ,C'#'),
OVERLAY=(13:513:8))
|
The ID is only valid on the PUSH. After the PUSH, the ID is in the position it has been PUSHed to.
Since the OUTFIL is not used for anything else, I've used IFOUTLEN to set the length of the record., so the BUILD is not needed to do that. Not tested, but should be close. |
|
| Back to top |
|
 |
abby.qiong.zhang
New User
Joined: 07 Jun 2012 Posts: 26 Location: China
|
|
|
|
| Bill Woodger wrote: |
| Code: |
OPTION COPY
INREC IFOUTLEN=512,
IFTHEN=(WHEN=GROUP,
BEGIN=(1,1,CH,EQ,C'B'),END=(1,1,CH,EQ,C'D'),
PUSH=(513:ID=8)),
IFTHEN=(WHEN=(1,1,CH,EQ,C'#'),
OVERLAY=(13:513:8))
|
The ID is only valid on the PUSH. After the PUSH, the ID is in the position it has been PUSHed to.
Since the OUTFIL is not used for anything else, I've used IFOUTLEN to set the length of the record., so the BUILD is not needed to do that. Not tested, but should be close. |
Hi Bill,
Here's the code works, within group only need to specify the B record otherwise no ID will be pushed in the trailer line. And you have a typo in the overlay statement, it's (13:513,8) instead of (13:513:8)
Many thanks for your help!
| Code: |
OPTION COPY
INREC IFOUTLEN=512,
IFTHEN=(WHEN=GROUP,
BEGIN=(1,1,CH,EQ,C'B'),
PUSH=(513:ID=8)),
IFTHEN=(WHEN=(1,1,CH,EQ,C'#'),OVERLAY=(13:513,8))
|
|
|
| Back to top |
|
 |
|
|
 |
All times are GMT + 6 Hours |
|