Skip to Content

UDF in HCI

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.

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

3 Answers

  • Best Answer
    May 03, 2017 at 09:34 AM

    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

    Add comment
    10|10000 characters needed characters exceeded

  • Apr 27, 2017 at 10:28 AM

    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

    Add comment
    10|10000 characters needed characters exceeded

  • Apr 26, 2017 at 05:23 PM

    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

    Add comment
    10|10000 characters needed characters exceeded

    • Mark Bernabe 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?