Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

How to prevent text wrapping from breaking on words

I've got a formula in a Group Footer that concatenates the Group Header results. When I display it, however, the text wrapping cuts off words at the width of the text box. I've checked Can Grow, but can't really widen the text box due to the constraints of the layout. Here's my example:

GH2     Jenny

GH2     Jonny

GH2     Penny

GH2     Sally

GH2     Michael

GF2     Jenny, Jonny, Pe

            nny, Sally, Micha


Is there any way to control the text wrapping so that it only breaks on a word? Thanks!

Former Member

Hi Ahren,

Here's what you need to do:

1) Create another text object of the same width and count the maximum number of letters that can fit

2) It is advisable that you use a fixed width font like Courier New. If you can't however, you could count by using a letter that takes the most space - example W, X or Z.

3) You would then fill up the text object with either of these characters and this will help you count the letters that can fit in that space

4) Create a formula with this code:

stringvar s := {string_field_or_formula_variable};

local stringvar array arr := split(s," "); 

local numbervar i; 

numbervar lcount; 

lcount := 1; 

local numbervar fixed := 13;  //Replace this number with the letters you counted that can fit in the text object

local booleanvar nl := false; 

for i := 1 to ubound(arr) do 

    If i = 1 then 


        local stringvar nstring := nstring + trim(arr[i]) + " "; 

        local numbervar rem := fixed - len(nstring); 


    else if i <> 1 and i <> ubound(arr) then 



        if len(arr[i]) <= rem then 


            nstring := nstring + trim(arr[i]) + " "; 

            rem := (fixed*lcount) - (len(nstring)+lcount);        

            stringvar s := nstring; 

            numbervar t := rem;  




            nstring := rtrim(nstring) + chr(13) + trim(arr[i]) + " "; 

            lcount := lcount + 1; 

            nl := true; 

            rem := (fixed)- len(arr[i] + " "); 



    else if i = ubound(arr) then 


        if len(arr[i]) <= rem then 


            nstring := nstring + trim(arr[i]); 

            rem := fixed - len(nstring); 




            nstring := nstring + chr(13) + trim(arr[i]); 

            rem := fixed - len(arr[i] + " "); 





Note: Line #6 is where you would type in the number of letters that can fit

5) Make sure 'Can Grow' is enabled

Hope this helps.


0 View this answer in context
Not what you were looking for? View more on this topic or Ask a question