BUILD_HTML
subroutine. Since the last update dates are different, I scanned the codes to see how the HTML codes were generated. In debug mode, I grabbed the generated HTML codes. As you can see the "line-height" values are different.
System 1 (last changed: 26.11.2018) |
System 1 (last changed: 19.11.2020) |
Hello POPUP_TO_CONFIRM function module. Could you please display this message? But every sentence must start on a new line! There are a few limitations, but I know you can! You can even display one more sentence.
Hello POPUP_TO_CONFIRM function module.
Could you please display this message?
But every sentence must start on a new line!
There are a few limitations, but I know you can!
You can even display one more sentence.
⚠️ Mr. and Mrs. Brown ProblemSince the ending (punctuation) marks that determine the end of a sentence are not used only at the end (as in the Mr. and Mrs. Brown example), I will create a text of sentences separated by a newline character in this story. |
Step | Description |
Step 1 | Build a text by combining 5 sentences with a newline character between them. Since we do not use a user-defined button, each sentence can be up to 48 characters long. |
Step 2 | Split the text into segments by "newline" characters. |
Step 3 | Add the required number of spaces at the end of each segment to complete up to 48 characters. Then append the segment to the end of the text. (i) There must be at least one space between sentences. Otherwise, the last word of the current sentence and the first word of the next sentence can be considered as a single word. |
Step 4 | Add an invisible character to preserve the trailing spaces at the very end of the text. If we do not add any character other than space, they will be ignored/removed. (Here again, I opt to use the newline character). When we merge all the segments (sentences), there will be a different number of spaces between them in the final text. |
Step 5 | Call the function module with the manipulated text. |
Sentence | Sentence Length | Max Length per Line | Number of Spaces to Add |
Hello POPUP_TO_CONFIRM function module. | 39 | 48 | 9 |
Could you please display this message? | 38 | 48 | 10 |
But every sentence must start on a new line! | 44 | 48 | 4 |
There are a few limitations, but I know you can! | 48 | 48 | 0 → See step 3(i) |
You can even display one more sentence. | 39 | 48 | 9 |
What about the flowchart?
*--------------------------------------------------------------------*
* Anatomy of a Function Module: POPUP_TO_CONFIRM - Part 3
*
* Story 3: Splitting Long Text into 48-Character-Wide Sentences and
* Starting Them on New Lines
*--------------------------------------------------------------------*
REPORT sy-repid.
CONSTANTS: newline VALUE cl_abap_char_utilities=>newline,
maxlen TYPE i VALUE 48.
DATA: question TYPE string,
answer(1).
*--------------------------------------------------------------------*
* Step 1:
* Build a text by combining 5 sentences with a newline character
* between them. Since we do not use a user-defined button, each
* sentence can be up to 48 characters long.
*--------------------------------------------------------------------*
question &&=:
|Hello POPUP_TO_CONFIRM function module.| , newline,
|Could you please display this message?| , newline,
|But every sentence must start on a new line!| , newline,
|There are a few limitations, but I know you can!| , newline,
|You can even display one more sentence.| , newline.
*--------------------------------------------------------------------*
* Step 2:
* Split the text into segments by newline characters.
*--------------------------------------------------------------------*
SPLIT question AT newline INTO TABLE DATA(segments).
CLEAR question.
*--------------------------------------------------------------------*
* Step 3:
* Add the required number of spaces at the end of each segment to
* complete up to 48 characters. Then append the segment to the end
* of the text.
* (i) There must be at least one space between sentences. Otherwise,
* the last word of the current sentence and the first word of the next
* sentence can be considered as a single word.
*--------------------------------------------------------------------*
LOOP AT segments ASSIGNING FIELD-SYMBOL(<segment>).
DO COND #( WHEN strlen( <segment> ) EQ maxlen THEN 1 ELSE ( maxlen - strlen( <segment> ) ) ) TIMES.
<segment> &&= | |.
ENDDO.
question &&= <segment>.
ENDLOOP.
*--------------------------------------------------------------------*
* Step 4:
* Add an invisible character to preserve the trailing spaces at the
* very end of the text. If we do not add any character other than
* space, they will be ignored/removed. (Here again, I opt to use the
* newline character).
*--------------------------------------------------------------------*
question &&= newline.
*--------------------------------------------------------------------*
* Step 5:
* Call the function module with the manipulated text.
*--------------------------------------------------------------------*
CALL FUNCTION 'POPUP_TO_CONFIRM'
EXPORTING
text_question = question
IMPORTING
answer = answer
EXCEPTIONS
OTHERS = 2.
🖥️ Output:
Now the question is:
With the QUESTION_TEXT
parameter and the "start each sentence on a new line" logic, how many sentences can we show at most if all the sentences are 48 characters wide?
CL_ABAP_CHAR_UTILITIES=>NEWLINE
as separator and its length is 1, here is the formula:Question text max length / ( Output text max length + Length of separator )
400 / ( 48 + 1 ) = 8.163265306122449
*--------------------------------------------------------------------*
* Anatomy of a Function Module: POPUP_TO_CONFIRM - Part 3
*
* Story 3: Splitting Text into 48-Char Sentences and Starting on New Lines
*--------------------------------------------------------------------*
REPORT sy-repid.
CONSTANTS: newline VALUE cl_abap_char_utilities=>newline,
maxlen TYPE i VALUE 48.
DATA: question TYPE string,
answer(1).
*--------------------------------------------------------------------*
* SELECTION-SCREEN
*--------------------------------------------------------------------*
PARAMETERS p_line01 TYPE c LENGTH 48 LOWER CASE DEFAULT 'This is the first sentence.'.
PARAMETERS p_line02 TYPE c LENGTH 48 LOWER CASE DEFAULT 'This is the second sentence.'.
PARAMETERS p_line03 TYPE c LENGTH 48 LOWER CASE DEFAULT 'This is the third sentence.'.
PARAMETERS p_line04 TYPE c LENGTH 48 LOWER CASE DEFAULT 'This is the fourth sentence.'.
PARAMETERS p_line05 TYPE c LENGTH 48 LOWER CASE DEFAULT 'This is the fifth sentence.'.
PARAMETERS p_line06 TYPE c LENGTH 48 LOWER CASE DEFAULT 'This is the sixth sentence.'.
PARAMETERS p_line07 TYPE c LENGTH 48 LOWER CASE DEFAULT 'This is the seventh sentence.'.
PARAMETERS p_line08 TYPE c LENGTH 48 LOWER CASE DEFAULT 'This is the eigth sentence.'.
PARAMETERS p_line09 TYPE c LENGTH 48 LOWER CASE DEFAULT 'This is the nineth sentence.'.
"Start each sentence on a new line
PARAMETERS p_newlin TYPE xfeld.
*--------------------------------------------------------------------*
* START-OF-SELECTION
*--------------------------------------------------------------------*
START-OF-SELECTION.
DO 9 TIMES.
DATA(line) = 'P_LINE0' && sy-index.
ASSIGN (line) TO FIELD-SYMBOL(<line>).
IF <line> IS NOT INITIAL.
question &&=: <line>, COND #( WHEN p_newlin EQ abap_false THEN | | ELSE newline ).
ENDIF.
ENDDO.
SPLIT question AT newline INTO TABLE DATA(segments).
CLEAR question.
LOOP AT segments ASSIGNING FIELD-SYMBOL(<segment>).
DO COND #( WHEN strlen( <segment> ) EQ maxlen THEN 1 ELSE ( maxlen - strlen( <segment> ) ) ) TIMES.
<segment> &&= | |.
ENDDO.
question &&= <segment>.
ENDLOOP.
question &&= newline.
CALL FUNCTION 'POPUP_TO_CONFIRM'
EXPORTING
text_question = question
IMPORTING
answer = answer
EXCEPTIONS
OTHERS = 2.
🖥️ Output:
Top image: newline is off | Top image: newline is off |
The length of this sentence is exactly fifty-seven chars.
USER_DEFINED_F1_HELP
button to appear. The good news is we don't need to provide a value that actually exists. (The first part of this blog series explains this).Question text max length / ( Output text max length + Length of separator )
400 / ( 57 + 1 ) = 6.896551724137931
*--------------------------------------------------------------------*
* Anatomy of a Function Module: POPUP_TO_CONFIRM - Part 3
*
* Story 4: Splitting Text into 57-Char Sentences and Starting on New Lines
*--------------------------------------------------------------------*
REPORT sy-repid.
CONSTANTS: newline VALUE cl_abap_char_utilities=>newline,
maxlen TYPE i VALUE 57.
DATA: question TYPE string,
answer(1).
DO 7 TIMES.
question &&=: 'The length of this sentence is exactly fifty-seven chars.', newline.
ENDDO.
SPLIT question AT newline INTO TABLE DATA(segments).
CLEAR question.
LOOP AT segments ASSIGNING FIELD-SYMBOL(<segment>).
DO COND #( WHEN strlen( <segment> ) EQ maxlen THEN 1 ELSE ( maxlen - strlen( <segment> ) ) ) TIMES.
<segment> &&= | |.
ENDDO.
question &&= <segment>.
ENDLOOP.
question &&= newline.
CALL FUNCTION 'POPUP_TO_CONFIRM'
EXPORTING
text_question = question
userdefined_f1_help = '_' "Displaying this button increases the width of the popup window.
IMPORTING
answer = answer
EXCEPTIONS
OTHERS = 2.
🖥️ Output:
USER_DEFINED_F1_HELP
with a value that doesn't exist is that the following message is displayed when the user clicks that button.QUESTION_TEXT
parameter.More Resources
|
Trademarks
Disclaimer
|
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
4 | |
2 | |
2 | |
2 | |
2 | |
1 | |
1 | |
1 | |
1 | |
1 |