Four Stars

Check for alternate records in a file

Hai,
I have a positional file as follows
Header
G221ABCDEFGH100
G222XYZJHDJHK200
G221JHJHDSUEE300
G222HFGTYKJDK400
Trailer4
1. Here I need to check whether the total number of records (excluding Header and Trailer) is equal to that given in the Trailer
2. Check if the alternate records are G221 and G222 (G221 must be followed by a G222)
Here
1. First line is the header record
2. Second is a G221 record, name (ABCDEFGH) and balance amt (100)
3. Third is a G222 record, name (XYZJHDJHK) and balance amt (200)
4. Final line is the Trailer record which has the total number of G221 and G222 records in the file
Please help me, how I can achieve this.
Thanks and regards,
Amirths
6 REPLIES
Community Manager

Re: Check for alternate records in a file

Hello Amirths
1. Here I need to check whether the total number of records (excluding Header and Trailer) is equal to that given in the Trailer

1) Use tFileRowCount to count the total lines, eg: there are 6 lines in file, so we can get the total number of records are 4=6-2.
2) tFileInputFullRow---->tSampleRow-->tJavaRow
tFileInputFullRow: to read the whole line at a time
tSampleRow: set the range as "6" to read only the last line(trailer)
tJavaRow: parse this line and get the total number, eg: String totalNumber=row1.line.substring(7), then int line=Integer.parseInt(totalNumber), so now we can compare line with total number from step 1.
2. Check if the alternate records are G221 and G222 (G221 must be followed by a G222)

tFileInputFullRow(read the whole line at a time)---->tSampleRow (set range as "2..total number-1") to read only the detaild record excluding header and trailer, then check the lines on 1,3,5...if start with G221, check the lines on 2,4,6...if start with G222.
Best regards

shong
----------------------------------------------------------
Talend | Data Agility for Modern Business
Four Stars

Re: Check for alternate records in a file

Shong,
Thanks for the update.
But the problem is that, the number of lines of the input file may vary time to time. It is not a constant.
Can u please upload the images.
Thanks and Regards,
Amirths
Community Manager

Re: Check for alternate records in a file

Hello
But the problem is that, the number of lines of the input file may vary time to time. It is not a constant.

Yes, I know, so use the tFileRowCount to count the number of lines first.
Best regards

shong
----------------------------------------------------------
Talend | Data Agility for Modern Business
Four Stars

Re: Check for alternate records in a file

Hi Shong,
How can I specify the values "1,3,5....." in tSampleRow
(Read only the Odd line no's till end of file)
Is there any way to describe that.
Regards,
Amirths
Community Manager

Re: Check for alternate records in a file

Hello Amirths
I create a job to show you:
Check if the alternate records are G221 and G222 (G221 must be followed by a G222), if it satisfy this condition, the file is validate, otherwise it is not.
Input file:

Header
G221ABCDEFGH100
G222XYZJHDJHK200
G221JHJHDSUEE300
G222HFGTYKJDK400
G221JHJHDSUEE500
G222HFGTYKJDK600
Trailer6

Result:
Starting job forum6057 at 16:31 07/04/2009.
The total lines is: 8
The range expression in tSampleRow is: 2..7
.--+----------------.
| tLogRow_1 |
|=-+---------------=|
|id|line |
|=-+---------------=|
|1 |G221ABCDEFGH100 |
|2 |G222XYZJHDJHK200|
|3 |G221JHJHDSUEE300|
|4 |G222HFGTYKJDK400|
|5 |G221JHJHDSUEE500|
|6 |G222HFGTYKJDK600|
'--+----------------'
The file is validate?true
Job forum6057 ended at 16:31 07/04/2009.

Best regards

shong
----------------------------------------------------------
Talend | Data Agility for Modern Business
Four Stars

Re: Check for alternate records in a file

Thanks a lot SHONG........That is working fine.......
Regards,
Amirths