INSERTING ROWS MULTIPLE TIMES

Post questions here relative to DataStage Server Edition for such areas as Server job design, DS Basic, Routines, Job Sequences, etc.

Moderators: chulett, rschirm, roy

Post Reply
Poornagirija
Participant
Posts: 65
Joined: Fri Nov 19, 2004 12:00 am

INSERTING ROWS MULTIPLE TIMES

Post by Poornagirija »

HI FOLKS, :D
We are working in DS7.5.1 on Unix.
We have requirement as below.
Example:source
Table A contains
a1 a2 a3
MQ2www deployed 3
MQ2xxx Inactive 2

where a1,a2,a3 are field names

TARGET:
We have to populate the target table as follows
If a3 = 3 then we have to insert the target table repeating that particular row 3 times
If a3 = 2 then we have to insert the target table repeating that particular row 2 times and so on

Target table is as follows:

TABLE B
a1 a2 a3
MQ2www deployed 3
MQ2www deployed 3
MQ2www deployed 3
MQ2xxx Inactive 2
MQ2xxx Inactive 2

IS there any functions available to implement the same in Datastage.(except writing and calling procedure)

Your inputs are valueable to us.

Many thanks in advance
With Regards,
Poornagirija.

"Don't limit your challenges - challenge your limits"
ArndW
Participant
Posts: 16318
Joined: Tue Nov 16, 2004 9:08 am
Location: Germany
Contact:

Post by ArndW »

How about using a transform stage with multiple outputs that have constraints on them so that your data is written multiple times depending on the value of field a3?
Poornagirija
Participant
Posts: 65
Joined: Fri Nov 19, 2004 12:00 am

Post by Poornagirija »

HI ArndW,
Thanks for your response.
Im perplexed :?

It will be great if you explain me in elaborate manner.
With Regards,
Poornagirija.

"Don't limit your challenges - challenge your limits"
ArndW
Participant
Posts: 16318
Joined: Tue Nov 16, 2004 9:08 am
Location: Germany
Contact:

Post by ArndW »

In you transform you have one input link and (let us assume just 3 maximum) 3 output links. In the constraint for the 2nd one, put "In.a3=>2" and output the row. In the constraint for the third one, put "In.a3=>3" and output the row. This way, if a3 = 3 then for each input row you will get 3 output rows. You will need to either use a link collector to merge these 3 streams into one for writing to a sequential file or make sure that all of your output links have some sort of a unique key if writing straight to the database.
sb_akarmarkar
Participant
Posts: 232
Joined: Fri Sep 30, 2005 4:52 am
Contact:

Post by sb_akarmarkar »

Create a routine which uses concatenation a1:a2:a3 :char(10):char(13) in loop for no of a3 and output of routine to flat file .... This will help you ..


Thanks,
Anupam
Poornagirija
Participant
Posts: 65
Joined: Fri Nov 19, 2004 12:00 am

Post by Poornagirija »

HI ArndW,
The a3 is not always going to have 3 or 2.its just an example.
It may contain any no.

Thanks

Hi Anupam,
Thanks for your solution,let me try and get back to you.
With Regards,
Poornagirija.

"Don't limit your challenges - challenge your limits"
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

For a little less... terse... example of the technique, check this FAQ posting on the same subject.
-craig

"You can never have too many knives" -- Logan Nine Fingers
ArndW
Participant
Posts: 16318
Joined: Tue Nov 16, 2004 9:08 am
Location: Germany
Contact:

Post by ArndW »

This thread is an exact repeat of one that happened last week. If you have a reasonable limit on the output links (say 30) then this method will work efficiently. The easy alternate is what Anupam has suggested, by using an algorithm to loop around creating multiple "lines" by inserting <cr><lf> into the string; this way you might just do one "write" in the job to the sequential file, but since you have added line breaks yourself you will get multiple "reads" off that one write. This is a very efficient method and you can save disk I/O by using a named pipe as your interim sequential file.
kumar_s
Charter Member
Charter Member
Posts: 5245
Joined: Thu Jun 16, 2005 11:00 pm

Post by kumar_s »

Another thought. Have a Table with the following values.

1
2
2
3
3
3
4
4
4
4....

to the maximum possible value of a3. (Which can be populated even at runtime by finding the max of a3 from TableA.)
Do a lookup to the Table A with a3 column. And get the Table A values.
Impossible doesn't mean 'it is not possible' actually means... 'NOBODY HAS DONE IT SO FAR'
Poornagirija
Participant
Posts: 65
Joined: Fri Nov 19, 2004 12:00 am

Post by Poornagirija »

HI :D ,
Thanks for all your support.
I tried Anupams routine and its working fine.

Thanks Anupam. :)
With Regards,
Poornagirija.

"Don't limit your challenges - challenge your limits"
Post Reply