Loop Implementation

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
naren6876
Participant
Posts: 233
Joined: Mon Feb 07, 2005 7:19 pm

Loop Implementation

Post by naren6876 »

Hi All,

My requirement is as below......

First get a record from Table A and then get the record from Table B and do the runn_bal - rem_amt.

If runn_bal - rem_amt <> 0 then update the runn_bal with runn_bal - rem_amt an Table A , and get the second record from Table B and and do the math again...and again.until it reaches 0. When it reaches 0 stop the process of Table B and update the runn_bal=0 for the first record in Table A.

Then get the second record from Table A and get the third record from Table B and process.so on and so.......

Code: Select all


Note:
There is no relation between rcvbl_id and remtc id

Table A	
rcvbl_id ano	rcvbl_amt	runn_bal status
1          1	      254	254         0
2          1	      3089  3089        0
3          1	      2	  2           0

Table B	
remtc_id ano	rem_amt	status
1          1	    254	    0
2          1	    3089	   0
3          1	    3089	   0
4          1	    2	      0
5          1	    2	      0

the output should be

Table A	
rcvbl_id ano	rcvbl_amt	runn_bal status
1          1	      254	0         1
2          1	      3089  0         1
3          1	      2	  -3091     1
Please let me know how can i achieve this.

Thanks in advance.
anbu
Premium Member
Premium Member
Posts: 596
Joined: Sat Feb 18, 2006 2:25 am
Location: india

Post by anbu »

Are you updating Table A with runn_bal - rem_amt always?
You are the creator of your destiny - Swami Vivekananda
naren6876
Participant
Posts: 233
Joined: Mon Feb 07, 2005 7:19 pm

Post by naren6876 »

anbu wrote:Are you updating Table A with runn_bal - rem_amt always?
I should update it...Or we can hold it in a variable until it reaches 0 and then update it.
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Looks like you need to source a Cartesian product of A and B.

How is Status determined?
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
anbu
Premium Member
Premium Member
Posts: 596
Joined: Sat Feb 18, 2006 2:25 am
Location: india

Post by anbu »

naren6876 wrote:
anbu wrote:Are you updating Table A with runn_bal - rem_amt always?
I should update it...Or we can hold it in a variable until it reaches 0 and then update it.
Can you give better example for what do you mean by loop?
You are the creator of your destiny - Swami Vivekananda
naren6876
Participant
Posts: 233
Joined: Mon Feb 07, 2005 7:19 pm

Post by naren6876 »

ray.wurlod wrote:Looks like you need to source a Cartesian product of A and B.

How is Status determined? ...
Thanks Ray..


For Table A....as soon as it reaches 0.change the status to 1.....

For Table B.....as soon as you read the record change the status to 1..
naren6876
Participant
Posts: 233
Joined: Mon Feb 07, 2005 7:19 pm

Post by naren6876 »

anbu wrote:
naren6876 wrote:
anbu wrote:Are you updating Table A with runn_bal - rem_amt always?
I should update it...Or we can hold it in a variable until it reaches 0 and then update it.
Can you give better example for what do you mean by loop?
Hi anbu,

I don't know what to call it....so called it as loop.....

The reason being...first i need read the record from A.....and loop it thru B records until balance reaches to 0....so i called it as Loop..

Thanks in advance.
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

There's no looping within the Transformer stage until the next version.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
naren6876
Participant
Posts: 233
Joined: Mon Feb 07, 2005 7:19 pm

Post by naren6876 »

ray.wurlod wrote:There's no looping within the Transformer stage until the next version. ...
Hi All,

Thanks for your inputs.

Is there any other way to implement it (if not in DS)?

Thanks in advance.
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Yes, as I indicated earlier, a Cartesian product (cross join) in your extraction SQL. Stage variables to keep track of what's happening. And patience to await the result of processing a very large number of rows (every possible combination).
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
Gopinath
Participant
Posts: 52
Joined: Wed Apr 25, 2007 2:18 am
Location: Chennai

Re: Loop Implementation

Post by Gopinath »

naren6876 wrote:Hi All,

My requirement is as below......

First get a record from Table A and then get the record from Table B and do the runn_bal - rem_amt.

If runn_bal - rem_amt <> 0 then update the runn_bal with runn_bal - rem_amt an Table A , and get the second record from Table B and and do the math again...and again.until it reaches 0. When it reaches 0 stop the process of Table B and update the runn_bal=0 for the first record in Table A.

Then get the second record from Table A and get the third record from Table B and process.so on and so.......

Code: Select all


Note:
There is no relation between rcvbl_id and remtc id

Table A	
rcvbl_id ano	rcvbl_amt	runn_bal status
1          1	      254	254         0
2          1	      3089  3089        0
3          1	      2	  2           0

Table B	
remtc_id ano	rem_amt	status
1          1	    254	    0
2          1	    3089	   0
3          1	    3089	   0
4          1	    2	      0
5          1	    2	      0

the output should be

Table A	
rcvbl_id ano	rcvbl_amt	runn_bal status
1          1	      254	0         1
2          1	      3089  0         1
3          1	      2	  -3091     1
Please let me know how can i achieve this.

Thanks in advance.



Hi,


Please find my understanding below, correct me if iam wrong.


Table A
rcvbl_id ano rcvbl_amt runn_bal status
1 1 254 254 0
2 1 3089 3089 0
3 1 2 2 0

Table B
remtc_id ano rem_amt status
1 1 254 0
2 1 3089 0
3 1 3089 0
4 1 2 0
5 1 2 0


STEP 1
---------

1) Extract Table A
2) Create a surrogate key starts with 1 (SurroKeyA is going to be as similar as rcvl_id)
3) Load into a dataset, which holds 3 records like below

Output of Step1: Dataset1
---------------------------

rcvbl_id ano rcvbl_amt runn_bal status SurroKeyA
1 1 254 254 0 1
2 1 3089 3089 0 2
3 1 2 2 0 3


STEP 2
-------

1) Extract Table B
2) Create a surrogate key starts with 1 (SurroKeyB is going to be as similar as remtc_id)
3) Load into a dataset, which holds 5 records like below

Output of Step2: Dataset2
---------------------------

remtc_id ano rem_amt status SurroKeyB
1 1 254 0 1
2 1 3089 0 2
3 1 3089 0 3
4 1 2 0 4
5 1 2 0 5


STEP 3
------

1) Sort the records on SurrKey and Join DS1 and DS2 on surroKey.
2) Do the transformation (A-B) in TFM and update the column in Table A as 0, update the column in TableB as 1
3) Use the DS to load the table A and table B by dropping the unwanted columns.


Please reply back if aim something here.

Thanks
Gopinath
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Apart from the fact that it's a server job, you mean?
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
Kryt0n
Participant
Posts: 584
Joined: Wed Jun 22, 2005 7:28 pm

Re: Loop Implementation

Post by Kryt0n »

naren6876 wrote:Hi All,
If runn_bal - rem_amt <> 0 then update the runn_bal with runn_bal - rem_amt an Table A , and get the second record from Table B and and do the math again...and again.until it reaches 0. When it reaches 0 stop the process of Table B and update the runn_bal=0 for the first record in Table A.
What happens if the difference goes below zero?
What about summing up of Table B's column and then work out how many rows from Table A can fit in to the sum? The remainder can be plugged in to the last row
Post Reply