cancel
Showing results for 
Search instead for 
Did you mean: 

user defined function

RaghuVamseedhar
Active Contributor
0 Kudos

Hi all, <br>

I need to wright an user defined function to add all the source fields to one target fields. All the fields are integer type. <br>

<u><b>source </b></u>----


<u><b>Target</b></u><br>

Salary_____1...1----


Owner____1...1<br>

payA______0...unbound----


sum______1...1<br>

payB______1...unbound<br>

payC______1...1<br><br><br>

Mapping is ( payApayBpayC ) -> ( user defined fun ) -> sum <br><br>

Please send me the code.<br>I think the Cache type -- Value will not work as the payA can increase at run time(0..unbound). Cache type should be Context or Queue( So that we can refer whole context).<br>I want to know whether this can possible with out user defined function.

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

See this UDF

int payAsum=0;

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

{

payAsum =payAsum+Integer.parseInt(payA<i>);

}

int payBsum=0;

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

{

payBsum =payBsum+Integer.parseInt(payB[j]);

}

result.addValue(payAsumpayBsumpayC+"");

This will be context level function with payA payB payC as input

Mudit

RaghuVamseedhar
Active Contributor
0 Kudos

Thank you very much. <br>

But the last payC"" is not working because that is string. ( If we add 2 and 1 the out put is 21). I have tryed parseInt but i am getting addValue(java.lang.String) in com.sap.aii.mappingtool.tf3.rt.ResultList cannot be applied to (int) result.addValue(payAsumpayBsum+payCsum);. I have tried using Integer.parseInt(payC[0]) and i got error. Please slove this one. <br> Is above issue can be sloved with out any user defined function?

Former Member
0 Kudos

int payAsum=0;

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

{

payAsum =payAsum+Integer.parseInt(payA);

}

int payBsum=0;

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

{

payBsum =payBsum+Integer.parseInt(payB[j]);

}

int payCsum=Integer.parseInt(payC[0]);

int total=payAsumpayBsumpayCsum;

result.addValue(total+"");

if the last part also dont work out try result.addValue((String)total);

Mudit

henrique_pinto
Active Contributor
0 Kudos

Do the sum in a line before:


int sum = payAsum + payBsum + payCsum;
result.addValue(sum+"");

or just use parenthesis:


result.addValue((payAsum + payBsum + payCsum)+"");

Regards,

Henrique.

Answers (1)

Answers (1)

prateek
Active Contributor
0 Kudos

This would help

Regards,

Prateek