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: 

Logic to format text in an internal table with the line length defined dynamically ... needed more than once, it may be useful to someone else, especially for those who are displaying text in a Smartform

bruno_moreira
Explorer
0 Kudos
212

Hi Everyone,

Logic in the attached .txt

Best Regards

Bruno

3 REPLIES 3

Former Member
0 Kudos
184

Thanks for sharing.

My take on this is essentially to search backwards from the maximum line length for the first space and chop off that number of characters then print them.  Keep going until the string is empty:

Start-Of-Selection.
*
Constants c_Max_Len Type i Value 50.
*
Data: l_Str         Type String,
      l_Trimmed     Type String,
      l_Pos         Type i,
      l_Len         Type i.
*
l_Str = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed'.
l_Str = l_Str && ' do eiusmod tempor incididunt ut labore et dolore magna'.
l_Str = l_Str && ' aliqua. Ut enim ad minim veniam, quis nostrud exercitation'.
l_Str = l_Str && ' ullamco laboris nisi ut aliquip ex ea commodo consequat.'.
l_Str = l_Str && ' Duis aute irure dolor in reprehenderit in voluptate velit'.
l_Str = l_Str && ' esse cillum dolore eu fugiat nulla pariatur. Excepteur sint'.
l_Str = l_Str && ' occaecat cupidatat non proident, sunt in culpa qui officia'.
l_Str = l_Str && ' deserunt mollit anim id est laborum.'.
*
While l_Str Is Not Initial.
      Clear l_Trimmed.
      l_Len = StrLen( l_Str ).
      If l_Len <= c_Max_Len.
         l_Trimmed = l_Str.
         l_Str     = ''.
      Else.
         l_Pos = Find( Val   = l_Str
                       Regex = ' [^ ]*$'
                       Off   = 0
                       Len   = c_Max_Len ).
         If l_Pos = -1.
            l_Pos = c_Max_Len.
         EndIf.
         l_Trimmed = SubString( Val = l_Str
                                Off = 0
                                Len = l_Pos ).
         l_Pos = l_Pos + 1.
         l_Str = SubString( Val = l_Str
                            Off = l_Pos ).
      EndIf.
      l_Len = StrLen( l_Trimmed ).
      Write :/ l_Trimmed, l_Len.
EndWhile.

naimesh_patel
Active Contributor
0 Kudos
184

It would be great if you convert this to the document with some screenshots showing inputs and expected output.

Thanks for sharing.

Regards,
Naimesh Patel

Jelena_Perfiljeva
Active Contributor
0 Kudos
184

I agree - this should not be posted as discussion. Add more explanation (especially business scenario when this could be needed) and re-post it as a document. See this document for more info. Also the title is barely readable, please don't put the whole text there.