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: 

take only the last 10 letters

Former Member
0 Kudos

Hi Experts,

How can you say take only the last 10 letters of a char(32).

e.g. here only 2222222222.

data lv_1(32) type c.

lv_1 = 'yyyyyyyyyyyyyyyyyyyyyy2222222222'.

Thx

Sas Erdem

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Another easy method will be ,

shift var right deleting trailing spaces.

var1 = var+22(10).

Mathews

7 REPLIES 7

Former Member
0 Kudos

try smthing like lv_1+22(10).

Pls Check syntax though

Regards

Shital

Former Member
0 Kudos

if its not always, populated all the 32 CHARs, then, its advisable to use CONDENSE after implimenting the above suggestion.

thanq

Edited by: SAP ABAPer on Mar 15, 2009 3:46 PM

Former Member
0 Kudos

Hi,

just by taking hardcoded offset would not solve your purpose dynamically as for an example if the string is of 22 characters then last 10 will be space....

if you want dynamically last 10 characters then use the code given below.

data : lv_1(32) type c,
         lv_len type i.

lv_len = strlen( lv_1 ).
if lv_len < 10.
  write lv_len.
else
  lv_len = lv_len - 10.
  write lv_1+lv_len(10).
endif.

This will surely resolve your issue for dynamic purpose

Regards,

Siddarth

Former Member
0 Kudos

Another easy method will be ,

shift var right deleting trailing spaces.

var1 = var+22(10).

Mathews

0 Kudos

Hi Mathews,

this will change the actual value of the string giving leading spaces which might create problems later in the coding...

Regards,

Siddarth

0 Kudos

Ok.... another not very simple method will be :

var_temp = var1.

shift var_temp right deleting trailing spaces.

var2 = var_temp+22(10)

Mathews

Former Member
0 Kudos

Simply take the value of the variable into another and fetch the last 10 letters as per logic given below:

DATA : lv_1(32) TYPE c VALUE 'yyyyyyyyyyyyyyyyyyyyyy2222222222',

lv_2(32) TYPE c,

lv_len TYPE i.

lv_2 = lv_1.

SHIFT lv_2 RIGHT DELETING TRAILING space.

lv_2 = lv_2+22(10).

WRITE 😕 lv_2.

Taking a second variable for processing will keep the values of your original variable intact.