cancel
Showing results for 
Search instead for 
Did you mean: 

split the string

vishnu_pallamreddy
Contributor
0 Kudos

Hi ,

I need to split the phone number string into country code and phone number

Source                    Target

+44|9742744480 = first field 44 second field = 9742744480

I tried to use sub string function it will get fail when +1|9742744480 or +142|9742744480  will come .

please suggest.

Regards,

Accepted Solutions (1)

Accepted Solutions (1)

Muniyappan
Active Contributor
0 Kudos

you have to use split.

you can try below snippet to get the data in udf.

String[] output = new String[3];

  output = input.split("[+|]");

output[1] and output[2] will have 44 and 9742744480 respectively.

vishnu_pallamreddy
Contributor
0 Kudos

Hi Muni,

Could you please elaborate more requirement is one input element and  2 out element will be there.

Regards,

Muniyappan
Active Contributor
0 Kudos

it will be something like below. you need to modify according your requirement. if you want it to be handled in single udf then you have to use result list to return.

Answers (3)

Answers (3)

former_member229310
Active Participant
0 Kudos

Hello Vishnu,

The country code in general can differ from 1 to 4 digits, so i suggest you to refer table T005K table in SAP for these details and apply some look up table or rfc call you can design with your feasibility.

Hope you have country in the payload to proceed in determining this details.

Cheers

Harsha

vishnu_pallamreddy
Contributor
0 Kudos

Hi Muni,

If I need Number with Multiple occurrence do I need to change the execution type and code.

String[] output =new String[3];

output= var1.split("[+|]");

return output[1];



String[] output =new String[3];

output= var1.split("[+|]");

return output[2];

Regards,

Muniyappan
Active Contributor
0 Kudos
 I need Number with Multiple occurrence

do you mean record occurrence? or field number1 occurrence?

if it is field yes you have to. for record not required as udf will execute per occurrence of record.

vishnu_pallamreddy
Contributor
0 Kudos

Hi Muni,

I have one source field coming under one segment which is coming multiple time and it will be split and go to 2 different field.

first field = +44|


second field = 9742744480

Regards

markangelo_dihiansan
Active Contributor
0 Kudos

Hi Vishnu,


If I need Number with Multiple occurrence do I need to change the execution type and code.

Yes, you need to change execution type and code. Use two ResultLists, below is a sample code:

Regards,

Mark

Muniyappan
Active Contributor
0 Kudos

please check if this is suitable.

UDF code:

for(int i = 0; i<var1.length;i++)

{

  String[]  output = var1[i].split("[+|]");

result1.addValue(output[1]);

result2.addValue(output[2]);

}

Former Member
0 Kudos

Hello Vishnu ,

1. How may different company codes you might be receiving?

Is that fixed? Based upon that you have to do mapping like IF-then(Sub String) or you can use UDF also.

But first you should be aware how many different kinds of country codes you will be receiving.

2. Another approach will be to tell your source system to send a constant digit county code like 3 digtis always for you to use Sub string.

For e.g. :

+142 = +142

+44 = +044

+1 = +001

Thanks.