Skip to Content

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

MAPPING: Increment counter while creating destination structures

Hello,

i have the following source and destination structure:

<src_struct> (0-n)

<qualifier>

<value>

</src_struct>

<dest_struct> (0-n)

<counter>

<qualifier>

<value>

</src_struct>

only those dest structures have to be created where <qualifier="XX">.

Thus my mapping on structure level looks like:

if <qualifier> equalS "XX" createIf --> <dest_struct>

This works fine.

But additionally i need to increment <counter> in the dest_struct. I.e., when i have 10 src_struct where 5 of them has <qualifier="XX"> i need 5 dest_struct with counter 1 to 5.

I tried this with a UDF which has just a constant as input:

"MY_COUNTER" --> UDF:getNextCounter --> <counter>

This argument is the name under which the last counter was saved in the global container. My expectation was that for each time the field <counter> will be created, my UDF reads the las counter, increments it, saves it back to the container and returns the result.

but the bahavior is different:

For example:

if src_structures 6-10 have <qualifier>="XX" my UFD returns 6-10 in sequnce instead

of 1-5. The shows me, that my UDF runs 10 times even though just 5 dest_struct are created.

What do i wrong?

Her my UDF:

GlobalContainer gc = container.getGlobalContainer();

String counter = new String();

counter = (String) gc.getParameter(MY_COUNTER);

if(counter==null) {

counter = "1";

gc.setParameter(MY_COUNTER,counter);

return(counter);

}

Integer i_counter = new Integer(counter);

int i = i_counter.intValue() + 1;

Integer I = new Integer(i);

counter = I.toString();

gc.setParameter(ID_TYPE,counter);

return(counter);

Former Member
Former Member replied

Hi

Check the condition on qualifier

i.e. if <qualifier> == "XX"

then only increment the counter

this should work

regards

Sheetal

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