Application Development 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: 

Right Four Characters of a string

Former Member
0 Kudos

Hi,

I have a string '00001005001YINS' i want to select only 'YSAS' last four characters of this strion is it any method for this

Regards

Nausal

1 ACCEPTED SOLUTION

Former Member
0 Kudos

DATA: w_var TYPE string,
      w_len type i,
      w_char(4) type c.
 
w_var = '00001005001YINS' .

w_len = strlen( w_var ).
w_len = w_len - 4.
w_char = w_var+w_len(4).

Edited by: Swastik Bharati on May 18, 2009 11:21 AM

7 REPLIES 7

Sandeep_Kumar
Advisor
Advisor
0 Kudos

Find the string length and then use OFFSET .

Former Member
0 Kudos

DATA: w_var TYPE string,
      w_len type i,
      w_char(4) type c.
 
w_var = '00001005001YINS' .

w_len = strlen( w_var ).
w_len = w_len - 4.
w_char = w_var+w_len(4).

Edited by: Swastik Bharati on May 18, 2009 11:21 AM

vallamuthu_madheswaran2
Active Contributor
0 Kudos

Hi,

here right 4 chsr is 'yins' but u mentioned 'ysas'.

string1 = '00001005001YINS'.

string2 = string1+11(4).

or

u got the value from internal table

if string1 ca 'ysas'

.......

.......

.......

endif.

Thanks & Regards,

Vallamuthu.M

former_member302911
Active Participant
0 Kudos

DATA: CONT TYPE I.
DATA: STRING1 TYPE STRING VALUE '00001005001YINS'.
DATA: STRING2(4).

CONT = STRLEN( STRING1 ).
CONT = CONT - 4.
STRING2 = STRING1+CONT.
WRITE STRING2.

former_member222860
Active Contributor
0 Kudos

Check this:

data: v_str type string.
data: v_str1 type string,
      len type i,
      len1 type i.

v_str = '00001005001YINS'.

len = Strlen( v_str ).
len1 = len - 4.

v_str1 = v_str+len1(4).

write:/ v_str1.

Former Member
0 Kudos

Hi

You can use followign piece of code

data: lv_test type string value 'TEST_REPORT'.
data: lv_length type I.
data: lv_last type string.
data: lv_index type I.

lv_length = strlen( lv_test ).
lv_index = lv_length - 4.
lv_last = lv_test+lv_index .
write: lv_last.

here lv_last is last four chars 'PORT'.

Hope this helps.

Regards

Manas Dua

Former Member
0 Kudos

If your source field is a fixed length and using up all characters in the field (which your example looks to be), you can do the following which uses less code and no data declarations:

SHIFT f1 BY 4 PLACES RIGHT CIRCULAR.

MOVE f1+0(4) TO f2.

In the above example, f1 is the source field containing "00001005001YINS" in your example, and f2 is the target field.

Note that f1 has now changed, if this needs to be referenced later in your code you'll need to either refresh it with new data or first copy it if you care about altering its value.

Regards,

Brendan Farthing