cancel
Showing results for 
Search instead for 
Did you mean: 

UDF for Replace first 4 char

Former Member
0 Kudos

Hi Friends,

Can anyone please provide me UDF for following Condition

my input is 123456 or 1234567.i need read first 4 char and replace it by sw..the output should be sw56 or sw567

Thanks in adv.

Reg,

dinesh

Edited by: Dineshbabu.M on Feb 18, 2011 2:20 PM

Accepted Solutions (0)

Answers (3)

Answers (3)

Former Member
0 Kudos

Hi Dinesh,

Is the length of the string is constant? If so then you can go ahead with the mapping as said. If the length varies then you need to write a UDF for it.

Thanks,

Former Member
0 Kudos

Hi Harren,

The input length is varies.

Thanks

Former Member
0 Kudos

Thank friends..i got it by UDF..

Former Member
0 Kudos

if its varied length then u can do it by function - replaceString - no need of UDF....

http://help.sap.com/saphelp_nw04/helpdata/en/1f/ea0fb12403844bbb6c4cbc8a00cda9/frameset.htm

chirag.

Former Member
0 Kudos

Hi Dinesh,

If the length of the input varies, then you need to write a UDF to fulfill your requirement.

Try with the below code:

a[0]= "c" + a[0].substring(4,a[0].length());
result.addValue(a[0]); 

Thanks,

Former Member
0 Kudos

Hi,

This simple UDF will do what you want:

The UDF takes a single String array as input, say s[ ] and it has a single ResultList item result as output.

The complete code is as follows:


 s[0]="sw"+s[0].substring(4,s[0].length());
 result.addValue(s[0]);

Pass the output of the UDF to the required target field. That's it.

HOPE IT HELPS YOU BUDDY!!!

THANKS

BISWAJIT

Edited by: 007biswa on Feb 18, 2011 7:04 PM

Former Member
0 Kudos

U can do it with graphical mapping itself

u can use substring function and remove the first four character then use concat function along with constant to append the sw value.

chirag