‎2008 Apr 15 7:43 AM
dear Gurus
I have string "AA000PGS01901", i want to store last 5 characters of the string into a variable. Pls.help me in this.
regards
Prasad
‎2008 Apr 15 7:50 AM
Hi,
data: v_string(50), v_result(50),
v_len type i.
v_string = 'AA000PGS01901'.
v_len = strlen( v_string ).
if v_len ge 5.
v_len = v_len - 5.
v_result = v_string+v_len(5).
write:/ v_result.
endif.
Edited by: Velangini Showry Maria Kumar Bandanadham on Apr 15, 2008 8:54 AM
‎2008 Apr 15 7:48 AM
Hi,
code like below.
DATA:str type string value 'AA000PGS01901'.
data:sub_str(5),len(2) type n.
len = strlen( str ).
if len GE 5.
len = len - 5.
else.
len = 0.
endif.
sub_str = str+len.
write:/ sub_str.
rgds,
bharat.
‎2008 Apr 15 7:48 AM
‎2008 Apr 15 7:50 AM
Hi,
data: v_string(50), v_result(50),
v_len type i.
v_string = 'AA000PGS01901'.
v_len = strlen( v_string ).
if v_len ge 5.
v_len = v_len - 5.
v_result = v_string+v_len(5).
write:/ v_result.
endif.
Edited by: Velangini Showry Maria Kumar Bandanadham on Apr 15, 2008 8:54 AM
‎2008 Apr 15 7:51 AM
Hi Prasad,
You can get the string length by STRLEN(STRING).then subract 5 from the count and just take the last 5 characters.I wil give you the example.
i = strlen(str)
i1 = i - 5.
Var=str+i1(5).
try this.it should be helpful
Thanks,
Bala
‎2008 Apr 15 7:54 AM
Check this code.
DATA: l_string(10) TYPE c VALUE 'ABC01005',
l_len TYPE i,
l_count TYPE i VALUE -1.
l_len = STRLEN( l_string ).
l_count = l_len - 5.
l_value = l_string+l_count(5).
write: l_value.
‎2008 Apr 15 7:55 AM
Hi,
data: var1 type string.
parameters: s1(100) type c.
data: v1 type i.
data: v2 type i value 5.
data: v3 type i value 5.
v1 = strlen( s1 ).
v2 = v1 - v2.
var1 = s1+v2(v3).
write: var1.
‎2008 Apr 15 9:30 AM
Hi,
data: string1(10) type c.
data: string2(5) type c.
data strlength type n.
string1 = 'sampl10203'.
strlength = strlen( string1 ).
strlength = strlength - 5.
string2 = string1+strlength(5).
write: / string2.
I think it is useful for you.