Page 1 of 1

Merging rows into a string

Posted: Wed Nov 03, 2004 10:02 pm
by sim
I have data in a sequential file. My data look like this:

25UB|23435
25XZ|89435
25MB|46377
25MD|38204
25YN|32048

I want to convert this data to:
25UB|23435|25XZ|89435|25MB|46377|25MD|38204|25YN|32048

Thanks

Posted: Wed Nov 03, 2004 10:24 pm
by vigneshra
You can achieve this very easily using stage variables. Keep accumulating the rows into a string without passing them onto the target and after the all the rows are appended pass the string at a stretch to the target.

Re: Merging rows into a string

Posted: Thu Nov 04, 2004 11:59 am
by Someswar Barkataki
Vigneshra,

Could you please explain how to know that job has reached the last row of the input file and how to pass only the last appended row?

I had faced the similar problem, and I solved it creating a new column appending each row values using a stage variable as Vigneshra mentioned. This gives me concatanated row values at the last row of my new column. However, I donot know how to determine the end of the input file to pass only the last row. That's why I passed all the rows and created a sequential file. Then I created a hash file taking the sequential file as input just to get the last row.

I feel my design is not the best one but still it works.
Thanks,
Somesh

Posted: Thu Nov 04, 2004 2:06 pm
by sim
I did like this:
I declared two stage variables...mergedRow, i, and totalRecCount
mergedRow = If @INROWNUM = i Then InputLink.col1 else mergedRow: InputLink.col1
i = i+1 (i has initial value 0)

Now, in the output link from the transformer, I put a constraint @INROWNUM = totalRecCount

I am getting totalRecCount through Aggregator, Merge to the transformer.

This output only the last fully merged record with out having to store the data in a file.