cancel
Showing results for 
Search instead for 
Did you mean: 

Problem with Message-Mapping: Loop over Elements possible?

Former Member
0 Kudos

Hi all,

I want do create a Message-Mapping for an IDoc-to-File Scenario. In the Source Structure there are some Elements which can appear more than once (1..unbounded). I need a mechanism which loops over these elements and search for specified values. From the Element which contains an element with this specified value the mapping should write a value in the target structure.

Here a simple example (source structure) for better understanding:

<root>

<invoice>

<number> 10 </number>

<sum> 200.00 </sum>

</invoice>

<invoice>

<number> 20 </number>

<sum> 150.00 </sum>

</invoice>

<invoice>

<number> 30 </number>

<sum> 120.00 </sum>

</invoice>

</root>

Now the duty of the Mapping should be to search in the elements <invoice> for the number 30. And then the sum of the invoice with the number 30 should be written in a field of the target structure.

I tried it out with a constant togehter with an equalsS-function and an ifWithoutElse-function, but it is working only then, if the invoice with the number 30 has the first position in the root context.

Can anybody help me? Thanks

With kind regards

Christopher

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi,

Write a UDF to sum the required values and map to target node.

See while writing the UDF select the type as queue.

number -- removecontext-UDF targetnode

sum----removecontext--/

number abd sum or the two inputs

in UDF

int nsum = 0;

for(int i;i < number.length;i++){

if number(i).equals("30") then

nsum = nsum + valueOf(sum(i));

}

result.addValue(nsum); // convert the nsum into string

Regsrds

Chilla

Former Member
0 Kudos

Hi,

In above UDF

change the

nsum = nsum + valueOf(sum(i));

to

nsum = nsum + Double.parseDouble.sum(i);

Regards

Chilla

Former Member
0 Kudos

Hey guys

Thanks for your help ... it could solve the problem

Best regards

Christopher

Answers (2)

Answers (2)

Former Member
0 Kudos

hi Christopher,

i think u hv to use UDF.

Try this :

number->Remove Context>UDF-->outputField

sum----->Remove Context>UDF

UDF :

double cnt = 0;

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

{

if(a<b>[</b>i<b>]</b>.equals("30") )

{

cnt = cnt + Double.parseDouble(b<b>[</b>i<b>]</b>) ;

}

}

result.addValue(""+cnt);

Thanks,

Maheshwari.

Former Member
0 Kudos

Hi Christopher,

This is possible without UDF.

First use IF-Without else to filter your source structure for number 30. And then you can play with the entire structure with keeping proper context in mind.

Regards,

Shri

Former Member
0 Kudos

Hi,

thanks for your quick response,

I tried it with ifWithoutElse. I tried it in the following way:

I compare the number with the String "30" (Text-function "equalsS"). Then I do a ifWithoutElse-function with the input of the "equalsS-Output" and the sum. Then i write the result in the target-field.

What is wrong?

Thank you