Skip to Content
0

UDF in HCI

Apr 26, 2017 at 04:36 PM

659

avatar image

Dear Experts,

What is the counterpart of 'result.addValue(value)' of PI UDF in HCI UDF?

i.e. There is a UDF in PI that dynamically maps the values of Source field var1 to a 0..unbounded target field. The same UDF needs to be converted into custom function in HCI.

i.e. var1 = "Apple,Mango,Orange"

String[] list = var1[0].split(",");

if (list.length > 0){
for (int j = 0; j < list.length; j++){
result.addValue(list[j]);
}
}

Appreciate your inputs. Thank you.

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

3 Answers

Best Answer
Sriprasad Shivaram Bhat May 03, 2017 at 09:34 AM
1

Hello Mark,

I am not sure in which step you are facing issues.I have tried its working fine without any issues .Refer the below.

Integration Flow:

Input Message:

<Root>    
    <Data>Apple,Mango,Orange</Data>
</Root>

Custom Function:

import com.sap.it.api.mapping.*
def void extParam(String[] P1, Output output, MappingContext context) 
{
    String[] list = P1[0].split(",");
    if (list.length > 0)
    {
        for (int j = 0; j < list.length; j++)
        {
         output.addValue(list[j]);
        }
    }
}

Output Message:

<?xml version="1.0" encoding="UTF-8"?>
<Items>
    <Fruit>Apple</Fruit>
    <Fruit>Mango</Fruit>
    <Fruit>Orange</Fruit>
</Items>

Regards,

Sriprasad Shivaram Bhat


Show 1 Share
10 |10000 characters needed characters left characters exceeded

Thanks Sriprasad!

0
Sriprasad Shivaram Bhat Apr 27, 2017 at 10:28 AM
1

Hello Mark ,

Create a Custom Function [ Ex: Custom_Function.gsh ] with below code and use it in your mapping it will work.

import com.sap.it.api.mapping.*

def void extParam(String[] P1, Output output, MappingContext context) {

    String[] list = P1[0].split(",");

    if (list.length > 0)
    {
        for (int j = 0; j < list.length; j++)
        {
         output.addValue(list[j]);
        }
    }
}

Hope this time I have interpreted your query correctly :).

Regards,

Sriprasad Shivaram Bhat

Show 1 Share
10 |10000 characters needed characters left characters exceeded

Thanks Sriprasad. I tried but it didn't work :(

0
Sriprasad Shivaram Bhat Apr 26, 2017 at 05:23 PM
0

Hello Mark,

If I have understood your requirement correctly counterpart is same[ addValue() works in SAP HCI too ).Below might help you with example of getting List of values and storing them in result list.

import com.sap.it.api.mapping.*
def void extParam(String[] P1, Output output, MappingContext context) {
    String op_str="";
    int p1Len=P1.length;
    for( int i=0;i<p1Len;i++)
    {
      op_str=op_str+P1[i];
      if (i != (p1Len-1))
        op_str=op_str+",";
    } 
    output.addValue(op_str);
}

Here is the link to Java Doc for Mapping step which might help you to understand the functionality better.

JAVA DOC SAP HCI

Regards,

Sriprasad Shivaram Bhat

Show 5 Share
10 |10000 characters needed characters left characters exceeded

Thanks Sriprasad! So it's possible to use .java for custom functions in message mapping? I thought it's only limited to groovy

0

Yes Mark its possible.

Regards,

Sriprasad Shivaram Bhat

0
Sriprasad Shivaram Bhat

Hi Sriprasad,

I'm getting invalid file extension when trying to create a .java Custom Function. How do you create such script?

script.

invalid.png (22.8 kB)
0

Hello Mark,

In your earlier question I missed .(mis interpret with whether we can use Java functions or not).

Very sorry for that,you can't use .Java extension to custom functions it has to be . Groovy.

Regards,

Sriprasad Shivaram Bhat

0
Sriprasad Shivaram Bhat

Hi Sriprasad,

No worries. Are you aware of any similar function in Groovy?

So the sample scenario is, a source has a field that contains CSV

<Root>
	<Item>Apple,Mango,Orange</Item>
</Root>

And target has a field that depends on the cardinality of the source field value.

<Root>
	<Items>
		<Fruit>Apple</Fruit>
		<Fruit>Mango</Fruit>
		<Fruit>Orange</Fruit>
	</Items>
</Root>

This can be easily achieved by using UDF in PI. But we need to do the same in HCI and we're not sure how to achieve a similar UDF in HCI. I know it's possible to import a message mapping from ESR in PI and it comes together with the UDF. The UDF also works during runtime. However, there's no way to view or edit the UDF in HCI directly. It can be a workaround but it's not sustainable since you always need PI to maintain it.

Any ideas?

0