cancel
Showing results for 
Search instead for 
Did you mean: 

How to add values in different context UDF required

Former Member
0 Kudos

Hi

my source structure looks like below, LinStatus occurs multiple times , so in this case i want to take the all values and add it and map to ID.how to achieve this

<Status>
      <LinStatus>1..unbounded
        <ID>

<Target>
    <ID>

Regards,

Ram

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi,

First of all map the output of ID field in source structure to removeContext node function to bring all the ID values in a single context.

Then map the output of removeContext to the UDF whose code is as below:

//This UDF takes a single String array input named instr[] and has a single ResultList item named result as output.

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

{

result.addValue ( instr [ j ] ); //please write j within third brackets, i have wriiten it but its not showing in my post

}

Map the output of this UDF to the ID field in the target structure. THAT'S IT .

I HAVE TESTED THE INTERFACE..IT WORKS FINE.

THANKS

BISWAJIT

Edited by: 007biswa on Feb 12, 2011 12:19 PM

Edited by: 007biswa on Feb 12, 2011 12:20 PM

Former Member
0 Kudos

ID Type is decimal, so this UDF will not work, any other clue or changes required in UDF?

Former Member
0 Kudos

Hi,

This UDF should work even if the input is decimal. It doesnot create any probelms. Else you can take an integer array as input and the rest of the code that i have written need not be changed at all. I have assumed that the ID in the target side has multiple(1..unbounded) occurrence under a single context unlike the source where there is context change for every value.

TRUST ME BUDDY, MY SOLUTION WILL WORK. I HAVE TESTED IT

THANKS

BISWAJIT

Former Member
0 Kudos

your UDF will not work for me ,

target side i am having only one ID occurance 1 to 1. i want to add all the values from contexts from source.

suppose in my source ID occured 4 times(1.5,2.5,3.5,4.5) then i want target id value as 12.

Regards,

Ram

Former Member
0 Kudos

Hi,

Initially I didnot understand your requirement as it was not clear. Now it is very easy as you have gave a test instance.

For your requirement, use the code below:

double sum=0;
for(int i=0;i<instr.length;i++)
{

sum=sum+Double.parseDouble(instr[ i ]);
}
result.addValue ( sum); 

please check the modified code now.

I HAVE TESTED THE CODE. IT WORKED FOR M

AND BEFORE THE UDF, USE THE removeContext NODE FUNCTION. IT IS MANDATORY HERE.

THNAKS

BISWAJIT

Edited by: 007biswa on Feb 12, 2011 4:02 PM

Edited by: 007biswa on Feb 12, 2011 4:06 PM

Edited by: Matt on Feb 14, 2011 6:55 AM

Former Member
0 Kudos

007biswa,

It's not good habit to write in upper case every time. Please read the "Rules-of -Engagement" on SDN and follow them.

Thanks!

Edited by: Sarvesh Singh on May 10, 2011 11:45 PM

Answers (1)

Answers (1)

Former Member
0 Kudos

I think this can be achieved without UDF as well... have you tried with standard "Sum" function, e.g.

ID --- RemoveContext --- Sum --- ID

baskar_gopalakrishnan2
Active Contributor
0 Kudos

I concur with Sarvesh. This logic will be helpful. If we cant do with standard function then go for UDF.

Former Member
0 Kudos

Yes. A simple Sum function helps. No need for writing UDF.