Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

Problems with summing segments

Hi experts,

I have an idoc as source, and I would like to sum the value of a specific segment under a condition:

my idoc is as following:

IDOC

>E1EDP01 0..unbounded

>>E1EDP04 0..unbounded

>>>MSWK

>>>MSWB

for each segment of E1EDP04, if the value of MSWK is the same, then I have to map the sum of all MSWB for the same value of MSWK.

Do you know how to do that? do I have to do an UDF? if yes, how should I start since i'm new at xi and java?

for example, i can have:

IDOC

>E1EDP01

>>E1EDP04

>>>MSWK = code1

>>>MSWB = 5

>E1EDP01

>>E1EDP04

>>>MSWK = code1

>>>MSWB = 7.5

>E1EDP01

>>E1EDP04

>>>MSWK = code1

>>>MSWB = 5

>E1EDP01

>>E1EDP04

>>>MSWK = code2

>>>MSWB = 4

>E1EDP01

>>E1EDP04

>>>MSWK = code2

>>>MSWB = 4.5

then I have to map the sum of MSWB to 2 segments:

>tax

>>type = code1

>> value = 17.5

>tax

>>type = code2

>> value = 8.5

Thanks a lot,

best regards,

jamal

Former Member
Former Member replied

Here's my solution:

step 1: create a UDF called getUniqueValues (queue function)

public void getUniqueValues(String[] MSWK,ResultList result,Container container){
import java.lang.*;

HashSet uniqueSet = new HashSet();

for (int i = 0 ; i < MSWK.length; i++ ) {
                if (uniqueSet.add(MSWK<i>))
	result.addValue(MSWK<i>);
}
}

This function returns the unique codes. You'll need this to determine how many tax segments you need and to sum up the values.

step 2: create a UDF called addValues (queue function)

public void addValues(String[] uniqueCodes,String[] allCodes,String[] addVals,ResultList result,Container container){

double sum = 0;

for (int i = 0; i < uniqueCodes.length; i++) {
	for (int j = 0; j < allCodes.length; j++) {
		if (uniqueCodes<i>.equals(allCodes[j])) {
			sum = sum + Double.parseDouble(addVals[j]);
		}
	}
	result.addValue(""+sum);
	sum = 0;
}
}

This function adds the values for each unique code as and returns them in a single context.

Step 3: the mapping of the tax segment: [http://www.xs4all.nl/~iddor/tax.jpg]

Set the context of MSWK to the parent segment of EDP01, in this case that is MT_SDN

Step 4: map field type like this: [http://www.xs4all.nl/~iddor/type.jpg]

Step 5: map the value field: [http://www.xs4all.nl/~iddor/value.jpg]

Set the contexts to the parent segment of EDP01, in this case that is MT_SDN. Add a context change between each value and you're done.

0 View this answer in context
Not what you were looking for? View more on this topic or Ask a question