Page 1 of 1

Looping in Buildop

Posted: Wed Dec 14, 2005 9:36 am
by pjsimon
Hello,
I'm trying to write a buildop for the following requirement........I have an input stream which has 2 columns

ProdID
ProdName

and I also have a rules reference table which has

ColumnNumber
Trigger
Value

suppose the rules reference table has values
colNum , Trigger , Value
1 , 2345 , 4567
2 , Marlboro , Marl Lights

For each and every record in the input stream......

The ProdID should take 4567 if its equal to 2345
and ProdName should take Marl Lights if it is equal to Marlboro....

I put together the following code for the buildop.......

Code: Select all

#include <string.h>
#include <stdio.h>

APT_String V_ProdID;
APT_String V_ProdName;


readRecord(0);
readRecord(1);


while (!inputDone(0))

{

V_ProdID = S1.ProdID;
V_ProdName = S1.ProdName;

while (!inputDone(1))
 {

  if (L1.ColumnNumber==1)
   { 
   if (L1.Trigger==S1.ProdID)
     V_ProdID = L1.Value;   
   }

else if  (L1.ColumnNumber==2)
   {  
   if (L1.Trigger==S1.ProdName)
     V_ProdName = L1.Value;
   }

readRecord(1);

 }

Output.ProdID = V_ProdID;
Output.ProdName = V_ProdName;

transferAndWriteRecord(0);
readRecord(0);
readRecord(1);

}
endLoop();
Problem:

The logic works only for the first record.......cos the second while loop in the code executes only once.......Is there a way to make the second loop run for each and every input record??????........

we are using DS 7.5.1A...........I welcome suggestions for doing outside of the buildop too......

Appreciate the help...

Thanks
PJSimon.

Try the lookup stage

Posted: Wed Dec 14, 2005 10:44 am
by pneumalin
pjsimon,
This is perfect case to use lookup stage. Try it and let me know how it goes!

Posted: Wed Dec 14, 2005 11:41 am
by pjsimon
pneuma,
The key for the rules reference table is ColumnNumber and key for the input stream is virtual........which is the column number.......Can u plz give more info on how to go a'bt doing it???

Posted: Mon Jan 02, 2006 11:08 pm
by Rajesh_kr82
Did you get any soultion for this issue. I am also in the same problem.

Posted: Tue Jan 03, 2006 9:59 am
by pneumalin
pjsimon wrote:pneuma,
The key for the rules reference table is ColumnNumber and key for the input stream is virtual........which is the column number.......Can u plz give more info on how to go a'bt doing it???
pjsimon,
Did you get it resolved yet?
If I understand your requirement correctly, I would lookup the reference table Twice using the Key: Trigger instead of ColumnNumber for each single Input record. One for ProdID, and the other for ProdName...
You can then determine if the matches(ProdID<->Trigger, ProdName<->Trigger) found or not..

Hope this help!

Posted: Tue Jan 03, 2006 10:45 am
by Rajesh_kr82
Actually this is not about data or something. It is just that for each and every record in the primary source, i need to look up values in some other source. If you see in the code it is done in the secound while loop. But you cannot loop through the other dataset more then once. I am facing the same problem.

I tried to look at the code being generated and i found that the getRecord() method returns false each time. This is bacause cursor has reached the end of file. There should be some way to set this cursor back to record 1 and the parameter APT_Bop_inputDone[INPUT] to false. I got this stuff from the generated code.

rajesh

Re: Looping in Buildop

Posted: Tue Jan 03, 2006 9:54 pm
by benny.lbs
Does the reference table large ?????

If it is not large, try to use vector to build up an internal table (in Pre-Loop), then loop with vector.
pjsimon wrote:Hello,
I'm trying to write a buildop for the following requirement........I have an input stream which has 2 columns

ProdID
ProdName

and I also have a rules reference table which has

ColumnNumber
Trigger
Value

suppose the rules reference table has values
colNum , Trigger , Value
1 , 2345 , 4567
2 , Marlboro , Marl Lights

For each and every record in the input stream......

The ProdID should take 4567 if its equal to 2345
and ProdName should take Marl Lights if it is equal to Marlboro....

I put together the following code for the buildop.......

Code: Select all

#include <string.h>
#include <stdio.h>

APT_String V_ProdID;
APT_String V_ProdName;


readRecord(0);
readRecord(1);


while (!inputDone(0))

{

V_ProdID = S1.ProdID;
V_ProdName = S1.ProdName;

while (!inputDone(1))
 {

  if (L1.ColumnNumber==1)
   { 
   if (L1.Trigger==S1.ProdID)
     V_ProdID = L1.Value;   
   }

else if  (L1.ColumnNumber==2)
   {  
   if (L1.Trigger==S1.ProdName)
     V_ProdName = L1.Value;
   }

readRecord(1);

 }

Output.ProdID = V_ProdID;
Output.ProdName = V_ProdName;

transferAndWriteRecord(0);
readRecord(0);
readRecord(1);

}
endLoop();
Problem:

The logic works only for the first record.......cos the second while loop in the code executes only once.......Is there a way to make the second loop run for each and every input record??????........

we are using DS 7.5.1A...........I welcome suggestions for doing outside of the buildop too......

Appreciate the help...

Thanks
PJSimon.

Posted: Fri Jan 06, 2006 6:10 pm
by Rajesh_kr82
I talked to Ascential Support and was told that it is not possible to go through the secondry datasource again and again using the code. Hence this code will not work.

Posted: Thu Jul 05, 2007 2:29 am
by Abid
I have similar code from buildop:

struct gui_rec {
int win_id;
string app_name;
string exe;
string win_title;
string rule1;
string rule2;
int type;
} gui_array[5000];

int rcnt=0;
readRecord(1);
while (!inputDone(1))
{
gui_array[rcnt].win_id=InLkp.WINDW_ID;
gui_array[rcnt].app_name=InLkp.APP_NAME;
gui_array[rcnt].exe=InLkp.EXE;
gui_array[rcnt].win_title=InLkp.WINDW_TITLE_TEXT;
gui_array[rcnt].rule1=InLkp.RULE1;
gui_array[rcnt].rule2=InLkp.RULE2;
gui_array[rcnt++].type=InLkp.TYPE;
readRecord(1);

}

Here as well,I am facing the issue as input has 2463 records but when checked "rcnt" comes to 1231 only.That's half of actual value.

Posted: Thu Jul 05, 2007 5:55 am
by Abid
Done...its been solved...

As pjsimon wrote,
The logic works only for the first record.......cos the second while loop in the code executes only once.......Is there a way to make the second loop run for each and every input record??????........


In DS job,in BuildOp stage,change execution mode to "Sequential".
and it takes all the records as needed.

Posted: Thu Jul 05, 2007 9:42 am
by ray.wurlod
You could have pre-read input port #1 into a static vector, as was suggested; you can then access this as often as you wish. For better performance, use a hash table rather than a vector - a bit more coding, but probably worth it.