Quantcast
Channel: ABAP Development
Viewing all articles
Browse latest Browse all 948

Overcome Smartforms Text Limitation of 255 characters

$
0
0
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.
img1.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.
img2.png
Remember to choose Start option as Append directly since we want to display the full text in correct format.
img3.png
And here we go...
img4.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.
 

Viewing all articles
Browse latest Browse all 948

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>