Skip to Content
Hi folks,
As we know, beside printing, Smartforms is also very useful with other usages.  E.g http://scn.sap.com/community/abap/blog/2013/01/24/send-html-mail-using-smartforms. 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
DO b TIMES.
     //Append to itab input_text+pos(255)
      //pos += 255;
ENDDO.
//Append to itab the remainder
input_text+pos(c)
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.

/wp-content/uploads/2013/07/img1_243082.png

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.

/wp-content/uploads/2013/07/img2_243086.png

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

/wp-content/uploads/2013/07/img3_243088.png

And here we go…
/wp-content/uploads/2013/07/img4_243095.png
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.
  else.
    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.
    enddo.
    "Append string remainder
    append i_str+lv_pos(lv_rmd) to et_str.
  endif.endfunction.
 
To report this post you need to login first.

7 Comments

You must be Logged on to comment or reply to a post.

  1. Suhas Saha

    Hello,

    You didn’t have to re-invent the wheel. You could have done this by –

    1. Method CL_DOCUMENT_BCS=>STRING_TO_SOLI( )
    2. Function SCMS_STRING_TO_FTEXT

    – Suhas

    PS – SAP’s likeness for 255 characters is a well-known fact 😘

    (0) 
  2. Dave Taranovich

    Here’s an option…

    In the Text Node… display the one field (type string) in ‘chunks’ that are less than 256 characters in length…

    I use 100 character ‘chunks’ so it’s easy to do the math for the next ‘chunk’…

     

    &wa_text_string+0(100)&&wa_text_string+100(100)&&wa_text_string+200(100)&&wa_text_string+300(100)&

     

    Dave T.

    (0) 

Leave a Reply