Creating a Control: SAP Picture Example
Prerequisites
The following process applies to all SAP custom controls. 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 example also assumes that you are using the custom control in a Custom Container. The SAP Container documentation contains details of further scenarios.
Process Flow
Create the Instance
DATA container TYPE REF TO cl_gui_custom_container.
DATA picture TYPE REF TO cl_gui_picture.
CREATE OBJECT container
EXPORTING container_name = 'CUSTOM'
lifetime = lifetime.
CREATE OBJECT picture
EXPORTING parent = container
lifetime = lifetime.
Register the Events
Use the Control
Destroy the Control
The
lifetime management is normally responsible for destroying any controls you use. However, the following two steps allow you to destroy the control yourself:CALL METHOD picture->free
EXCEPTIONS cntl_error = 1
cntl_system_error = 2.
CALL METHOD container->free
EXCEPTIONS cntl_error = 1
cntl_system_error = 2.
Pay careful attention to the sequence in which you destroy controls at the frontend. When you destroy a container, all controls in it are automatically destroyed as well. If you have already destroyed a control and try to destroy it again, an error occurs. You can check whether a control has already been destroyed using the method
is_alive.FREE PICTURE.
FREE CONTAINER.