Skip to Content
avatar image
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")))

{

result.addValue(""+sum);

}

else {

result.addValue(BETRG<i>);

}

}

thanks,

Piyush

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

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

2 Answers

  • 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

    Add comment
    10|10000 characters needed characters exceeded

  • Apr 04, 2011 at 07:06 PM

    Hi,

    You don't need to find the index of the E1EDP01, just define your UDF as Context (alle values of Context) and make sure input values are set to context E1EDP01. Then only the E1EDP05-segments corresponding to the current E1EDP01-segment with their KSCHL and BETRG-fields will be available in the queue in your UDF.

    -Kenneth

    Add comment
    10|10000 characters needed characters exceeded