Creating a Control: SAP Picture Example
Use
Prerequisites
The following process applies to all SAP custom controls. The programming examples use the SAP Picture Control. The programming examples use the SAP Picture Control.
However, to apply the example to other controls, you would only have to change the name of the control class. The SAP Container documentation contains details of further scenarios.
Process
-
Create the Instance
-
Define a reference variable for the Custom Container in which you want to place the custom control (see SAP Container).
DATA container TYPE REF TO cl_gui_custom_container.
-
Define a reference variable for the SAP Picture:
DATA picture TYPE REF TO cl_gui_picture.
-
Create the Custom Container. You must already have created the area 'CUSTOM' for the Custom Container in the Screen Painter. When you create the container, you must also specify its lifetime (method constructor).
CREATE OBJECT container EXPORTING container_name = 'CUSTOM' lifetime = lifetime.
-
Create the SAP Picture Control. You can also define a lifetime for this. However, the lifetime must not be longer than its container.
CREATE OBJECT picture EXPORTING parent = container lifetime = lifetime.
-
-
Register the Events
-
There are three steps: Registering the events with the Control Framework, defining a handler method, and registering the hander method. These steps are explained under Registering and Processing Events.
-
-
Use the Control
-
These steps are control-specific and therefore not described here.
-
-
Destroy the Control
The Lifetime Management is normally responsible for destroying any controls you use. However, if you want to destroy the controls manually in your program, you must proceed as follows:
-
Use the method free to destroy the Custom Control at the front end. If you do not need the control container any more, destroy it as well:
CALL METHOD picture->free EXCEPTIONS cntl_error = 1 cntl_system_error = 2. CALL METHOD container->free EXCEPTIONS cntl_error = 1 cntl_system_error = 2.
-
Delete the reference variables to the custom control and the control container.
FREE PICTURE. FREE CONTAINER.
-