on 04-26-2017 5:36 PM
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.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
Regards,
Sriprasad Shivaram Bhat
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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?
User | Count |
---|---|
84 | |
23 | |
11 | |
9 | |
8 | |
5 | |
5 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.