Entering content frame

Process documentationCreating a Control: SAP Picture Example Locate the document in its SAP Library structure

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

  1. Define a reference variable for the Custom Container in which you want to place the custom control ( see Structure link SAP Container).
  2. DATA container TYPE REF TO cl_gui_custom_container.

  3. Define a reference variable for the SAP Picture:
  4. DATA picture TYPE REF TO cl_gui_picture.

  5. 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 Structure link lifetime (see Structure link constructor).
  6. CREATE OBJECT container
        EXPORTING container_name = 'CUSTOM'

                  lifetime       = lifetime.

  7. Create the SAP Picture Control. You can also specify a lifetime for the SAP Picture, but it must not be longer than that of its container.
  8. CREATE OBJECT picture
         EXPORTING parent  = container

                  lifetime = lifetime.

    Register the Events

  9. 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.
  10. Use the Control

  11. These steps are control-specific and therefore not described here.
  12. Destroy the Control

    The Structure link lifetime management is normally responsible for destroying any controls you use. However, the following two steps allow you to destroy the control yourself:

  13. Use the method free to destroy the Custom Control at the frontend. If you no longer need the control container, release it as well:
  14. CALL METHOD picture->free
          EXCEPTIONS cntl_error        = 1
                     cntl_system_error = 2.
    CALL METHOD container->free
          EXCEPTIONS cntl_error        = 1
                     cntl_system_error = 2.

    Caution

    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.

  15. Delete the reference variables to the custom control and the control container.

FREE PICTURE.
FREE CONTAINER.

Leaving content frame