|
View previous topic :: View next topic
|
| Author |
Message |
Parthasarathy
New User
Joined: 24 Feb 2006 Posts: 18 Location: Chennai
|
|
|
|
Hi All,
I have the following requirement and i tried to find a solution searching old posts in the forum but couldn't find one.
The requirement is i have a sequential file fixed length 40 bytes.
The file has multiple header records and under each header, multiple detail records. The output file should have header records as-is and detail records sorted on field2 and field3 should be summed up using field 2 as key. (After summing, the field4 in detail can be from any record of the key, there is no restriction)
Header record:
Field1: 1 byte, always have value 1 to say header.
Field2: 4 bytes, any value
Field3: 35 bytes any value
Detail record:
Field1: 1 byte, always have value 2 to say detail
Field2: 4byte, any value
Field3: 3 byte, any 3 digit number
field4: 32 byte any value
Sample data
10004headerrecord1
20001003AAA
20001002BBB
20002004CCC
20002003DDD
20002002EEE
20003001FFF
20003004GGG
10002headerrecord2
20001003AAA
20001004BBB
20002001CCC
20002003DDD
20002002EEE
20003005FFF
20003002GGG
10001headerrecord3
20001003AAA
20001004BBB
The Expected output is
10004headerrecord1
20001005AAA
20002009CCC
20003005FFF
10002headerrecord2
20001007AAA
20002006CCC
20003007FFF
10001headerrecord3
20001007AAA
Many thanks in advance. |
|
| Back to top |
|
 |
saiprasadh
Active User
Joined: 20 Sep 2006 Posts: 154 Location: US
|
|
|
|
Parthasarathy,
Please use below mentioned sort card.
| Code: |
SORT FIELDS=(41,5,ZD,A,1,1,ZD,A,2,4,ZD,A)
INREC IFTHEN=(WHEN=GROUP,BEGIN=(1,1,ZD,EQ,1),
PUSH=(41:ID=5))
SUM FIELDS=(6,3,ZD)
OUTREC FIELDS=(1,40)
|
Output:
| Code: |
10004HEADERRECORD1
20001005AAA
20002009CCC
20003005FFF
10002HEADERRECORD2
20001007AAA
20002006CCC
20003007FFF
10001HEADERRECORD3
20001007AAA |
|
|
| Back to top |
|
 |
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
| You'll have to make your mind up about Field 4. Does it matter (OPTION EQUALS, if you want the first record of a group of duplitcates to be the base)? Or not? |
|
| Back to top |
|
 |
Parthasarathy
New User
Joined: 24 Feb 2006 Posts: 18 Location: Chennai
|
|
|
|
Thanks a ton for the solution  |
|
| Back to top |
|
 |
|
|
 |
All times are GMT + 6 Hours |
|