Page 1 of 1

Header, detail Logic

Posted: Thu Sep 10, 2009 11:44 pm
by datskosaraju
Hi guys,

Need some logic help!
I have a file with header and detail in the same file format like this
  • 1 xyz 1234
    2 fgg 1234
    2 fgg 1234
    2 dfg 1234
    1 rfr 5678
    2 tgg 5678
    2 gtt 5678
    2 tty 5678
[/list]

we differentiate between header and detail by col 1 ( 1 for header, 2 for detail) and we can uniquely identify detail of every corresponding header by col3 ( i.e if col3 of detail match to that of a header then they belong to the header)

I need to generate o/p like this
  • 1 xyz 1234
    2 fgg 1234 1
    2 fgg 1234 2
    2 dfg 1234 3
    1 rfr 5678
    2 tgg 5678 1
    2 gtt 5678 2
    2 tty 5678 3
i.e the first detail under the header gets 1 and the next detail gets incremented by 1 and so on..... header is not required in the output (just wrote that for simplification).
Can anyone please tell me the logic for this.( Stage variables ?)

Posted: Fri Sep 11, 2009 1:40 am
by Grace J.
Sort the records based on col1 and col3 and generate keychange column. And then in next transformer use a stage variable stgvar. Reset the stage variable to 0 if keychange column is 1, else increment the stage variable. And then pass records only with key change column=0

Posted: Fri Sep 11, 2009 6:03 am
by chulett
Since it's already 'sorted' you can skip that step and just set a stage variable to zero when Col1=1 and increment it by one when Col1=2.

Posted: Fri Sep 11, 2009 9:31 am
by datskosaraju
Grace, criag thanks for the replies. The logic worked!!