Loop in DS (transformer)
Moderators: chulett, rschirm, roy
Loop in DS (transformer)
Hello
I have following situation:
I've 4 rows in table in my source DB
x , x
y , y
z , z
s , s
, and I want to put to my target table sth. like this:
x , x , 1
x , x , 2
x , x , 3
y , y , 1
y , y , 2
y , y , 3
..........
s , s , 1
s , s , 2
s , s , 3
How can I do a loop in transformer stage and is it possible??
regards
I have following situation:
I've 4 rows in table in my source DB
x , x
y , y
z , z
s , s
, and I want to put to my target table sth. like this:
x , x , 1
x , x , 2
x , x , 3
y , y , 1
y , y , 2
y , y , 3
..........
s , s , 1
s , s , 2
s , s , 3
How can I do a loop in transformer stage and is it possible??
regards
LUK
-
- Participant
- Posts: 3337
- Joined: Mon Jan 17, 2005 4:49 am
- Location: United Kingdom
-
- Participant
- Posts: 12
- Joined: Fri Apr 30, 2004 9:11 am
For this specific task, the three output stages is a good solution, probably the best.
Another alternative is to use the multi-row lookup. I went so far as to create a table called process_counter. It had one column that was a number and I populated it with 1 - 1000. If you set this up once, you can reuse it again and again. The multi-row lookup yields multiple output records per input record.
Another alternative is to use the multi-row lookup. I went so far as to create a table called process_counter. It had one column that was a number and I populated it with 1 - 1000. If you set this up once, you can reuse it again and again. The multi-row lookup yields multiple output records per input record.
-
- Charter Member
- Posts: 130
- Joined: Mon Sep 06, 2004 3:05 am
- Location: Dubai,UAE
Hey I have written a job control that can easily do this task.
OPENSEQ "/home/dsadm/Input.txt" TO INPUT1 THEN
Call DSLogInfo("File Input.txt Opened Successfully.","Generating a Different Sequence")
END
ELSE
ErrorCode = 1
Call DSLogInfo("Error in Openening Input.txt. Aborting the job.","Generating a Different Sequence")
ABORT
END
OPENSEQ "/home/dsadm/Output.txt" TO OUTPUT THEN
Call DSLogInfo("File Output.txt Opened Successfully.","Generating a Different Sequence")
END
ELSE
ErrorCode = 1
Call DSLogInfo("Error in Openening Output.txt. Aborting the job.","Generating a Different Sequence")
END
LOOP
READSEQ INPUT1.RECORD FROM INPUT1 THEN
Call DSLogInfo("File is Being Read","Generating a Different Sequence")
F1= FIELD(INPUT1.RECORD,'|',1)
F2= FIELD(INPUT1.RECORD,'|',2)
for i=1 to 3
row<1>=F1
row<2>=F2
row<3>=i
CONVERT @AM TO "|" IN row
WRITESEQ row TO OUTPUT THEN
**Call DSLogInfo("File is Being Written.","Generating a Different Sequence")
END
next i
END
ELSE
Call DSLogInfo("CANNOT READ FILE","Generating a Different Sequence")
EXIT
END
REPEAT
CLOSESEQ INPUT1
CLOSESEQ OUTPUT
Hope this helps
OPENSEQ "/home/dsadm/Input.txt" TO INPUT1 THEN
Call DSLogInfo("File Input.txt Opened Successfully.","Generating a Different Sequence")
END
ELSE
ErrorCode = 1
Call DSLogInfo("Error in Openening Input.txt. Aborting the job.","Generating a Different Sequence")
ABORT
END
OPENSEQ "/home/dsadm/Output.txt" TO OUTPUT THEN
Call DSLogInfo("File Output.txt Opened Successfully.","Generating a Different Sequence")
END
ELSE
ErrorCode = 1
Call DSLogInfo("Error in Openening Output.txt. Aborting the job.","Generating a Different Sequence")
END
LOOP
READSEQ INPUT1.RECORD FROM INPUT1 THEN
Call DSLogInfo("File is Being Read","Generating a Different Sequence")
F1= FIELD(INPUT1.RECORD,'|',1)
F2= FIELD(INPUT1.RECORD,'|',2)
for i=1 to 3
row<1>=F1
row<2>=F2
row<3>=i
CONVERT @AM TO "|" IN row
WRITESEQ row TO OUTPUT THEN
**Call DSLogInfo("File is Being Written.","Generating a Different Sequence")
END
next i
END
ELSE
Call DSLogInfo("CANNOT READ FILE","Generating a Different Sequence")
EXIT
END
REPEAT
CLOSESEQ INPUT1
CLOSESEQ OUTPUT
Hope this helps
Warm Regards,
Amruta Bandekar
<b>If A equals success, then the formula is: A = X + Y + Z, X is work. Y is play. Z is keep your mouth shut. </b>
--Albert Einstein
Amruta Bandekar
<b>If A equals success, then the formula is: A = X + Y + Z, X is work. Y is play. Z is keep your mouth shut. </b>
--Albert Einstein
-
- Participant
- Posts: 108
- Joined: Wed Jul 28, 2004 7:15 am
-
- Participant
- Posts: 108
- Joined: Wed Jul 28, 2004 7:15 am
Luk, you dont have to bother with complex solutions
here its simple and efficient one by using Pivot stage as suggested by amsh76
Field1 Field2
x x
y y
z z
s s
take this input in In pivot stage
use below derivatives for pivoting
Field1,Field1,Field2 at 1st column
this will generate out putlike this
x x
x x
x x
y y
y y
y y
z z
z z
z z
s s
s s
s s
now use tranformer to create third column
Declare Stage Variable IncrSTG
give condition if incrSTG=3 then 1 else incrSTG+1 against this variable in derivative.
Now drag it to output column as 3rd col.
you will find out like this as desired.
x x 1
x x 2
x x 3
y y 1
y y 2
y y 3
z z 1
z z 2
z z 3
s s 1
s s 2
s s 3
I hope this will hepl .
I dedicate this solution to Sunshine2323
Thanks
Prashant
here its simple and efficient one by using Pivot stage as suggested by amsh76
Field1 Field2
x x
y y
z z
s s
take this input in In pivot stage
use below derivatives for pivoting
Field1,Field1,Field2 at 1st column
this will generate out putlike this
x x
x x
x x
y y
y y
y y
z z
z z
z z
s s
s s
s s
now use tranformer to create third column
Declare Stage Variable IncrSTG
give condition if incrSTG=3 then 1 else incrSTG+1 against this variable in derivative.
Now drag it to output column as 3rd col.
you will find out like this as desired.
x x 1
x x 2
x x 3
y y 1
y y 2
y y 3
z z 1
z z 2
z z 3
s s 1
s s 2
s s 3
I hope this will hepl .
I dedicate this solution to Sunshine2323
Thanks
Prashant
-
- Participant
- Posts: 22
- Joined: Thu Jul 29, 2004 8:10 am
-
- Participant
- Posts: 108
- Joined: Wed Jul 28, 2004 7:15 am
-
- Participant
- Posts: 108
- Joined: Wed Jul 28, 2004 7:15 am