Page 1 of 1

Loop in Transformer

Posted: Tue Feb 21, 2006 10:18 pm
by him121
Hi All

I am trying to convert one seq file let say SRC.txt to TGT.txt.

SRC structure is

Name Age Count
AA 32 4
BB 21 2


TGT structure (No. of rows are depend upon the 'Count' Value)
Name Age

AA 32
AA 32
AA 32
AA 32
BB 21
BB 21

Can any one through some light how can i achieve this.
I dont want to write routine for this.

Thanks
Him

Posted: Tue Feb 21, 2006 10:27 pm
by rasi
Hi Him

Post in the right forum. You are posting server question in Enterprise Forum.

Posted: Tue Feb 21, 2006 10:32 pm
by rasi
Him

There is no direct stage in datastage to do this. You have to write basic code to read the sequential file and then use the loop to write to a new sequential file

I will be interested to see if there is any other simple way of doing this

Re: Loop in Transformer

Posted: Tue Feb 21, 2006 10:34 pm
by kwwilliams
Is this for a PX or Server job?

Posted: Tue Feb 21, 2006 11:20 pm
by chulett
It's marked as a Server job question, so...

Him - is there any chance you know what the max 'count' value is you might be working with?

Posted: Wed Feb 22, 2006 6:04 am
by kwwilliams
His profile says server and the forum is PX, just want to make sure what the real basis of this requirement.

Posted: Wed Feb 22, 2006 7:43 am
by kumar_s
chulett wrote:Him - is there any chance you know what the max 'count' value is you might be working with?
Is there any method available other than using fixed number of stage variable for each fields?

Posted: Wed Feb 22, 2006 8:03 am
by chulett
I wasn't thinking about stage variables for this. Was wondering if there is a known upper limit to the count then you could simply have that number of output links from the transformer and constrain the output based on the count such that each record went down the first n links. Then a Link Collector to gather them all up. Not pretty but... :wink:

Posted: Wed Feb 22, 2006 4:20 pm
by reachthiru
Hi,

As long as you are going to write the output to a sequential file it is very simple. Assume that your field delimiter is tab and record delimiter is new line. What you have to do is create a output stage with only one field and the field value will be

Code: Select all

fld = Str(link.Name:'\t':link.Age:'\n',link.Count)
In the output stage, you make sure that record delimter is blank. Otherwise there will be empty records also.

Posted: Wed Feb 22, 2006 5:03 pm
by kumar_s
reachthiru wrote:Hi,

As long as you are going to write the output to a sequential file it is very simple. Assume that your field delimiter is tab and record delimiter is new line. What you have to do is create a output stage with only one field and the field value will be

Code: Select all

fld = Str(link.Name:'\t':link.Age:'\n',link.Count)
In the output stage, you make sure that record delimter is blank. Otherwise there will be empty records also.
Hi Thiru,

Not sure what you trying to explain, Again this will create one record per input record and not the loop activity :?
Is that you trying to explain to addup four such stage variable?

Posted: Wed Feb 22, 2006 5:20 pm
by reachthiru
Hi Kumar,

Since I am adding a new line character, though we write 1 record, the output file will have 'Count' # of records for each record.

Re: Loop in Transformer

Posted: Wed Mar 01, 2006 11:42 am
by Mallayagari
Hi

In this case you need to use a buil-op (custom stage) to do this. If the data is small then you can go for a unix script but if the data is huge then build-op is the right option.

Thanks
Malla

Posted: Thu Mar 02, 2006 3:01 pm
by DSguru2B
The solution to this would be if you find a logic to reverse group the data. the data that you show is grouped by two fields.