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: 

remove last character in a string

Former Member
0 Kudos

I have a variable with C type for example lv_c = 'xxxx#'. Now I want to remove the last character of this variable value? which function do I use? and how do I do that. Thanks!

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi,

data w_i type i.

w_i = strlen( lv_c ).

subtract 1 from w_i.

write : lv_c+0(w_i).

This is working.

13 REPLIES 13

Former Member
0 Kudos

use: SHIFT lv_c.

Former Member
0 Kudos

Hi,

just use offsetting..

data

w_temp like lv_c.

lv_c = 'xxxx#'.

w_temp = lv_c+0(4).

write: w_temp.

output is like this:

XXXX

lv_c+0(4) means it takes the first(i.e.from starting) 4 characters.based on this u can omitt or select the characters..just mention the offset value...

Regards

Kiran

Edited by: Kiran Saka on Feb 10, 2009 8:31 AM

Former Member
0 Kudos

hi,

u can use n = strlen(lv_c) // u will get length of the string..

then lv_c = lv_c+0(n-1)... will fetch u the value except last character..

Rgds.,

subash

former_member222860
Active Contributor
0 Kudos

Hi,

here's the logic.

data: str type string value 'abcd#',    len type i.

len = strlen( str ).
len = len - 1.
str = str+0(len).

write:/ str.

0 Kudos

thank u issue resolved.

Former Member
0 Kudos

first find string length from function strlen

lv_len = strlen(lv_c)

lv_len = lv_len - 1

then make one more var of type lv_c lv_c1

lv_c1 = lv_c + 0(lv_len)

Former Member
0 Kudos

Hi,

data w_i type i.

w_i = strlen( lv_c ).

subtract 1 from w_i.

write : lv_c+0(w_i).

This is working.

Former Member
0 Kudos

Hi ,

You can use the following code It will solve the problem.-----

DATA : w_data(6) TYPE c VALUE 'ABCDEF'.
CONDENSE w_data NO-GAPS.
SHIFT  w_data RIGHT .
WRITE w_data.

Regards

Pinaki

viquar_iqbal
Active Contributor
0 Kudos

Hi

you can use

shift lv_c

condense lv_c

it should give you the remaining characters

Thanks

Viquar Iqbal

Former Member
0 Kudos

Dear,

It is a special character.

To remove the special characters use below FM,

CONVERT_STREAM_TO_ITF_TEXT

Thanks and Regards,

Former Member
0 Kudos

hi,

data:

w_str(5) type c value 'xxxx#'.

shift w_str by 1 places right.

write:/ w_str.

regards,

Mdi.Deeba

Former Member
0 Kudos

Hi Anthony ,

Kindly go through this link below:

http://help.sap.com/saphelp_nw70/helpdata/en/9f/db999535c111d1829f0000e829fbfe/content.htm

Hope it helps

Regrds

Mansi

Former Member
0 Kudos

Hi,

You can write this logic,

DATA:  lv_len TYPE i.
lv_len = STRLEN( lv_c ).
SUBTRACT 1 FROM lv_len.
lv_c = lv_c+0(lv_len). "Here last character will be removed

Regards,

Manoj Kumar P