cancel
Showing results for 
Search instead for 
Did you mean: 

Calculate values based on two context

praveen_vanga3
Participant
0 Kudos

Hi,

How calculate values from two different queues?

I would like to multiply values from two arrays.

below are my queues.

My values for target queue will be like below

output:

75* 3139.00 = 2354.25

25*3139.00 = 78475

0

0

Below udf is not working based on contextchangenode.

String Res="";

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

{

for ( int j=0; j<var2.length; j++ )

{

Res = var1[i] * var2[j];

result.addValue(Res);

}

}

Thanks

Praveen

Accepted Solutions (1)

Accepted Solutions (1)

former_member182412
Active Contributor
0 Kudos

Hi Praveen,

Use below UDF:

Execution Type: All values of context


public void sum(String[] var1, String[] var2, ResultList result, Container container) {

  for (String var : var1) {

  result.addValue(new BigDecimal(var).multiply(new BigDecimal(var2[0])));

  }

  }

Test:

Regards,

Praveen.

Answers (4)

Answers (4)

praveen_vanga3
Participant
0 Kudos

Hi Praveen,

Thank you very much, I am very glad because your answers are straight to the point.

I have a small doubt, If the first queue has null values then How will it behave?

Thanks

Praveen

former_member182412
Active Contributor
0 Kudos

Thanks Praveen for your appreciation, use mapWithDefault(with zero value) before UDF then output will be zero.

Regards,

Praveen.

Former Member
0 Kudos

Hi Praveen,

As I suggested, we can achieve it by using existing mapping function multiply.

Please find the below example which I captured in the screenshots.

1. both the field has same context.

2. Both have different context.

If you really face issue in context handling and unable to achieve your requirement by using standard mapping then go for UDF.

Hope this will be helpful.

Thanks

Sagarika

GauravKant
Contributor
0 Kudos

Hi Praveen,

can you provide structure ?

And Also let us know , if corresponding value is not available in any of the context then what will be output expected. 0(Zero)?

Regards,

Gaurav

Former Member
0 Kudos

Hi Praveen,

Whether the two context is from 2 different field if yes then you can use existing mapping function to handle it.


Please give some more details on the requirements.

Thanks

Sagarika