4

I have a list with texts with lengths ranging from 1 character to several thousands. I want to cut off all texts exceeding 255 characters. How can I do that? Do I have to check the length of each String and then cut it with (255) or is there a more elegant expression?

Edit: like this

<% IF STRLEN( wa_comm-text ) > 255. %>
<%= wa_comm-text(255) %> ...
<% ELSE. %>
<%= wa_comm-text %>
<% ENDIF. %>

this is BSP

Thanks in advance

Sandra Rossi
  • 11,934
  • 5
  • 22
  • 48
Stefan Ernst
  • 2,781
  • 4
  • 25
  • 34

3 Answers3

4

The other option is:

<% 
data: ls_text(255) type c. 
ls_text = wa_comm-text.   
%>
<%= ls_text %>

Because you obviously cannot use substrings on strings, and if they are shorter, you will get a runtime error.

mydoghasworms
  • 18,233
  • 11
  • 61
  • 95
0

I created for this a 'string solutions' class called zss, with a static method that will cut off a given string and the given length.

Then you can just do something like this:

<%= zss=>left( s = wa_comm-text cutoff = 255 ). %>

or even a more specific method

<%= zss=>left255(  wa_comm-text ). %>
Wladimir Palant
  • 56,865
  • 12
  • 98
  • 126
tomdemuyt
  • 4,572
  • 2
  • 31
  • 60
0

Just as an option:

<%= CONV char255( wa_comm-text ) %>

inline conversion and trimming to target type is done here.

Suncatcher
  • 10,355
  • 10
  • 52
  • 90