Loop in Transformer

Post questions here relative to DataStage Enterprise/PX Edition for such areas as Parallel job design, Parallel datasets, BuildOps, Wrappers, etc.

Moderators: chulett, rschirm, roy

Post Reply
him121
Premium Member
Premium Member
Posts: 55
Joined: Sat Aug 07, 2004 1:50 am

Loop in Transformer

Post 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
rasi
Participant
Posts: 464
Joined: Fri Oct 25, 2002 1:33 am
Location: Australia, Sydney

Post by rasi »

Hi Him

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

Listening to the Learned

"The most precious wealth is the wealth acquired by the ear Indeed, of all wealth that wealth is the crown." - Thirukural By Thiruvalluvar
rasi
Participant
Posts: 464
Joined: Fri Oct 25, 2002 1:33 am
Location: Australia, Sydney

Post 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
Regards
Siva

Listening to the Learned

"The most precious wealth is the wealth acquired by the ear Indeed, of all wealth that wealth is the crown." - Thirukural By Thiruvalluvar
kwwilliams
Participant
Posts: 437
Joined: Fri Oct 21, 2005 10:00 pm

Re: Loop in Transformer

Post by kwwilliams »

Is this for a PX or Server job?
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post 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?
-craig

"You can never have too many knives" -- Logan Nine Fingers
kwwilliams
Participant
Posts: 437
Joined: Fri Oct 21, 2005 10:00 pm

Post by kwwilliams »

His profile says server and the forum is PX, just want to make sure what the real basis of this requirement.
kumar_s
Charter Member
Charter Member
Posts: 5245
Joined: Thu Jun 16, 2005 11:00 pm

Post 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?
Impossible doesn't mean 'it is not possible' actually means... 'NOBODY HAS DONE IT SO FAR'
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post 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:
-craig

"You can never have too many knives" -- Logan Nine Fingers
reachthiru
Participant
Posts: 28
Joined: Mon Jan 09, 2006 1:31 pm

Post 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.
With regards,
Thiru
kumar_s
Charter Member
Charter Member
Posts: 5245
Joined: Thu Jun 16, 2005 11:00 pm

Post 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?
Impossible doesn't mean 'it is not possible' actually means... 'NOBODY HAS DONE IT SO FAR'
reachthiru
Participant
Posts: 28
Joined: Mon Jan 09, 2006 1:31 pm

Post 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.
With regards,
Thiru
Mallayagari
Participant
Posts: 15
Joined: Tue Apr 20, 2004 3:10 am

Re: Loop in Transformer

Post 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
DSguru2B
Charter Member
Charter Member
Posts: 6854
Joined: Wed Feb 09, 2005 3:44 pm
Location: Houston, TX

Post 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.
Creativity is allowing yourself to make mistakes. Art is knowing which ones to keep.
Post Reply