Skip to Content

Overcome Smartforms Text Limitation of 255 characters

Hi folks,
As we know, beside printing, Smartforms is also very useful with other usages.  E.g However, from SAP Note 485296, we know one of Smartform’s limitations:
In Smart Forms, the output length for string fields is restricted to a maximum of 255 characters.
This means whenever we want to pass and display a dynamic text parameter (type STRING for example) in Smartforms, the text will be truncated after the first 255 characters. In this blog, I will share with you my 2-cents-worth in how I overcame the problem. It’s pretty straight forward, if 255 is the limitation, we just need to slit the text into many pieces of length 255 and append to the form. For this, we will find the answers to two questions below:

1. How to split the text correctly into an internal table with field length 255 chars?

Well, the solution to this problem is just basic math.
//First we need an itab of type TCHAR255
//Then we proceed with the calculations, let:
a = strlen(input_text)
b = floor(a/255)
c = a MOD 255
pos = 0
     //Append to itab input_text+pos(255)
      //pos += 255;
//Append to itab the remainder
We may want to wrap the above logic into a Function Module for reusing it with many text elements in the Smartforms.

2. How to append the split-ed text correctly to Smartforms?

We will structure our Smartforms as below: Program Lines followed by a Loop  and under the Loop is our Text Element.


We will need global variables: GT_TEXT TYPE TCHAR255, GV_TEXT TYPE CHAR 255
Looping through out GT_TEXT itab into GV_TEXT, and we will show the GV_TEXT for every loop.


Remember to choose Start option as Append directly since we want to display the full text in correct format.


And here we go…
This is it for this blog, hope it helps you and please share if you know of any other method. Cheers!
Source Code:
function z_split_string.*"----------------------------------------------------------------------*"*"Local Interface:*"  IMPORTING*"     REFERENCE(I_STR) TYPE  STRING*"  EXPORTING*"     REFERENCE(ET_STR) TYPE  TCHAR255*"----------------------------------------------------------------------
  data: lv_len   type i, "String Length
        lv_rmd   type i, "Remainder of String Length / 255
        lv_pos   type i, "String position
        lv_fct   type i, "Integer: Roundown(String Length/255)
        lv_pfct  type p  length 4 decimals 2.*---Get length of input string
  lv_len =  strlen( i_str ).*---Split string into itab of field length 255 char
  if lv_len < 255.
    append i_str to et_str.
    lv_rmd   = lv_len mod 255.
    lv_pfct  = floor( lv_len / 255 ).
    lv_fct   = lv_pfct.
    do lv_fct  times.
      append i_str+lv_pos(255) to et_str.
      lv_pos = lv_pos + 255.
    "Append string remainder
    append i_str+lv_pos(lv_rmd) to et_str.
You must be Logged on to comment or reply to a post.