SAP Grid Control and Containers
SAP Grid Control and Containers
Contents:
SAP Grid Control - Standard Application
Preview of Other Techniques
SAP AG 2002
SAP AG 2002
SAPGrid
SAP Grid Control:
Control: Simple
Simple Application
Application
MoreComplex
More ComplexTechniques
Techniques
Outlook
Outlook
SAP AG 2002
SAP AG 2002
If custom controls are to be included on the frontend, then the SAPGUI acts as a container for them.
Custom controls can be ActiveX Controls or JavaBeans.
The system uses a Remote Function Call (RFC) to transfer methods for creating and using a control
to the front end.
ABAP objects are used to implement the controls in programs.
An SAP Container can contain other controls (for example, SAP Grid Control, Tree Control, SAP
Picture Control, SAP Splitter Control, and so on). The SAP Container administers these controls
logically in one collection and provides a physical area for the display.
Every control exists in a container. Since containers are themselves controls, they can be nested
within one another. The container becomes the parent of its control. SAP containers are divided into
five groups:
SAP custom container: Displays within an area defined in Screen Painter on screens or subscreens.
Class: CL_GUI_CUSTOM_CONTAINER
SAP dialog box container: Displays in a modeless dialog box or as a full screen. Class:
CL_GUI_DIALOGBOX_CONTAINER
SAP docking container: Displays as docked, resizable sub-window with the option of displaying it as
a modeless dialog box. Class: CL_GUI_DOCKING_CONTAINER
SAP splitter container: Displays and groups several controls in one area - that is, splits the area into
cells Class: CL_GUI_SPLITTER_CONTAINER
SAP easy splitter container: Displays controls in two cells, which the user can resize using a split bar.
Class: CL_GUI_EASY_SPLITTER_CONTAINER.
Toolbar
SAP AG 2002
Within the control, you can manually make the columns wider and narrower or use the AutoFit
function. You can also rearrange the columns by dragging a selected column to the new position.
Standard functions are available in the control toolbar. The detailed display appears as a modal
dialog box containing all the fields in the row (including hidden ones) at the current cursor position.
The ALV control supports the Sort function for any number of columns. You can define complex sort
criteria and sort the columns in ascending or descending order.
You can use the Find function to search for a string in rows or columns within a selected area
(wildcard search does not require *).
You can calculate totals for one or more numerical columns. You can then use the Subtotals function
to set up control level lists. Select the columns (non-numeric fields only) to calculate and the system
displays the appropriate control level totals.
When you print or download, the system always processes the complete list, not just the displayed
screen sections.
You can define display variants to meet your own specific requirements. Saving variants: See Other
Techniques
Collect data in
SELECT ... an internal table
QuickView
SAP AG 2002
The SAP grid control is a generic tool for displaying lists in screens. The control offers standard
functions such as sorting by any column, adding numeric columns, and fixed lead columns
Data collection is performed in the program using SELECT statements or GET eventsse. The data
records are saved in an internal table and passed on to the SAP control along with a field description.
The field description contains information about the characteristics of each column, such as the
column header and output length. This information can defined either globally in the Dictionary
(structure in the Dictionary) or in the field catalog in the program itself. You can also merge both
techniques.
The SAP link is a standard function of Query and QuickViewer. If multiline queries or QuickView
lists have been defined, they will automatically compress into a single line and output in the SAP
control as a long, single line list.
CL_GUI_OBJECT
CL_GUI_CONTROL
CL_GUI_ALV_GRID_BASE
CL_GUI_ALV_GRID
SAP AG 2002
SAP AG 2002
Use Screen Painter to create a container for the SAP grid control. The control requires an area where
it can be displayed in the screen. You have to create a container control that determines this area.
Use the corresponding icon in the Screen Painter layout to create the container control. The size of
area MY_CONTROL_AREA determines the subsequent size of the SAP control.
A dialog status with the standard BACK, EXIT, and CANCEL functionality must be set during the
PBO event. You must also add the necessary coding for these function codes in the PAI event.
SAP AG 2002
The reference variables for the custom container and the ALV grid control must be declared.
To create reference variables, use ABAP statement TYPE REF TO <class name>.
The global classes you need to do this are called cl_gui_custom_container (for the custom container
control) and cl_gui_alv_grid (for the SAP grid control).
The global classes are defined in the Class Builder. You can use the Class Builder to display
information for the methods, their parameters, exceptions, and so on.
IF g_custom_container IS INITIAL.
CREATE
CREATE OBJECT
OBJECT g_custom_container
EXPORTING container_name = 'MY_CONTROL_AREA'.
CREATE
CREATE OBJECT
OBJECT sap_grid C
EXPORTING i_parent = g_custom_container.
ENDIF.
SAP AG 2002
Use ABAP statement CREATE OBJECT <name> to create the objects for the container and the
ALV control. Objects are instances of a class.
When an object is created (CREATE), method CONSTRUCTOR of the corresponding class is
executed. The parameters of method CONSTRUCTOR determine which parameters have to be
supplied with data when the object is created. In the above example, object sap_grid is given the
name of the container control (g_custom_container) in exporting parameter i_parent,
which links the two controls. For information on which parameters method CONSTRUCTOR
possesses and which of these parameters are required, see the Class Builder.
Objects should only be created once during the program. To ensure that this is the case, enclose the
CREATE OBJECT statement(s) in an IF <object_name> IS INITIAL. ... ENDIF
clause. The objects must be generated before the control is displayed for the first time - that is,
during the PBO event of the ALV subscreen container.
START-OF-SELECTION
Internal table with data Description of columns
itab_sflight Field catalog DIC
A B C sflight
SELECT * FROM A A B C
sflight ... B
C
MODULE transfer_data.
SAP AG 2002
To display the requested dataset in the SAP Grid Control, the data must be passed on to the control as
an internal table, and a field description must exist indicating the order in which the columns will be
output.
In the simplest case, the field description can use a structure from the Dictionary. The Dictionary also
determines the technical field attributes like type and length, as well as the semantic attributes like
short and long texts. The SAP Grid Control uses this information to determine the column widths and
headers. The column sequence is determined by the field sequence in the structure.
If no suitable structure is active in the Dictionary, or you want to output internal program fields in the
control, then you will have to define information like the output length and column header in the
field catalog.
In a typical report application, the data is read first using SELECT...INTO TABLE or using a
logical database and then APPEND/INSERT the data into an internal table. When the data retrieval
is complete, the ABAP statement CALL SCREEN <number> is used to call the screen containing
the SAP Grid Control.
MODULE status_0100.
MODULE create_objects.
MODULE transfer_data.
SAP AG 2002
The data transfer to the ALV control takes place during the call of method
set_table_for_first_display from class cl_gui_alv_grid. The method call must be programmed at
the PBO event of the screen with the SAP Grid Control container.
The name of the Dictionary structure that supplies the field description is specified in exporting
parameter i_structure_name. The name of the internal table that contains the data records to
display is specified in changing parameter it_outtab.
SAPGrid
SAP Grid Control:
Control: Simple
Simple Application
Application
MoreComplex
More ComplexTechniques
Techniques
Outlook
Outlook
SAP AG 2002
END OF t_con.
SAP AG 2002
The field description for the SAP Grid Control can be taken from an active Dictionary structure
(fully automatic), by passing a field catalog (manual), or through a mixture of the two options
(merge).
The field catalog is in internal table with type lvc_t_fcat. This type is defined globally in the
Dictionary.
Each line in the field catalog table corresponds to a column in the SAP control.
SAP AG 2002
The field characteristics (= column characteristics) are defined in the field catalog. The field catalog
is in internal table with type lvc_t_fcat. Each line that is explicitly described in the ALV control
corresponds to a column in the field catalog table.
The link to the data records to output that are saved in internal table <outtab> is established through
field name <outtab-field>. This name must be specified in column fieldname in the field catalog.
This field can be classified through a Dictionary reference (ref_table and ref_field) or by specifying
an ABAP data type (inttype).
Column headers and field names in the detail view of an SAP control line can be determined in the
field catalog in coltext and seltext, respectively.
The position of a field during output can be determined with col_pos in the field catalog.
If you want to hide a column, fill field no_out with an X in the field catalog. Hidden fields can be
displayed again in a user display variant.
Icons can be displayed in the SAP control. If you want a column to be interpreted as an icon, then the
icon name must be known to the program (include <icon>.) and icon = X must be specified for this
column in the field catalog.
CLEAR wa_fieldcat.
wa_fieldcat-fieldname = 'FREE_SEATS'.
wa_fieldcat-ref_table = 'SFLIGHT'.
wa_fieldcat-ref_field = 'SEATSMAX'.
wa_fieldcat-coltext = text-001.
wa_fieldcat-seltext = text-001. Fill field catalog
wa_fieldcat-col_pos = pos_free.
APPEND wa_fieldcat TO gt_fieldcat. for additional fields
CLEAR wa_fieldcat.
wa_fieldcat-fieldname = 'ICON_NAME'.
wa_fieldcat-icon = 'X'. " Displayed as Icon
wa_fieldcat-coltext = text-001.
wa_fieldcat-seltext = text-001.
wa_fieldcat-col_pos = pos_icon.
APPEND wa_fieldcat TO gt_fieldcat.
SAP AG 2002
The above example shows a semi-automatic field description: Part of the field description comes
from the Dictionary structure (sflight), while another part is explicitly defined in the field catalog
(gt_fieldcat).
The field catalog (internal table) which fills in the program, passes on together with the name of the
Dictionary structure during the method call. The information merges accordingly in method
set_table_for_first_display.
F1 F2 F3 F4 Z
Data table in the A2 B2 B4 Z
calling program
Display in the
F1 F2 F3 F4 F1 Z F2 F3 F4 A2 B2 B4 Z
SAP Grid Control
Parameter
I_STRUCTURE_NAME
Parameter
IT_FIELDCATALOG
SAP AG 2002
Field catalogs are created in one of the following three ways depending on the line type used by the
data table:
Case 1:
All the fields of the global structure type have an identically-named column in the data table. You
want to display precisely these columns. In this case, you can have the proxy instance generate the
field catalog. You need only pass the name of the global structure type. Data table columns are not
displayed on the screen unless they are defined in the global structure type.
Case 2:
All fields of the global structure type have an identically-named column in the data table, but you
want to adapt the attributes derived from the ABAP Dictionary or you want to add columns or both.
In this case, you need to add lines in the field catalog matching the columns you want to add or
change.
Case 3:
Either there are no Dictionary references in the line type of the data table or there are references only
for some of the global structure fields. In this case, the calling program must generate the field
catalog from scratch.
* Save variants
data: gs_variant type disvariant,
x_save.
CHANGING
it_outtab = gt_outtab
it_fieldcatalog = gt_fieldcat.
SAP AG 2002
For a user to save display variants, parameters is_variant and i_save must be passed on
during method call set_table_for_first_screen. To assign display variants uniquely to a
program, at least the program name must be supplied in the transferred structure (gs_variant).
Program names can be up to 30 characters long.
If you only pass on the current parameters for is_variant, then existing variants can be loaded,
but no new ones can be saved. If you use parameter i_save, you must pass on a variant structure
with is_variant.
I_SAVE = 'X' The user can only save general (shared) variants.
I_SAVE = 'A' The user can save both user-specific and general (shared) variants.
* Layout
DATA: gs_layout TYPE lvc_s_layo.
CHANGING
it_outtab = gt_outtab
it_fieldcatalog = gt_fieldcat.
SAP AG 2002
You can use parameter is_layout of method set_table_for_first_display, for example, to define the
header in the ALV control and the detail display.
To do this, define a query area <gs_layout> in the program in accordance with Dictionary structure
lvc_s_layo, and pass on the text to display in field <gs_layout>-grid_title or <gs_layout>-detailtitl.
If you want to create print lists with zebra stripes, set field <gs_layout>-zebra to X. You can display
a print preview for print lists by requesting standard function Print.
it_special_groups = Groupings
SAPGrid
SAP Grid Control:
Control: Simple
Simple Application
Application
MoreComplex
More ComplexTechniques
Techniques
Outlook
Outlook
SAP AG 2002
SAP AG 2002
If the user double-clicks a data area, the DOUBLE_CLICK event is triggered in the calling
program.
The export parameters contain information about the data table. Note that both parameters are
structures.
E_ROW:
The INDEX field contains the line number in the internal table that belongs to the double-clicked
row in the data area.
E_COLUMN:
The FIELDNAME field contains the name of the column in the internal table that belongs to the
double-clicked cell in the data area.
If a column is characterized as a hot spot, the HOTSPOT_CLICK event is triggered when the user
clicks this column in the data area. The export parameters are filled in a similar way to those of the
DOUBLE_CLICK event.
For further information about other mouse operation events, refer to the online documentation.
DOUBLE_CLICK.
SAP AG 2002
Events are defined in global class cl_gui_alv_grid; you can use these events to implement
user interaction within the program. To respond to a double-click on a table line, you must respond
to event DOUBLE_CLICK.
You receive control in the program, allowing you to implement interactive reporting - such as a full-
screen details list. The events for cl_gui_alv_grid are located in the Class Builder.
Registration of
SET HANDLER sap_dblclick->on_dblclick
handler method
FOR alv_grid.
for event double_click
SAP AG 2002
To define and implement a local class in the program, you use a handler method. In this handler
method, you program the functionality to trigger by a double-click in the output table.
To activate a handler method at runtime, a class or an object from that class registers itself with an
event using command SET HANDLER. The names of the IMPORTING parameters in the handler
method correspond to the names of the EXPORTING parameters of the related event.
In the above example, the local class is LCL_ILS and the handler method is ON_DBLCLICK. An
object - SAP_DBLCLICK - is created and registers itself for event DOUBLE_CLICK.
You can query parameter e_row-index to determine which output line was requested by the double-
click. This parameter corresponds to the line number of the output table (internal table with the data
records to output). If you need information for the selected line, you have to read it with READ
TABLE itab INDEX e_row-index.
This subsequent read in the output table generally corresponds to the HIDE area in conventional
reporting. You first have to make sure that the user has double-clicked a line in the output table
(similar to the valid line selection with the HIDE technique).
SAP AG 2002
As well as these demonstration and test programs, you will also find other Repository objects for the
SAP Grid Control in the SLIS package.
This package is part of the standard SAP R/3 System - that is, it is always delivered with the ABAP
Workbench.
You can also analyze and execute these and other demonstration and test programs in a comfortable
test environment. In the ABAP Workbench, choose Environment Examples Control examples.
SAP AG 2002
When you have completed these exercises, you will be able to:
Use the applications of the ALV grid control
The OK code processing for screen 100 is included in the template (BACK, EXIT,
CANCEL). Do not work in the Screen Painter.
All the necessary program objects are contained in the TOP include.
1-1-1 Familiarize yourself with the program.
2-1 Read data from table SFLIGHT and display the data on screen 100 in an ALV grid
control.
2-1-1 Calculate the number of free seats.
2-1-2 Include the following fields in the ALV control:
carrid, connid, fldate, price, planetype, seatsmax, seatsocc, paymentsum,
free_seats.
Use the method SET_TABLE_FOR_FIRST_DISPLAY of class
CL_GUI_ALV_GRID.
2-1-3 Place the field free_seats in position 10 and make sure that the column
is colored (for example, colour 3, intensified display).
*&---------------------------------------------------------------------*
*& SAPBC405_ALVS_1 *
*& *
*&---------------------------------------------------------------------*
*& *
*& *
*&---------------------------------------------------------------------*
INCLUDE bc405_alvs_1top.
*&---------------------------------------------------------------------*
*& Event START-OF-SELECTION
*&---------------------------------------------------------------------*
START-OF-SELECTION.
SELECT * FROM sflight INTO CORRESPONDING FIELDS OF wa_outtab
WHERE carrid IN so_car.
wa_outtab-free_seats = wa_outtab-seatsmax - wa_outtab-seatsocc.
APPEND wa_outtab TO gt_outtab.
ENDSELECT.
*&---------------------------------------------------------------------*
*& Module EXIT INPUT
*&---------------------------------------------------------------------*
*& Module USER_COMMAND_0100 INPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE user_command_0100 INPUT.
MOVE ok_code TO save_ok_code.
CLEAR ok_code.
CASE save_ok_code.
WHEN 'BACK'.
CALL METHOD g_custom_container->free.
LEAVE TO SCREEN 0.
WHEN 'EXIT'.
CALL METHOD g_custom_container->free.
LEAVE TO SCREEN 0.
ENDCASE.
ENDMODULE. " USER_COMMAND_0100 INPUT
*&---------------------------------------------------------------------*
*& Module CREATE_OBJECTS OUTPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE create_objects OUTPUT.
IF g_custom_container IS INITIAL.
CREATE OBJECT g_custom_container
EXPORTING container_name = 'MY_CONTROL_AREA'.
CHANGING
it_outtab = gt_outtab
it_fieldcatalog = gt_fieldcat.
CLEAR wa_fieldcat.
wa_fieldcat-fieldname = 'FREE_SEATS'.
wa_fieldcat-ref_table = 'SFLIGHT'.
wa_fieldcat-coltext = 'Free seats'(001).
wa_fieldcat-seltext = 'Free seats'(001).
wa_fieldcat-col_pos = pos_free.
wa_fieldcat-emphasize = 'C310'.
*&---------------------------------------------------------------------*
*& Module LAYOUT OUTPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE layout OUTPUT.
*&---------------------------------------------------------------------*
*& Include BC405_ALVS_1TOP *
*& *
*&---------------------------------------------------------------------*
PROGRAM sapbc405_alvs_1 .
* OK code handling
DATA: ok_code LIKE sy-ucomm,
save_ok_code LIKE sy-ucomm.
* Field position
DATA: pos_free TYPE i VALUE 10.
* Fieldcatalog
DATA: gt_fieldcat TYPE lvc_t_fcat,
wa_fieldcat LIKE LINE OF gt_fieldcat.
* CONTROLS
DATA: g_custom_container TYPE REF TO cl_gui_custom_container,
alv_grid TYPE REF TO cl_gui_alv_grid.
* Selection Screen
SELECTION-SCREEN BEGIN OF BLOCK connection WITH FRAME.
SELECT-OPTIONS: so_car FOR wa_outtab-carrid.
SELECTION-SCREEN END OF BLOCK connection.