When I need something, I look for it in the nearest place.

SAP standard codes are my main resource when it comes to ABAP development. That’s why I usually lose myself in SAP codes. It’s a kind of journey. The good thing is, I always get something useful from SAP at the end of every journey.

That’s why I’m a traveler.

* * *

Let me tell you about one of them. Before starting this journey, your SAP backpack should contain some ABAP knowledge, the POPUP_TO_CONFIRM function module, and optionally the ARBFND_DETAILED_LONGTEXT document object.

After you log in to your SAP system, you can check the existence of these objects in transactions SE37 for the function module and SE61 for the document object.

This journey will include the following sections including six campfire stories (two stories in each next post):

  • Discovery
    • What is POPUP_TO_CONFIRM?
    • The Moment I Feel a Journey Approaching
    • Experiment: Newline Character and HTML <br> Tag
    • Function Interface (Parameters)
    • Flow Logic
  • Campfire
    • Story 1: Changing the Popup Icon
    • Story 2: Customizing the Icons and Quick Info of Buttons
    • Story 3: Splitting Text into 48-Char Sentences and Starting on New Lines
    • Story 4: Splitting Text into 57-Char Sentences and Starting on New Lines
    • Story 5: Displaying an Unordered List
    • Story 6: Displaying Longer Text Using a Document Object

🧭 Let’s start the journey!

Discovery

What is POPUP_TO_CONFIRM?

POPUP_TO_CONFIRM is a standard function module used to display a message (question, document object text, or both) in a modal dialog box, and also to ask users to decide.

I recommend reading the documentation before using it. To do this, please follow the steps below.

  1. Launch transaction SE37.
  2. Enter POPUP_TO_CONFIRM in the Function Module input field.
  3. From the top menu, choose Goto → Documentation → Function Module Documentation.

💡 This is the first step in getting something from SAP.

The Moment I Feel a Journey Approaching

I was writing an ABAP program that reads spreadsheet data from a Microsoft Excel file and creates a Purchasing Contract² in an SAP S/4HANA 2020 On-Premise system.

The user selects a file, executes the program, and then the program uploads the file, displays the content, and performs an incompleteness check. If everything is fine, the user clicks the “Create Contract” button.

To prevent accidental button clicks, the program displays the following message and asks for a confirmation.

An%20example%20output%20of%20the%20POPUP_TO_CONFIRM%20function 

An example output of the POPUP_TO_CONFIRM function

Since the second sentence was broken, a possible request would be:

“As a user, I want to see the sentences of the message start on new lines so I can read them easily”

Experiment: Newline Character and HTML <br> Tag

I wondered if I could make each sentence start on a new line. My first attempt was to insert a newline character (CL_ABAP_CHAR_UTILITIES=>NEWLINE) between sentences (which is probably the first thing that comes to mind). Of course, it didn’t work! Then, I started to analyze the codes of the function.

When I understand the logic and noticed a few hard-coded values, I thought I could achieve something useful.

* * *

Welcome to the anatomy of the POPUP_TO_CONFIRM function module.

↑ Top

Function Interface (Parameters)

Let’s first explore some of the parameters.

TEXT_QUESTION Parameter

The POPUP_TO_CONFIRM function displays the text in an HTML container. Therefore, it splits the TEXT_QUESTION text into segments to populate an HTML table. The function uses the TEXT_SPLIT function to do this but, sentences in the text do not start on new lines and there is no parameter to control this.

In the meantime, a quick note about the TEXT_SPLIT function. It splits the input text once in the specified line length word-compatibly. See the function’s documentation for more details.

⚠️ Here, we should keep in mind that we can send a maximum of 400 characters to the TEXT_QUESTION parameter which is already mentioned in the function module documentation. That means more than 400 characters will be truncated. It is a possible risk that the last sentence is displayed incompletely.

USERDEFINED_F1_HELP Parameter

The USERDEFINED_F1_HELP parameter is used to provide information from a document object. When used, a third button labeled “Info” appears.

If the USERDEFINED_F1_HELP parameter has a value (even if it is invalid), the function splits the TEXT_QUESTION text into 57-character-wide segments. Otherwise, the text is 48 characters wide.

48/57: Please note these numbers. They will be the key to our development.

IF userdefined_f1_id NE space.
  textlength = 57.
ELSE.
  textlength = 48.
ENDIF.

Also, the window size is adjusted based on the text length. See the formula in the CALCULATE_SCREEN_SIZE subroutine:

end_spalte = start_spalte + textlength + 15.

Briefly, the text length increases when the info button is present, as the length of the text increases, the window size also increases.

DIAGNOSE_OBJECT Parameter

As mentioned in the function module documentation, in addition to TEXT_QUESTION, a standard or custom document text that exists in the system can be displayed by setting the parameter DIAGNOSE_OBJECT. (See transaction code SE61, and database tables DOKHL, and DOKTL).

PARAMETER Parameter

If the DIAGNOSE_OBJECT parameter contains placeholders and we populate the PARAMETER table with the corresponding PARAM and VALUE values, the function replaces them in the DIAGNOSE_OBJECT text.

Wait a minute! Does this only apply to the DIAGNOSE_OBJECT text?

No, it also applies to the TEXT_QUESTION text. We can build a dynamic TEXT_QUESTION using a DIAGNOSE_OBJECT.

💡 Placeholders are useful when building dynamic text.

↑ Top

Flow Logic

Let’s review the flow logic of the function. When we use all these DIAGNOSE_OBJECTTEXT_QUESTIONUSERDEFINED_F1_HELP, and PARAMETER parameters, the function performs the following steps:

  • Sets the icon of the popup (Form TYPE_OF_POPUP).
  • Sets the text width based on the presence of the USERDEFINED_F1_HELP value.
  • Reads the text of the document object in the DIAGNOSE_OBJECT parameter (Function module DOCU_GET_FOR_F1HELP).
  • Replaces existing placeholders in the text with the corresponding values in the PARAMETER table (Function modules TEXT_INCLUDE_REPLACE and TEXT_CONTROL_REPLACE).
  • Splits the final DIAGNOSE_OBJECT text into segments and fills the TEXT_TAB2 internal table.
  • Replaces existing placeholders in the TEXT_QUESTION text with the corresponding values in the PARAMETER table.
  • Decides whether to include the ‘Cancel’ button.
  • Decides whether to include the ‘Info’ button.
  • Sets button icons and quick info.
  • Splits final TEXT_QUESTION text into segments and fills the TEXT_TAB1 internal table (Form FORMAT_TEXT).
  • Calculates the screen size (Form CALCULATE_SCREEN_SIZE).
  • Calls the screen 0700 (includes subscreen 0702).
  • Subscreen 0702 generates HTML content and fills HTML tables. Finally, HTML containers show generated data (Form BUILD_HTML and SHOW_HTMLS).
    • If the DIAGNOSE_OBJECT text is too long, a vertical scroll bar appears on the right.
    • If both DIAGNOSE_OBJECT and TEXT_QUESTION are present, a line of 57 hyphens is displayed as a separator between the texts.

All this happens in a dialog screen with custom containers, using the CL_GUI_CUSTOM_CONTAINER and CL_GUI_HTML_VIEWER classes.

🗺️ Need a Map for Your Trip?

Flow%20logic%20of%20the%20Function%20Module%20POPUP_TO_CONFIRM 

Flow logic of the Function Module POPUP_TO_CONFIRM

Conclusion

In this blog post, you have learned how the POPUP_TO_CONFIRM function works, information about some of its parameters, what kind of objects are behind it, how its size is determined, and its flow logic.

As you can see, we have a powerful function module that we can use for different scenarios.

Next Step?

Now that we’ve discovered how the function module works, I will build a campfire and tell the first 2 stories in the next chapter.

Upcoming stories:

  • Story 1: Changing the Popup Icon
  • Story 2: Customizing the Icons and Quick Info of Buttons

See you in the next chapter.

↑ Top

More Resources 

  • For more resources on ABAP development, you can visit the ABAP Development topic page here, ask a question, or follow the ABAP Development blog here.
  • Please follow Serkan Saglam for future posts and feel free to share your feedback or thoughts in a comment.
Endnotes 

  • ¹ I’m not a scientist, just a traveler (Serkan Saglam, December 1, 2022)
  • ² Purchasing Contract: An outline purchase agreement that contains special conditions that are negotiated between a purchaser and a seller which covers the supply of goods or the performance of services.

Trademarks

  • Microsoft®, Microsoft Excel® are trademarks of the Microsoft group of companies.
  • SAP®, ABAP® are the trademarks or registered trademarks of SAP SE or its affiliates in Germany and in other countries.

Disclaimer

  • All source code available in this blog post is provided “as is” without warranty of any kind, and any use of such source code is at your own risk.
Sara Sampaio

Sara Sampaio

Author Since: March 10, 2022

0 0 votes
Article Rating
Subscribe
Notify of
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x