Converting one record to many
Posted: 17 Oct 2012 05:59
Hi,
I’m receiving a file multi-format (in the same file can exist records with different formats), in the file the first record will be the header (the 1st character will have the letter "H"), then an record with the costumer identification (the 1st character of registration with the letter "C"), registration relating to movements (in the 1st character of registration with the letter "X" followed by a registration with the letter "R") and finally a record identifying the end of file (the 1st character registration with the letter "T").
Here's an example
H201209110000011022E
C10001 000R000000000040000000006
X0003012100000000000102200000784L
R20120911110101ALFA123456789CTX
X0003012100000110222010209000784L
R20120911110403ALFA123456789CTBETA135798642CTZETA246897531CTY
T2012091111080000DFRFGT07609530000002030
In the case of the R-type registers, identifying the movements, the same record can have more than one movement (being the number of movements identified in column 14 to 16, "R20120911110403" being in this case referring to 03 movements) .
For these cases intended to turn that line into as many moves as the number of movements contained. for Example
R20120911110403 (1º movement) ALFA123456789CT (2º movement) BETA135798642CT (3º movement) ZETA246897531CT (can have more movents) Y (the last character refers the type of movements)
Intended to be transformed into
R20120911110403ALFA123456789CTY
R20120911110403BETA135798642CTY
R20120911110403ZETA246897531CTY
It should be noted that the last character refers to the type of movement (in the first record R-type is “X” an in the 2º R-Type the 3 movements have “Y” type) and is repeated for each movement processed.
The file should be convert to
H201209110000011022E
C10001 000R000000000040000000006
X0003012100000000000102200000784L
R20120911110101ALFA123456789CTX
X0003012100000110222010209000784L
R20120911110403ALFA123456789CTY
R20120911110403BETA135798642CTY
R20120911110403ZETA246897531CTY
T2012091111080000DFRFGT07609530000002030
Anyone have any idea how I can make this transformation?
I’m receiving a file multi-format (in the same file can exist records with different formats), in the file the first record will be the header (the 1st character will have the letter "H"), then an record with the costumer identification (the 1st character of registration with the letter "C"), registration relating to movements (in the 1st character of registration with the letter "X" followed by a registration with the letter "R") and finally a record identifying the end of file (the 1st character registration with the letter "T").
Here's an example
H201209110000011022E
C10001 000R000000000040000000006
X0003012100000000000102200000784L
R20120911110101ALFA123456789CTX
X0003012100000110222010209000784L
R20120911110403ALFA123456789CTBETA135798642CTZETA246897531CTY
T2012091111080000DFRFGT07609530000002030
In the case of the R-type registers, identifying the movements, the same record can have more than one movement (being the number of movements identified in column 14 to 16, "R20120911110403" being in this case referring to 03 movements) .
For these cases intended to turn that line into as many moves as the number of movements contained. for Example
R20120911110403 (1º movement) ALFA123456789CT (2º movement) BETA135798642CT (3º movement) ZETA246897531CT (can have more movents) Y (the last character refers the type of movements)
Intended to be transformed into
R20120911110403ALFA123456789CTY
R20120911110403BETA135798642CTY
R20120911110403ZETA246897531CTY
It should be noted that the last character refers to the type of movement (in the first record R-type is “X” an in the 2º R-Type the 3 movements have “Y” type) and is repeated for each movement processed.
The file should be convert to
H201209110000011022E
C10001 000R000000000040000000006
X0003012100000000000102200000784L
R20120911110101ALFA123456789CTX
X0003012100000110222010209000784L
R20120911110403ALFA123456789CTY
R20120911110403BETA135798642CTY
R20120911110403ZETA246897531CTY
T2012091111080000DFRFGT07609530000002030
Anyone have any idea how I can make this transformation?