Application Development Blog Posts
Learn and share on deeper, cross technology development topics such as integration and connectivity, automation, cloud extensibility, developing at scale, and security.
cancel
Showing results for 
Search instead for 
Did you mean: 
Jigang_Zhang张吉刚
Active Contributor
0 Kudos
cover_f.jpg
Its a little awkward to talk about Smartforms in 2024~ Even though the current SAP world is surrounded by popular words like Cloud, Odata, and RESTFUL API Adobe forms for S/4 HANA, many Smartforms are still stubborn to keep on duty today. As long as those Smartforms have been used, changes will occur sooner or later. 
 
Think about one requirement for the long text display at Smartforms with the detailed specifications below:
From the customized screen side:
  1. The user will maintain long text at one text editor;
  2. Up to 3000 characters;
  3. Each text line should support up to 100 characters;
From Smartform's side:
  1. The long text should be displayed at the main window after the item total part, which means dynamic positions;
  2. The height of this long text should be based on how much text the user inputs at the text editor, which means dynamic height;
  3. The long text should have an outer frame only, no other borderline per line;
  4. The line feed from the text editor should be kept;
  5. The long text should auto-wrap up;

It looks familiar, but I forget how I figured it out before! That is why I write it down here. There must exist a better approach, I'm all ears : D

1, What if using Adobe Forms to achieve this?

Sounds easy, right? Itll be quite straightforward if using Adobe Forms to realize it:
  1. Choose Flowed positions for the Subform that contains this long text;
  2. Tick the checkbox of Allow Multiple Lines for the Text field with the format of Rich Text
  3. Tick the checkbox of Expand to fit for height.
01.jpg
After a few years spoilered by Adobe Forms, its frustrating to look back and find that Smartform doesnt support those convenient features at all. For me, there are two major issues for this requirement:

2, Deal with wrap-up for long text

I rarely consider the wrap-up issue for long text because normally it will be saved as SO10 text objects at tables STXH and STXL. Text table lines can be fetched through FM: READ_TEXT which has less than 100 characters per line, maybe 72 precisely which is wide enough for normal long text like item texts/footer, etc.
05.jpg
 
But this case needs 100+ characters per line occupying a width of 18CM+ while printed out. To achieve dynamic position and height at output for this long text, I can't use a template and have to choose Table.
p3.jpg
I thought I had to convert long strings from the text editor into table lines like the format of TLINE (TDFORMAT and TDLINE), which is not a good idea as the up limit existed! 
 
First, the long text from a text editor is in string format instead of in TLINE format which is input for FM like 'FORMAT_TEXTLINES' and 'SPLIT_TEXTLINE'. Second, you will encounter limitation issues from FM (like VB_CP_CONVERT_STRING_2_ITF ) that can't support more than 72 characters per line or word split issue. 
02.jpg
Any idea dealing with word concatenate and wrap-up on one's own could complicate simple things. Then I found FM like 'SOTR_SERV_STRING_TO_TABLE' and 'RKD_WORD_WRAP' can deal with wrap-up without word truncation and dynamic characters per line like below:
06.jpg
Those FMs need the maximum number of characters per line and this limit number is fixed. Once the window width changes inside the Smartforms, it always happens then need to update this up limit as well. 
Finally, I found 'CONVERT_STREAM_TO_ITF_TEXT' which does not need to input a fixed output length and supports up to 132 characters per line (which can fulfill auto-adapt the window width for this case).
p1.jpg
Here the whole text is copied from the SAP website which has no line feed by force at the end of the line(exists at the end of the paragraph), just let the text editor deal with the line feed. But if the user inputs manually and adds line feed by force per line, it'll be like the below. That pound symbol(##) stands for line feed input by the user inside the string.
p2.jpg
Now the text lines are available with the correct width to fit the window and the perfect wrap-up, then how to set the outer frame?

3, Set the outer frame for long text

07.jpg
For Template, just setting the Box and Shading at output options will get the outer Frame. But there are no ‘Box and Shading’ options for Table. Two options here:
  • Use the 'Outer Frame' at Tab attributes:
08.jpg
  • Use the 'Select Pattern' at Tab attributes:
09.jpg
Be aware of step 1 which needs to select all the line types together, otherwise, it'll not work if no selection. Besides, if you don't use line type for the header or footer just like in my case, a nightmare is coming.
10.jpg
The outframe will not work!!! it'll be an item frame all the time! I just realized that after dozens of tests that cost hours~ Even have a header/footer line type does not exist header/footer line uses those line types (with item line type at the middle), the 'Select Pattern' approach will not work as well.
 
As no content for the header and footer, they'll still occupy some heights at the text window. To deal with this, I create a tiny paragraph style to make the header and footline as small as possible~

 

One more thing

The output table from 'CONVERT_STREAM_TO_ITF_TEXT' is still in TLINE format, if passed to the Text table of Smartforms, then it'll lose auto-fit for window width~
11.jpg
The trick here is to create one deep structure to make table ITF_TEXT as a line field and display the text with Dynamic text options.
12.jpg

Summary:

  1.  Get the long string from the text editor and convert the string with 'CONVERT_STREAM_TO_ITF_TEXT';
  2.  Use Dynamic text with a loop of one deep structure that contains ITF_TEXT as a line field;
  3.  Create a header and footer for the table, and use the 'Select Pattern' approach to set the outer frame.
Not sure whether I'm overthinking or not. I believe so but it's hard to believe that I can only achieve this requirement in such a bizarre way...
 
One scary question here is what if there are more than 132 characters per text line? The good news is at least for A4 paper size, more than 132 characters per line is almost unreadable. And we have Adobe forms! 
 
Please kindly leave comments if any better way to achieve this. Many thanks.