Former Member

### UDF code for indx function (Statistics)

Hi All,

My query is based in an IDoc mapping.

Would appreciate your patience in going thr the below req:

I have a requirement where I have input and output structure as below:

E1EDP01 (0:n)

-

E1EDP05(0:n)

-

KSCHL

-

BETRG

Now I have to implement the below logic:

if KSCHL = ZRTP or ZIPP then BETRG = Sum of BETRG

For the above logic, I have to loop through KSCHL, store the sum of BETRG in local variable and then pass it to BETRG.

But the problem is that while looping thr KSCHL it loops for full queue (for all E1EDP01 rows). Due to this the GRNAD sum is calculated, which is not required.

To solve this I thought of passing the current index of E1EDP01 to my udf and then based on the index I would loop in KSCHL.

Now coming to my query :

How can I find the current index of an input Queue in an UDF.

This is achievable thr, index function but I want in the UDF.

please suggest a better solution, if my approach is incorrecr.

regards,

Piyush

FYI, I am pasting the UDF:

int i;

double sum=0, ret=0;

int flagSumMapped=0; //flag to check if sum has already been mapped to the target

for(i=0;i<KSCHL.length;i++)

{

if((KSCHL<i>.equals("ZRTP")) || (KSCHL<i>.equals("ZIPP")))

{

sum = sum + Double.parseDouble(BETRG<i>.trim());

}

}

for(i=0;i<KSCHL.length;i++)

{

if((KSCHL<i>.equals("ZRTP")) || (KSCHL<i>.equals("ZIPP")))

{

}

else {

}

}

thanks,

Piyush

Edited by: Piyush Mathur SAP on Mar 25, 2011 2:31 PM

10|10000 characters needed characters exceeded

• Mar 28, 2011 at 05:17 AM

Hello,

You could try to use this mapping:

```KSCHL -> equalsS -> Or -> ifWithoutElse -> removeContext -> sum -> BETRG
ZIPP -> /            /   BETRG -> /
KSCHL -> equalsS -> /
ZRTP -> /
```

The above code will add all the values of BETRG that have KSCHL values of ZIPP and ZRTP.

Hope this helps,

Mark