|
In previous chapter we learned how to create a control area on the screen. In this chapter we will tell you how to create a custom container object and attach it to the control area on the screen. Before we go into creation of containers, lets understand the class hierarchy of the containers. The below diagram shows the hierarchical relationship.
In the above diagram we can see that the container class is inherited from the GUI Control class. This container class is further inherited by the custom container class, docking container etc. To create a instance of the container refer the below code: Create a Container Object: DATA : lref_container TYPE REF TO cl_gui_custom_container. CREATE OBJECT lref_container EXPORTING * parent = container_name = 'MY_AREA' " Name of your control area * style = * lifetime = lifetime_default * repid = * dynnr = * no_autodef_progid_dynnr = EXCEPTIONS cntl_error = 1 cntl_system_error = 2 create_error = 3 lifetime_error = 4 lifetime_dynpro_dynpro_link = 5 OTHERS = 6. You can use the 'Pattern' button on the tool bar to create the instance. Note: Here the variable LREF_CONTAINER is the container where you can attach any SAP control. When you create the instance of the SAP control you will define this as the parent container. Create a SAP control object: Let's say I want to create a picture control object on my screen. Refer to the below code to create a control object. DATA : lref_picture TYPE REF TO cl_gui_picture. CREATE OBJECT lref_picture EXPORTING * lifetime = * shellstyle = parent = lref_container " Name of the parent container created in previous step. * name = EXCEPTIONS error = 1 OTHERS = 2. Here, the parent is defined as the container object that we created in the last step. Now check the methods available on the CL_GUI_PICTURE class. You can use these methods to show a picture on the screen. Tip: You can re-link a custom container. Use the method LINK on the class CL_GUI_CUSTOM_CONTAINER to relink to a separate area on the screen. Few examples to create a container and attach a control:
|