The CREATE OBJECT statement, which includes all parameters and exceptions of the constructor method, is then inserted in the ABAP source code. Optional parameters and exceptions are inserted as comments. In this way, you can avoid typing errors and omissions.
You then complete the actual parameters and program the exception handling.
Insertion of CREATE OBJECT by Drag and Drop
You can also use the drag and drop function of the ABAP Workbench to insert the CREATE OBJECT statement for a global class.
For example, you can display the global class cl_gui_custom_container, in the navigation area and drag it to the editing area. The CREATE OBJECT statement, including the signature and exceptions of the instance constructor, is inserted at the current cursor position in the source code of the program. Optional parameters and exceptions are inserted as comments.
You then need to complete the actual parameters and program the exception handling.
Avoidance of Multiple Generation of Controls
If you package the control-specific processing in a PBO module, ensure that an instance is generated only the first time the dynpro is called. Otherwise, a new object is created every time the dynpro is processed.
You can stop unwanted instances from being created by checking that the container reference (go_container) is initial, before creating the object.
Creation of a GUI Control Instance – Process Flow
The procedure to create an instance of the ALV Grid is similar to the container control instance.
Create the instance of the ALV Grid after the container control instance, but before the SAP GUI window is sent to the presentation server.
Creation of an ALV Grid Instance
To create an ALV Grid instance, you need a reference variable declared with reference to class CL_GUI_ALV_GRID (go_alv_grid is the name of this reference variable in the figure).
Assign a reference to the previously created container control instance to the i_parent parameter in the constructor.
If an error occurs when creating the instance, you must catch the exception. The instance of the ALV Grid is connected to the container and to the container screen using the object reference passed in the interface.
To display the ALV Grid in full screen mode, that is, the control covers the entire screen, assign a value to the i_parent export parameter as follows:
i_parent = cl_gui_custom_container=>screen0.
In this case, you do not require a control area on the screen or a container control.
Screen, Container, and ALV Grid
By following these steps, an ALV Grid as a screen element will be created. However, at this stage only a frame will be displayed in the SAP GUI window, because the controls do not yet display anything. It is now necessary to supply the presentation server controls with data that needs to be displayed.
Release of Control Instances
By default, resources that the control occupies at the presentation server are automatically released at the end of the program. However, you can also explicitly release these resources by calling the free instance method.
Every control wrapper has this free method (inherited from CL_GUI_OBJECT). Call this method in every case in which the presentation server controls are no longer required in the course of your program.
By releasing the object references (ABAP statements CLEAR or FREE), you ensure that the resources for the ABAP Objects instances (representative objects) created in your program are released in memory the next time the garbage collector runs.
Data Display with the ALV Grid Control