----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8
********************************* Top of Data **********************************
10010 HDRREC 10002
10010 DDDDDDDDD D DDDD A00 3978 1965-01-01 PRES
10010 EEEEEEE E EEEEEEEE B01 3476 1973-10-10 MANAGER
10010 FFFFF F FFFF C01 4738 1975-04-05 MANAGER
10010 HDRREC 10003
10010 GGGGGGGGG G GGGG A00 3978 1965-01-01 PRES
10010 HHHHHHH H HHHHHHHH B01 3476 1973-10-10 MANAGER
10010 IIIII I IIII C01 4738 1975-04-05 MANAGER
10010 HDRREC 10001
10010 AAAAAAAAA A AAAA A00 3978 1965-01-01 PRES
10010 BBBBBBB B BBBB B01 3476 1973-10-10 MANAGER
10010 CCCCC C CCCC C01 4738 1975-04-05 MANAGER
******************************** Bottom of Data ********************************
All records will start with Department ID. First 5 bytes belong to Department ID. In above file it is 10010
File will have Header record followed by Detail records. Header record will be identified by checking string as 'HDRREC'.
Header record will also have Employee Id of 5 bytes starting from 18 byte. Above file has 3 Employee ID details: 10002, 10003 and 10001.
We need to SORTOUT as below which will also VB file with LRECL 84 bytes:
Code:
----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8
********************************* Top of Data **********************************
10010 HDRREC 10001
10010 AAAAAAAAA A AAAA A00 3978 1965-01-01 PRES
10010 BBBBBBB B BBBB B01 3476 1973-10-10 MANAGER
10010 CCCCC C CCCC C01 4738 1975-04-05 MANAGER
10010 HDRREC 10002
10010 DDDDDDDDD D DDDD A00 3978 1965-01-01 PRES
10010 EEEEEEE E EEEEEEEE B01 3476 1973-10-10 MANAGER
10010 FFFFF F FFFF C01 4738 1975-04-05 MANAGER
10010 HDRREC 10003
10010 GGGGGGGGG G GGGG A00 3978 1965-01-01 PRES
10010 HHHHHHH H HHHHHHHH B01 3476 1973-10-10 MANAGER
10010 IIIII I IIII C01 4738 1975-04-05 MANAGER
******************************** Bottom of Data ********************************
18,5 is the same on each record in a group, so no need to PUSH that. With OPTION EQUALS (or using EQUALS on the SORT statement), which preserves the input order of identical keys in the output data (by assigning a sequence number internally) you don't need the SEQ. Because you have extended your record at the "end", all your records on your output file are now 84 bytes long, no longer variable:
The BUILD on INIT just leaves some "space" to put the PUSHed Employee ID.
I think the order of your SORT is incorrect, you need your Department Id sorting first. This is a deficiency in your test data, which only had one department. I haven't made the change. Code is untested, so fix any typos. If all employees are in strict sequence across departments, the change would be unnecessary, but that seems unlikely.