Custom Controls (2024)

Use

A custom control is a rectangular area on the screen of a dynpro. They are created in Screen Painter and, like all other screen objects, have a unique name. Custom controls are used to embed controls in these areas. Controls are software components of the presentation server. Depending on the SAP GUI used, these components are either ActiveX controls or JavaBeans. They allow certain tasks, such as editing texts, to be performed locally on the presentation server. The control is driven by the application logic, which continues to run on the application server.

SAP Control Framework

The controls on the presentation server and the ABAP application programs on the application server communicate using SAP Control Framework. SAP Control Framework contains global classes that can be found in the class library under Custom Controls (1)BasisCustom Controls (2)Frontend ServicesCustom Controls (3). These classes encapsulate the communication between the application server and presentation server, which is implemented using Remote Function Call.

All application controls are encapsulated in a global class. The classes for controls shipped by SAP can be found, for example, in the class library under Custom Controls (4)Basis Custom Controls (5) Frontend ServicesCustom Controls (6), or Custom Controls (7)Basis Custom Controls (8) Component IntegrationCustom Controls (9). Programs that use controls on a screen of a dynpro work exclusively with the methods and events of these classes.

Container Controls

Before a custom control on a screen can be used, it must be assigned a container control. Container controls are instances of special global classes from SAP Control Framework. The global class for custom controls is called CL_GUI_CUSTOM_CONTAINER. To associate a custom control with a container control, the custom control name is passed to the constructor of the container control when it is instantiated using CREATE OBJECT.

As well as using custom containers, controls can be associated with dynpros using a docking container from the class CL_GUI_DOCKING_CONTAINER. Docking containers do not embed the control in a dynpro. Instead, they attach it to one of its four edges. Containers can also be nested. For example, splitter controls from the classes CL_GUI_EASY_SPLITTER_CONTAINER or CL_GUI_SPLITTER_CONTAINER can be associated with other containers. This makes it possible to split a custom control or docking control into more than one window, so enabling more than one standalone control to be used in a single container.

Application Controls

An instance in the ABAP program must also be created for the actual application control to be displayed in the custom control area, for example a TextEdit control from the class CL_GUI_TEXTEDIT or a tree control from the class CL_GUI_SIMPLE_TREE. When the control is instantiated, a reference to the required container control is passed to the parameter PARENT of the constructor. The container may be an instance of the class CL_GUI_CUSTOM_CONTAINER, but can also be an instance of one of the other containers.

Control Methods

For information about control methods and their documentation, see the class definitions in Class Builder or the SAP Library documentation. To minimize the network load between the application and presentation servers, method calls are buffered in the automation queue before being sent to the presentation server at defined synchronization points. One of the automatic synchronization points is the end of PBO processing. A synchronization point can be forced in the program by using non-buffered method calls or by calling the static method FLUSH from the global class CL_GUI_CFW in Control Framework.

Control Events

Unlike dynpros, where user interaction triggers the PAI event and control is passed to the application server, user interaction on controls is not automatically passed back to the application server. If an event is to be passed back to the application server, it must be registered in the program using the special method SET_REGISTERED_EVENTS from the class of the control. For a list of the events that can be registered for each control, see to its wrapper class in Class Builder. Two kinds of event handler can be defined using SET_REGISTERED_EVENTS:

Handling as System Events (Default)

The event is passed to the application server, but does not trigger the PAI. If an event handler method is registered in the associated ABAP program for the event (using the statement SET HANDLER), this method is executed on the application server.

Within the event handler method, the static method SET_NEW_OK_CODE of the global class CL_GUI_CFW is used to set a function code and trigger the PAI event in a program-driven way and pass any function code. After PAI processing, the PBO event of the next screen is triggered.

The advantage of using this technique is that the event handler method is executed automatically and there are no conflicts with the automatic input checks associated with the dynpro. One drawback, however, is that the contents of the remaining dynpro fields are not transported to the program automatically, which means that obsolete values could appear on the next screen. A workaround for this is to use the SET_NEW_OK_CODE method to trigger a field transport after the event handler has finished.

Handling as Application Events

The event is passed to the application server and triggers the PAI. The function code passed contains an internal identifier. This does not have to be evaluated in the ABAP program. Instead, if the event is to be handled, a method call must be included in a PAI dialog module for the static method DISPATCH of the global class CL_GUI_CFW. If an event handler method is defined in the ABAP program for the event (using the statement SET HANDLER ), the DISPATCH method calls it. After the event is handled, control is passed to the PAI event after the DISPATCH method call and PAI processing continues.

The advantage of this is that the point at which the event is handled can be specified and the contents of the dynpro fields are transported to the application server beforehand. One drawback, however, is that this kind of event handling can produce conflicts with the automatic input checks on the dynpro, causing events to be lost.

Custom Controls (12)

More Information

For further information about controls, and in particular help on troubleshooting and optimizing synchronization, see BC Controls Tutorial and

BC - SAP Control Framework.

Example

The following example shows the difference between system events and application events.

REPORT demo_custom_control .* Declarations *****************************************************CLASS event_handler DEFINITION. PUBLIC SECTION. METHODS: handle_f1 FOR EVENT f1 OF cl_gui_textedit IMPORTING sender, handle_f4 FOR EVENT f4 OF cl_gui_textedit IMPORTING sender.ENDCLASS.DATA: ok_code LIKE sy-ucomm, save_ok LIKE sy-ucomm.DATA: init, container TYPE REF TO cl_gui_custom_container, editor TYPE REF TO cl_gui_textedit.DATA: event_tab TYPE cntl_simple_events, event TYPE cntl_simple_event.DATA: line(256) TYPE c, text_tab LIKE STANDARD TABLE OF line, field LIKE line.DATA handle TYPE REF TO event_handler.* Reporting Events ***************************************************START-OF-SELECTION. line = 'First line in TextEditControl'. APPEND line TO text_tab. line = '--------------------------------------------------'. APPEND line TO text_tab. line = '...'. APPEND line TO text_tab. CALL SCREEN 100.* Dialog Modules *****************************************************MODULE status_0100 OUTPUT. SET PF-STATUS 'SCREEN_100'. IF init is initial. init = 'X'. CREATE OBJECT:  container EXPORTING container_name = 'TEXTEDIT', editor EXPORTING parent = container, handle. event-eventid = cl_gui_textedit=>event_f1. event-appl_event = ' '. "system event APPEND event TO event_tab. event-eventid = cl_gui_textedit=>event_f4. event-appl_event = 'X'. "application event APPEND event TO event_tab. CALL METHOD: editor->set_registered_events EXPORTING events = event_tab. SET HANDLER handle->handle_f1 handle->handle_f4 FOR editor. ENDIF. CALL METHOD editor->set_text_as_stream  EXPORTING text = text_tab.ENDMODULE.MODULE cancel INPUT. LEAVE PROGRAM.ENDMODULE.MODULE user_command_0100 INPUT. save_ok = ok_code. CLEAR ok_code. CASE save_ok. WHEN 'INSERT'. CALL METHOD editor->get_text_as_stream  IMPORTING text = text_tab. WHEN 'F1'. MESSAGE i888(sabapdocu) WITH text-001. WHEN OTHERS. MESSAGE i888(sabapdocu) WITH text-002. CALL METHOD cl_gui_cfw=>dispatch. ENDCASE. SET SCREEN 100.ENDMODULE.* Class Implementations **********************************************CLASS event_handler IMPLEMENTATION. METHOD handle_f1. DATA row TYPE i. MESSAGE i888(sabapdocu) WITH text-003. CALL METHOD sender->get_selection_pos IMPORTING from_line = row. CALL METHOD sender->get_line_text EXPORTING line_number = row IMPORTING text = field. CALL METHOD cl_gui_cfw=>set_new_ok_code  EXPORTING new_code = 'F1'.  CALL METHOD cl_gui_cfw=>flush. ENDMETHOD. METHOD handle_f4. DATA row TYPE i. MESSAGE i888(sabapdocu) WITH text-004. CALL METHOD sender->get_selection_pos IMPORTING from_line = row. CALL METHOD sender->get_line_text EXPORTING line_number = row IMPORTING text = field. CALL METHOD cl_gui_cfw=>flush. ENDMETHOD.ENDCLASS. 

The layout of dynpro 100 is:

Custom Controls (13)

The dynpro contains an output field field and a custom control called textedit.

The flow logic of dynpro 100 is:

PROCESS BEFORE OUTPUT. MODULE status_0100.PROCESS AFTER INPUT. MODULE cancel AT EXIT-COMMAND. MODULE user_command_0100. 

The GUI status SCREEN_100 has the functions BACK, EXIT, and CANCEL (all with type E) and the function INSERT (normal function).

There is a local class event_handler defined in the program. It contains event handler methods for the F1 and F4 events of global class CL_GUI_TEXTEDIT. When the program is executed, objects of the classes CL_GUI_CUSTOM_CONTROL, CL_GUI_TEXTEDIT, and event_handler are instantiated at PBO of dynpro 100.

The container control is associated with the custom control on the dynpro and the instance of the textedit control is associated with this container. The F1 and F4 events of the textedit control are registered using the SET_REGISTERED_EVENTS method to ensure that they are passed to the application server when they occur. F1 is defined as a system event and F4 as an application event. The event handler methods of the handle instance of the class event_handler are registered as handlers for the events.

Before dynpro 100 is displayed, the textedit control is filled with the contents of table text_tab . The user can edit the text while the dynpro is being displayed. If the user chooses INSERT, the PAI event is triggered and the current text from the textedit control is passed to table text_tab.

If the user chooses F1 on the textedit control, the handle_f1 method is executed. This assigns the contents of the line to the field field: The method SET_NEW_OK_CODE triggers the PAI event. This is the only way to ensure that the PBO is processed and the contents of field are sent to the dynpro.

If the user chooses F4 on the textedit control, the PAI event is triggered. The DISPATCH method is called and triggers the method handle_f 4. This assigns the contents of the line to the field field: Since the PAI processing continues after the event, the PBO event follows, and the field contents are sent.

The contents of the textedit control are not passed to the internal table text_tab either after F1 or after F4. The contents of the textedit control are therefore overwritten in the PBO event with the previous contents of text_tab.

Custom Controls (2024)

FAQs

Why would you use custom controls 2 correct answers? ›

Custom controls can be used in a wide range of applications. Custom controls allow developers to construct controls that may be applied to a wide variety of applications. It is perfect for developing UI factors that can be used in a variety of operations.

What do you mean by custom control? ›

Customs control is the process where Customs inspects, verifies and examines inward and outward means of transport, goods, personal articles as well as mails and parcels according to the law to ensure the implementation of national laws and regulations concerning entry and exit of means of transport, goods, personal ...

Why custom control is important? ›

Customs controls are necessary in order to protect citizens and society against illegal drugs, defective goods, dangerous substances and hazardous materials, etc., as well as to preserve the environment and cultural heritage.

What is custom control in UID? ›

Custom Control refers to a user interface component designed specifically to fulfill a unique requirement or functionality that isn't provided by the built-in controls within a given programming environment. These controls enhance the user experience by offering greater customization and flexibility to the developer.

What is difference between user and custom control? ›

A user control is a composition of existing controls while a custom control is a control derived from one base control. This might be better in stackoverflow btw.

What is the difference between user controls and custom controls in asp net? ›

User controls are good for static layout whereas custom controls are good for dynamic layout. User controls are easier to create in comparison to custom controls, however user controls can be less convenient to use in advanced scenarios.

What is an example of customs control? ›

Customs control, for example: duties and taxes to be paid, and the correct classification of the goods, their origin and value; security and safety requirements (counterfeited products, fight against terrorism, smuggling, etc.);

What is a custom example? ›

Examples of it are:

Ceremonies is a class of customary, collective action. In some countries bowing to older people is polite and respectful. In some countries it is okay to burp while eating food. In some countries you take your shoes off before entering the house. In some places they sit on the floor and eat.

What is a custom give an example? ›

A custom is defined as a cultural idea that describes a regular, patterned behavior that is considered characteristic of life in a social system. Shaking hands, bowing, and kissing—all customs—are methods of greeting people. The method most commonly used in a given society helps distinguish one culture from another.

What is the purpose of custom? ›

Customs is an authority or agency in a country responsible for collecting tariffs and for controlling the flow of goods, including animals, transports, personal effects, and hazardous items, into and out of a country.

What are the customs principles? ›

We are governed by five principles, namely: Legality; Reducing bureaucracy; Administrative decentralization; Organizational flexibility; and Valuing human resources.

What is the role of customs and border control? ›

With more than 60,000 employees, U.S. Customs and Border Protection, CBP, is one of the world's largest law enforcement organizations and is charged with keeping terrorists and their weapons out of the U.S. while facilitating lawful international travel and trade.

What is a user control? ›

A user control is a collection of Windows Forms controls encapsulated in a common container. This kind of control is referred to as a composite control. The contained controls are called constituent controls. User controls derive from the UserControl class. User controls are designed like Forms, with a visual designer.

What are the three golden rules of UID? ›

The golden rules are divided into three groups: Place Users in Control. Reduce Users' Memory Load. Make the Interface Consistent.

Why is user control used? ›

User controls are substantially easier to create than custom controls, because you can reuse existing controls. They make it particularly easy to create controls with complex user interface elements.

In which of the following scenarios the custom control is used? ›

Custom controls are used in following scenarios, If the control doesn't exist and you have to create it from scratch. If you want to extend or add functionality to a preexisting control by adding an extra property or an extra functionality to fit your specific scenario.

What are the two ways of placing controls on a form? ›

Answer: To place controls on form, select them in the Toolbox and then draw, on the form, the rectangle in which the control will be enclosed.

What is custom control in VB net? ›

What Does Custom Control Mean? Custom control is a control that is not included in the . NET framework library and is instead created by a third-party software vendor or a user. Custom control is a concept used while building both Windows Forms client and ASP.NET Web applications.

Top Articles
Latest Posts
Article information

Author: Manual Maggio

Last Updated:

Views: 6801

Rating: 4.9 / 5 (69 voted)

Reviews: 84% of readers found this page helpful

Author information

Name: Manual Maggio

Birthday: 1998-01-20

Address: 359 Kelvin Stream, Lake Eldonview, MT 33517-1242

Phone: +577037762465

Job: Product Hospitality Supervisor

Hobby: Gardening, Web surfing, Video gaming, Amateur radio, Flag Football, Reading, Table tennis

Introduction: My name is Manual Maggio, I am a thankful, tender, adventurous, delightful, fantastic, proud, graceful person who loves writing and wants to share my knowledge and understanding with you.