Search code examples
abapsap-bsp

Cut off text exceeding a certain length


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


Solution

  • 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.