cancel
Showing results for 
Search instead for 
Did you mean: 

Need only the last 7 characters from string

Former Member
0 Kudos

Hi

I have some strings that i have to process and i only need the last 7 characters out of each one.The problem is that those strings have different length each time.Is there any offset function that can help me or how can i do this in the easy way.I would not want to count the length of the string each time to process it using offsets

thanks

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi,

Try this, hope it will solve ur problem .

x(3) type c.

strn = ''aaaa aaa aaa''

x = strlen( strn ) .

x = x - 7.

strn2 = strn+x(7).

Former Member
0 Kudos

Hi

First of all thanks for the fast response.

I have tried with this code:

data: str(20) type c.

LOOP AT gt_lips INTO gs_lips.

str = strlen( gs_lips-vgbel ).

if str > 7.

str = str - 7.

gs_lips-vgbel = gs_lips-vgbel + str(7).

endif.

modify gt_lips from gs_lips.

ENDLOOP.

but at this line: gs_lips-vgbel = gs_lips-vgbel + str(7). the program fails.I do not know why it fails.

Former Member
0 Kudos

Your Code :- gs_lips-vgbel = gs_lips-vgbel + str(7).

Correct code :- gs_lips-vgbel = gs_lips-vgbel+str(7).

Try to remove spaces in ur program between gs_lips-vgbel and + and str(7).

Edited by: vijetasap on May 14, 2009 12:06 PM

Former Member
0 Kudos

Use the following. Dont use str instead use x.

data: x(3) type c.

LOOP AT gt_lips INTO gs_lips.

str = strlen( gs_lips-vgbel ).

if x > 7.

x = x - 7.

gs_lips-vgbel = gs_lips-vgbel+x(7).

endif.

modify gt_lips from gs_lips.

ENDLOOP.

Hope it will solve ur problem.

Former Member
0 Kudos

Thanks a lot everybody ,it worked.

Former Member
0 Kudos

Hi,

Try this..

LOOP AT gt_lips INTO gs_lips.
str = strlen( gs_lips-vgbel ).
if str > 7.
str = str - 7 - 1.  " now you get the last 7 char
" The sum of position and offset should not be greater than field length
gs_lips-vgbel = gs_lips-vgbel + str(7).        
endif. 
modify gt_lips from gs_lips.
ENDLOOP.

Answers (5)

Answers (5)

Former Member
0 Kudos

Hi,

try this:


DATA: STR TYPE STRING.
DATA: STRL TYPE I.
*
STR = '0123456789abcdefg'.
STRL = STRLEN( STR ).
*
IF STRL > 7.
  STRL = STRL - 7.
  STR = STR+STRL(7).
ENDIF.
WRITE: / STR.

regards, Dieter

Former Member
0 Kudos

Hi,

Use class CL_RECA_STRING_SERVICES method RIGHT and indicate the number of characters you want to get from the right (=7) as below.

CALL METHOD cl_reca_string_services=>right

EXPORTING

id_string = my_string

id_length = 7

RECEIVING

rd_string = my_last_7_chars.

Hope this will help you.

Issa

Former Member
0 Kudos

Hi,

You use STRLEN to count the length.

Lets suppose a variable v_var of length 10.

DATA: v_var type char10,

v_var1 type char7,

v_len type i.

v_var = 'ABCDEFGHIJ'.

v_len = strlen( v_var ).

v_len = v_len - 7.

if v_len < 0.

v_len = 0.

endif.

v_var1 = v_var+v_len(7).

Hope this resolves ur query.

Regards,

Nikhil

Former Member
0 Kudos

Hi,

Refer the following program with string length calculation.


data:
 w_string type string,
 w_string1 type string,
 w_off type i value 0,
 w_off1 like w_off.

 w_string = 'vjhsdfahdfseht'.
 w_off = strlen( w_string ).
 w_off1 = w_off - 7.
 w_string1 = w_string+w_off1(7).
 write:
  w_string1.

Thanks,

Nithya

Former Member
0 Kudos

Hi,

Do like this...


parameter : s(100).
CALL FUNCTION 'STRING_REVERSE'
  EXPORTING
    string          = s
    lang            = 'E'
 IMPORTING
   RSTRING         = S
 EXCEPTIONS
   TOO_SMALL       = 1
   OTHERS          = 2
          .
S = S+0(7).
CALL FUNCTION 'STRING_REVERSE'
  EXPORTING
    string          = s
    lang            = 'E'
 IMPORTING
   RSTRING         = S
 EXCEPTIONS
   TOO_SMALL       = 1
   OTHERS          = 2
          .
WRITE S.

Regards

Debarshi