Thank you Jean for your quick reply.
You are very useful on this issue, let me reconfirm the requirement so it is easy to understand and write the program as needed.
as you assumed the input file values are below: (
the file is fixed length)
all the P1 values are incremental.
1X.....................
1234567890123456111T0000300013XT1
1Z
01............no of P1's as
2 (
sub header 1)
P1
00001............ (it is 5 digit value for
subheader and not 01001)
Q1........
R1.................
P1
00002.........
Q1..................
R1......................
1Z
02............no of P1's as
5 (
sub header 2)
P1
00001..........
Q1.............
R1...........
S1.....
P1
00002..........
Q1.............
R1...........
S1.....
P1
00003..........
Q1.............
R1...........
S1.....
P1
00004..........
Q1.............
R1...........
S1.....
P1
00005..........
Q1.............
R1...........
S1.....
1Z
03............no of P1's as
6(
sub header 3)
P1
00001..........
Q1.............
R1...........
S1.....
P1
00002..........
Q1.............
R1...........
S1.....
P1
00003..........
Q1.............
R1...........
S1.....
P1
00004..........
Q1.............
R1...........
S1.....
P1
00005..........
Q1.............
R1...........
S1.....
P1
00006..........
Q1.............
R1...........
S1.....
4C.........
--------------Out puts should be like below-----------
If we think of doing split for every 5 P1's in to a seperate file then the out put should be like below:
File 1:
1X.....................
1234567890123456111T0000200005XT1
1Z
01............ (
sub header 1)
P1
00001........no of P1's as 2(it is 5 digit value for
subheader and not 01001)
Q1........
R1.................
P1
00002.........
Q1..................
R1......................
1Z
02............no of P1's as
3(
sub header 2)
P1
00001..........
Q1.............
R1...........
S1.....
P1
00002..........
Q1.............
R1...........
S1.....
P1
00003..........
Q1.............
R1...........
S1.....
4C.........
File 2:
1X.....................
1234567890123456112T0000200005XT1
1Z
01(2)............no of P1's as
2(
sub header 1(2) recounting again)
P1
00001(4).......... four should be recounted again
Q1.............
R1...........
S1.....
P1
00002(5)..........
Q1.............
R1...........
S1.....
1Z
02(3)............no of P1's as
3(
sub header 3)
P1
00001..........
Q1.............
R1...........
S1.....
P1
00002..........
Q1.............
R1...........
S1.....
P1
00003..........
Q1.............
R1...........
S1.....
4C.........
File 3:
1X.....................
1234567890123456113T0000100003XT1
1Z
01(3)............(
sub header 1(3))
P1
00001(4)..........
Q1.............
R1...........
S1.....
P1
00002(5)..........
Q1.............
R1...........
S1.....
P1
00003(6)..........
Q1.............
R1...........
S1.....
4C.........
I think the above example gives good idea how it looks like in the output files.
1) for every 5 P1's , there should be a new file which has header and trailer
2) For the 1Z records, the number starts counts again with 1 for next file, if the 1Z has more than 5 P1's even the rule is same.
3) The header should represent how many 1Z and P1's in it aslo needs to increment the last digit by one (or some thing to add one for the
19 digits) to make it unique for each out put files.
I really appreciate your help and support.
Happy New year
in advance and
Marry Christmas.
Chowhan