2009 Feb 10 7:27 AM
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!
2009 Feb 10 7:35 AM
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.
2009 Feb 10 7:29 AM
2009 Feb 10 7:30 AM
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
2009 Feb 10 7:30 AM
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
2009 Feb 10 7:33 AM
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.
2021 Nov 03 5:59 AM
2009 Feb 10 7:33 AM
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)
2009 Feb 10 7:35 AM
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.
2009 Feb 10 7:36 AM
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
2009 Feb 10 7:40 AM
Hi
you can use
shift lv_c
condense lv_c
it should give you the remaining characters
Thanks
Viquar Iqbal
2009 Feb 10 7:43 AM
Dear,
It is a special character.
To remove the special characters use below FM,
CONVERT_STREAM_TO_ITF_TEXT
Thanks and Regards,
2009 Feb 10 7:46 AM
hi,
data:
w_str(5) type c value 'xxxx#'.
shift w_str by 1 places right.
write:/ w_str.
regards,
Mdi.Deeba
2009 Feb 10 7:46 AM
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
2009 Feb 10 8:39 AM
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 removedRegards,
Manoj Kumar P
2025 May 12 6:51 PM - edited 2025 May 22 7:27 PM
While working in ABAP, especially when preparing data for file downloads or exporting internal tables, you might notice that some lines seem to end with a " # " symbol. But here's the catch that " # " is not always a real hash symbol. Naturally, you might think it’s a hashtag — but often, it’s not. These characters don’t display visually, but depending on how the file is opened or downloaded, they may appear as strange or misleading symbols.
Sometimes, that " # " is just how non-printable characters like carriage return (CR) or newline (LF) appear when viewed in SAP ALV, Excel, or when downloading.
These hidden characters:
Here’s a reliable way to detect the actual last character and remove it only if needed (e.g. it's a # or control character):
DATA: lv_value TYPE string VALUE 'ABCDE#', " Input string (may have unwanted char at end)" replace this variable with yours*
lv_len TYPE i, " Length of the string
lv_lastval TYPE string, " Last character of the string
lv_hex TYPE xstring, " Hex value of the last character
lv_newval TYPE string. " Final cleaned value
" Step 1: Find the length of the string
lv_len = strlen( lv_value ).
SUBTRACT 1 FROM lv_len. " Adjust to point to last character (0-based index)
" Step 2: Get the last character
lv_lastval = lv_value+lv_len(1).
" Step 3: Convert last character to hex using built-in function module
CALL FUNCTION 'NLS_STRING_CONVERT_FROM_SYS'
EXPORTING
lang_used = sy-langu " Use system language
source = lv_lastval " Character to convert
to_fe = 'MS ' " Target frontend encoding (Microsoft)
IMPORTING
result = lv_hex " Hex value of the character
EXCEPTIONS
OTHERS = 1. " Simple error catch
" Step 4: Check if the character is '#' (hex 23)
IF lv_hex = '23'. " ASCII hex for '#'
lv_newval = lv_value+0(lv_len). " Remove last character
ELSE.
lv_newval = lv_value. " Keep original if not '#'
ENDIF.I hope this helps! Let me know your thoughts or if you have any questions.
Thanks,
Akshay Anil
Technical Consultant, SAP ABAP | BTP | Fiori | Ui5