Application Development and Automation 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: 
Read only

Remove last character

Former Member
0 Likes
4,063

Hi Experts,

I have one field with type string. Now you enters some data with star key.

For example :

test*

z*

zsample_*

Now my requirement is I need the characters only( test, z, zsample). I dont want symbols like *, _.

So how can i eliminate these symbols from my field. Its very urgent.

Anyone help me on this issue.

Points will be rewarded for all suggestions.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,530

data : v_string(10) value 'ztest*'.

  translate v_string using '* '.
  condense v_string no-gaps.

  write v_string. 

data : v_string(10) value 'ztest*'.

  translate v_string using '* '.
  condense v_string no-gaps.

  write v_string. 
7 REPLIES 7
Read only

Former Member
0 Likes
1,531

data : v_string(10) value 'ztest*'.

  translate v_string using '* '.
  condense v_string no-gaps.

  write v_string. 
Read only

Former Member
0 Likes
1,530

Check the code.

REPORT ztest_m1 .

parameters: p_text(50) type C.

data: w_len type i,

W_OFF TYPE I.

w_len = strlen( p_text ).

do w_len times.

W_OFF = SY-INDEX - 1.

if sy-abcde cs p_text+W_OFF(1).

else.

p_text+W_OFF(1) = SPACE.

ENDIF.

ENDDO.

CONDENSE p_TEXT.

WRITE : p_TEXT.

Read only

Former Member
0 Likes
1,530

Hi

Finding String Length and Avoiding Last Character in the string by using offset is the only easy way.

If you know the exact length of the variable value, then you can do offset directly. So that u can remove all the unwanted characters

reward if useful

Regards

Ravi

Read only

rainer_hbenthal
Active Contributor
0 Likes
1,530

Use shift command to shift the contents to right until the last character is wanted one, then shift left to delete tle leading blanks.

pseduo code:

do until right most character is a valid one.

shift var right by 1 PLACES.

enddo.

shift var left deleteing leading spaces.

Read only

Former Member
0 Likes
1,530

Hi

parameters: p_text(50) type C,

p_word(50) type C.

data: w_len type i,

W_OFF TYPE I.

w_len = strlen( p_text ).

wa_len = w_len - 1.

p_word = p_text+0(w_len).

CONDENSE p_word.

wRITE : p_word.

Read only

0 Likes
1,530

Hi,

use the following code

DATA: str type string.

DATA: w_len type I.

w_len = STRLEN( str ).

w_len = w_len - 1.

str = str+0(w_len).

regards

Mahesh

Read only

Former Member
0 Likes
1,530

this will solve ur problem..

data: count type n.

value = 'TESTZ'.

count = strlen( value ).

count = count - 1." count = 4

value = value+0(count). "value = TEST.

write value.

Regards

Sugumar G