08-04-2010 12:45 AM
Hi,
I want a substring function in ABAP, which starts from right instead of left to display some character out of a complete string.
Suppose there is a variable zdatavar -
zdatavar = 'MyNameIsBush'.
zdatavar = zdatavar+4(2).
The above will start from the left.
I want some function which start from the right.
Your help will be greately appreciated.
Regards,
SC
08-04-2010 12:51 AM
Hi,
there is no standad ABAP command which supports this. You need to get length of string with STRLEN and then convert it proper index. Another solution could be to reverse string and then use standard syntax.
Cheers
08-04-2010 12:51 AM
Hi,
there is no standad ABAP command which supports this. You need to get length of string with STRLEN and then convert it proper index. Another solution could be to reverse string and then use standard syntax.
Cheers
08-04-2010 3:52 AM
Hi Sume,
please see code below. just reuse function rsubstring according to your needs.
REPORT ZTEST99.
DATA str TYPE STRING.
DATA str2 TYPE STRING.
str = 'MyNameIsBush'.
WRITE: / str.
PERFORM rsubstring
USING
str
4
2
CHANGING
str2
.
WRITE: / str2.
FORM rsubstring
USING
str TYPE STRING
offset
len
CHANGING
out TYPE STRING
.
DATA:
strln TYPE i,
l_offset TYPE i,
l_len TYPE i
.
strln = STRLEN( str ).
l_offset = strln - offset - len.
l_len = len.
out = str+l_offset(l_len).
ENDFORM.
08-04-2010 4:34 AM
Hi,
Please check if this is working.
REPORT Z0804.
DATA str TYPE STRING.
DATA str2 TYPE STRING.
str = 'MyNameIsBush'.
WRITE: / str.
PERFORM rsubstring
USING
str
2
CHANGING
str2
.
WRITE: / str2.
FORM rsubstring
USING
str TYPE STRING
len
CHANGING
out TYPE STRING
.
DATA:
strln TYPE i,
l_offset TYPE i,
l_len TYPE i
.
strln = STRLEN( str ).
if strln GE len.
l_offset = strln - len.
l_len = len.
out = str+l_offset(l_len).
endif.
ENDFORM.
result:
MyNameIsBush
sh
regards,
Xiang Li
08-04-2010 7:15 PM