Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

Take values before comma

Hi folks

I need help in a context udf : pass arrays

Source field:

Array of values

Sun is bright,Moon shines

Ball is blue,table is brown

If we see there is a comma in source field and we pass an array of source values to a udf

In target i have 2 fields.

I want to extract the values from source before comma and map to the first target field

and the text after comma in the second target field.

Is it achievable in XI and I am not good in writing java udfs.

Help will be appreciated.

Thnx

Former Member
Former Member replied

Hi,

as you have two targets you will have two UDFs ( a is the parameter).

For the first string:

>int index = (a.indexOf(";") > a.indexOf(",")? a.indexOf(";") : a.indexOf(","));

>if (index > 0) {

>return a.substring(0, index);

>}

>return a;

For the second string:

>int index = (a.indexOf(";") > a.indexOf(",")? a.indexOf(";") : a.indexOf(","));

>if (index > 0) {

>return a.substring(index + 1, a.length());

>}

>return a;

You could also do it with one UDF if you pass another parameter b that you fill with a constant ( "1" in case of first target and "2" in case of second target).

The UDF looks then like this:

>int index = (a.indexOf(";") > a.indexOf(",")? a.indexOf(";") : a.indexOf(","));

>if (index > 0 && b.equals("1")) {

>return a.substring(0, index);

>}

>if (index > 0 && b.equals("2")) {

>return a.substring(index + 1, a.length());

>}

>return a;

Regards

Patrick

Edited by: Patrick Koehnen on Sep 25, 2008 10:45 AM

0 View this answer in context

Helpful Answer

by
Not what you were looking for? View more on this topic or Ask a question