Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

substring

Former Member
0 Likes
955

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

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
929

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

7 REPLIES 7
Read only

Former Member
0 Likes
929

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.

Read only

Former Member
0 Likes
929

pass this to a variable say A

then B = A+8(5).

Read only

Former Member
0 Likes
930

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

Read only

Former Member
0 Likes
929

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

Read only

Former Member
0 Likes
929

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.

Read only

Former Member
0 Likes
929

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.

Read only

Former Member
0 Likes
929

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.