cancel
Showing results for 
Search instead for 
Did you mean: 

UDF to collect the values in single context

Former Member
0 Kudos


Dear All,

I am planning to send collecting values from my row each columns and send to target structure with in single context separated by characters.

Could you suggest me how could I write UDF

For ex:

Thanks in Advance.

Sateesh

Accepted Solutions (1)

Accepted Solutions (1)

engswee
Active Contributor
0 Kudos

Sateesh

You can try the logic below with a UDF of Execution type "All Values of Queue", with a single input a


  StringBuilder sb = new StringBuilder();

  for (int i = 0; i < a.length; i++) {

   sb.append("||").append(a[i]);

  }

  sb.append("||");

  result.addValue(sb.toString());

Test results

You can adjust the logic accordingly if you need further tweaking.

Rgds

Eng Swee

Former Member
0 Kudos

Hi Eng,

Thanks for your help to solve my problem,

With this UDF I achieved the result what I was expect.

But at that same time I got to know the value of parameter should not pass more 4000 characters.if the value more than 4000 characters with last value of field, then it doesn't take last field value and create to next statement.

(or)

I need to this UDF upto 5 values collection then again new statement create with 5 values then again repeat upto end.

Do I get possible edit this UDF to achieve this result?

Thanks in Advance.

Best Regards,

Sateesh

engswee
Active Contributor
0 Kudos

Sateesh

Try with the following and adjust accordingly to your requirement.


  StringBuilder sb = new StringBuilder();

  for (int i = 0; i < a.length; i++) {

   sb.append("||").append(a[i]);

   if(((i+1) % 5) == 0) {

    sb.append("||");

    result.addValue(sb.toString());

    if(i != a.length) {

     result.addContextChange();

    }

    sb.setLength(0);

   }

  }

  if(sb.length()!=0) {

   sb.append("||");

   result.addValue(sb.toString());

  }

Rgds

Eng Swee

Former Member
0 Kudos

Hi Eng,


Thanks, yes the UDF gives results perfectly but problem here is ,the 6th value does not come into next statement.

Currently I am getting this result

Thanks
Sateesh


engswee
Active Contributor
0 Kudos

Sateesh

You need to also adjust the mapping as well for the target parent segment storedProcedureName.

Create another UDF of execution all values of queue with the following logic


  for (int i = 0; i < a.length; i++) {

   if((i % 5) == 0) {

    result.addValue("");

   }

  }

Your mapping logic should look like that - I've named the second UDF parent but you can choose whatever name you like.

After executing the entire mapping, it would look like that

If you want to, it is also possible to combine the two UDFs into a single one with two outputs, but I leave that to you if you desire so.

Rgds

Eng Swee

Answers (0)