0% found this document useful (0 votes)
93 views

ALV Using OOP

The ALV Grid control is a flexible tool for displaying lists in ABAP. It provides functions like sorting, filtering, and summing. When using the ALV Grid control, the basic components to prepare include the list data in an internal table, a field catalog defining display specifications for each column, a layout structure for general display options, and an event handler class to handle events. The example program demonstrates how to create an ALV Grid control, populate it with sample data, and display it on a screen.

Uploaded by

Avinash Jha
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
93 views

ALV Using OOP

The ALV Grid control is a flexible tool for displaying lists in ABAP. It provides functions like sorting, filtering, and summing. When using the ALV Grid control, the basic components to prepare include the list data in an internal table, a field catalog defining display specifications for each column, a layout structure for general display options, and an event handler class to handle events. The example program demonstrates how to create an ALV Grid control, populate it with sample data, and display it on a screen.

Uploaded by

Avinash Jha
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 8

ALV display

Advanced List Viewer

The ALV Grid control is a flexible tool for displaying lists.


The ALV Grid control is used to build non-hierarchical, interactive, and modern-design lists.
The ALV Grid control provides typical list functions as sorting, filtering, summing, etc.,
while also gives the opportunity to develop user functions where needed.
It presents numerous interfaces like Excel Inplace and Crystal Reports.
The wrapper class implemented to encapsulate ALV Grid functionality is
"CL_GUI_ALV_GRID".

While preparing a list to be displayed via an ALV grid control, we have some basic components
to prepare. These are;
i. List data: Obviously, this is the data in an internal table to be listed. Standard ALV functions
except sorting makes just read access to the list data. However, sorting changes state of the
internal table. The internal table holding list data may be of any flat type. Deep types are only
allowed when set for some functionalities of ALV Grid.
ii. Field Catalog: We use another internal table to define specifications on how the fields of our
list will be displayed. This internal table is called the
"field catalog". The field catalog must comprise some technical and additional information about
display options for each column to be displayed. There are three procedures to generate the field
catalog as "Automatic generation", "Semi-automatic generation", and "Manual
generation". The internal table for the field catalog must be referenced to the dictionary type
"LVC_T_FCAT".
iii. Layout Structure: We fill a structure to specify general layout options for the grid. With this
structure we can set general display options, grid customizing, totals options, color adjustments
etc... The layout structure must be of type "LVC_S_LAYO".
iv. Event Handler: We should define and implement an event handler class if we want to handle
events triggered by the ALV Grid instance. After creating ALV Grid instance, we must register an
instance of this event handler class to handle ALV Grid events.
v. Additional Data: To trigger some additional features of ALV Grid we can have some additional
data to pass as parameters. For example, initial sorting criteria, buttons to be deactivated

Now lets start with a simple example program .

Step 1.
Create an object of class CL_GUI_CUSTOM_CONTAINER.

Step 2.
Create an object of class CL_GUI_ALV_GRID.

Step 3.
Populate the internal table that you want to display on the GRID.
Step 4.
Call the screen that contains the CUSTOM CONTAINER, in which you want to display the
list .

Call the screen.

Create a custom container.

flow logic

Step 5.
Call the method SET_TABLE_FOR_FIRST_DISPLAY of class CL_GUI_ALV_GRID and pass
the required parameters.

Program:

DATA:
T_SFLIGHT TYPE TABLE OF SFLIGHT,
FS_SFLIGHT TYPE SFLIGHT.
DATA:
R_CONTAINER TYPE REF TO CL_GUI_CUSTOM_CONTAINER,
R_GRID TYPE REF TO CL_GUI_ALV_GRID.
SELECT * FROM SFLIGHT INTO TABLE T_SFLIGHT.
CALL SCREEN 100.
&---------------------------------------------------------------------
*& Module STATUS_0100 OUTPUT
&---------------------------------------------------------------------
text
----------------------------------------------------------------------
MODULE STATUS_0100 OUTPUT.
SET PF-STATUS 'SCREEN1'.
SET TITLEBAR 'TITLE1'.ENDMODULE. " STATUS_0100 OUTPUT
&---------------------------------------------------------------------
*& Module USER_COMMAND_0100 INPUT
&---------------------------------------------------------------------
text
----------------------------------------------------------------------
MODULE USER_COMMAND_0100 INPUT.
CASE SY-UCOMM.
WHEN 'BACK'.
LEAVE TO SCREEN 0.
ENDCASE.
ENDMODULE.&-------------------------------------------------------------------
--
*& Module LIST OUTPUT
&---------------------------------------------------------------------
text
----------------------------------------------------------------------
MODULE LIST OUTPUT.
CREATE OBJECT R_CONTAINER
EXPORTING
CONTAINER_NAME = 'CONTAINER'.CREATE OBJECT R_GRID
EXPORTING
I_PARENT = R_CONTAINER.
CALL METHOD R_GRID->SET_TABLE_FOR_FIRST_DISPLAY
EXPORTING
i_structure_name = 'SFLIGHT'
CHANGING
IT_OUTTAB = T_SFLIGHT.
ENDMODULE.

Creating DYNAMIC FIELD CATALOG.

You can change the field catalog during runtime .


To achieve this you can use the method 'get_frontend_fieldcatalog',
of class 'cl_gui_alv_grid'.

Step 1.

Create an internal table of type LVC_T_FCAT.

Step 2.

Call method 'get_frontend_fieldcatalog' of class cl_gui_alv_grid


and populate the field catalog using the parameter 'et_fieldcatalog' .
This parameter will give you the field catalog of the current displayed
screen.

Step 3.

Now loop at the field catalog and make the required changes.

Step 4.

Call the method 'set_table_for_first_display' and pass the field catalog.

Example:
In this example ,SLFIGHT details will be displayed first and if you press
the push button on the screen(SWITCH) ,SFLIGHT details will be displayed
with changes like 1. OUTPUT LENGTH OF CONNID WILL BE CHANGED.
2. FIELD PLANETYPE WILL BE HIDDEN.
3. GRAND TOTAL OF FIELD PRICE WILL BE CALCULATED.

REPORT zalv_dynamic_fieldcatalog.
DATA:
t_sflight TYPE TABLE OF sflight,
fs_sflight TYPE sflight.
DATA:
r_container TYPE REF TO cl_gui_custom_container,
r_grid TYPE REF TO cl_gui_alv_grid.
DATA:
t_fcat TYPE lvc_t_fcat,
fs_fcat TYPE lvc_s_fcat.
SELECT * FROM sflight INTO TABLE t_sflight.
CALL SCREEN 100.
*&---------------------------------------------------------------------
*& Module STATUS_0100 OUTPUT
*&---------------------------------------------------------------------

MODULE status_0100 OUTPUT.


SET PF-STATUS 'SCREEN'.
SET TITLEBAR 'SFLIGHT DETAILS'.
ENDMODULE. " STATUS_0100 OUTPUT
*&---------------------------------------------------------------------
*& Module USER_COMMAND_0100 INPUT
*&---------------------------------------------------------------------
MODULE user_command_0100 INPUT.
CASE sy-ucomm.
WHEN 'BACK'.
LEAVE TO SCREEN 0.
WHEN 'SWITCH'.
CALL METHOD r_grid->get_frontend_fieldcatalog
IMPORTING
et_fieldcatalog = t_fcat.
LOOP AT t_fcat INTO fs_fcat.
CASE fs_fcat-fieldname.
WHEN 'CONNID'.
fs_fcat-outputlen = '10'.
MODIFY t_fcat FROM fs_fcat.
WHEN 'PLANETYPE'.
fs_fcat-no_out = 'X'.
MODIFY t_fcat FROM fs_fcat.
WHEN 'PRICE'.
fs_fcat-do_sum = 'X'.
MODIFY t_fcat FROM fs_fcat.
ENDCASE.
ENDLOOP.
CALL METHOD r_grid->set_table_for_first_display
CHANGING
it_fieldcatalog = t_fcat
it_outtab = t_sflight.
ENDCASE.
ENDMODULE. "user_command_0100 INPUT
*&---------------------------------------------------------------------
*& Module list OUTPUT
*&---------------------------------------------------------------------
MODULE list OUTPUT.
CREATE OBJECT r_container
EXPORTING
container_name = 'CONTAINER'.
CREATE OBJECT r_grid
EXPORTING
i_parent = r_container.
CALL METHOD r_grid->set_table_for_first_display
EXPORTING
i_structure_name = 'SFLIGHT'
CHANGING
it_outtab = t_sflight.
ENDMODULE. " HANDLER OUTPUT

Field catalog options :

FIELDNAME:
You use this field to assign a field name of your output table to a row of the field catalog. All
settings that you make in this row refer to the corresponding column of the output table.
REF_FIELD:
You must fill this field if:
• the output table field described by the current entry in the field catalog has a corresponding
field in the Data Dictionary and
• the field name in the output table is not identical to the field name of the field in the Data
Dictionary.
If the field names are identical, it is sufficient to specify the DDIC structure or table in field
REF_TABLE of the field catalog.
REF_TABLE:
You must fill this field only if the output table field described by the current entry in the field
catalog has a corresponding entry in the Data Dictionary. Using this assignment, the ALV Grid
Control can copy the text for the column header from the Dictionary.
CHECKBOX:
Outputting a checkbox. The checkbox cannot be modified by the user.
COL_POS:
Relevant only if the relative column positions should not be identical to the sequence of fields in
the field catalog when the list is displayed for the first time. The parameter determines the
relative column position of the field for list output. The user can interactively modify the order of
the columns. If this parameter is initial for each field catalog entry, the order of the columns
corresponds to the sequence of fields in the field catalog.
DO_SUM:
If this field is set, the ALV uses this field to calculate the total (this corresponds to the generic
totals function in the toolbar.)
EMPHASIZE:
If the field is set to 'X', the ALV uses a pre-defined color for highlighting the column. If it is set
to 'Cxyz' (color code), the remaining numbers have the following meaning:
• x: color number
• y: intensified display on/off
• z: inverse display on/off
HOTSPOT:
If this field is set, all cells of this column are hotspot-sensitive.
HREF_HNDL:
Handle to which an URL is assigned. The ALV Grid Control displays all cells of the column as
hyperlinks. You must maintain the target address of the hyperlink in a table of type
LVC_T_HYPE and pass it using set_table_for_first_display.
KEY:
If this field is set, the ALV Grid Control color-codes the column as a
key field and fixes this column during horizontal scrolling. The order of the key columns in the
ALV Grid Control can be modified interactively. In contrast to the SAP List Viewer, the ALV
Grid Control allows you to directly hide key columns with NO_OUT
LOWERCASE:
If this field is set, the ALV Grid Control recognizes upper/lower case in the output table. This
affects the sorting of fields, for example.
NO_OUT:
If you set this field, you hide the relevant column in the list. Nevertheless, the column is
available in the field selection and can be interactively selected by the user as a display field. The
ALV displays the contents of hidden fields on the detail screen for a row in the grid control.
NO_MERGING:
If this field is set, cells with the same value are not merged into a single cell when this column is
sorted.
NO_SUM:
If you set this field, you lock totals calculation for the relevant field.
OUTPUTLEN:
Determines the column width of the field:
• If the field has a reference to the Data Dictionary, you can leave the field set to its initial value.
In this case, the ALV adopts the output length of the relevant domain.
• For fields without reference to the DDIC, you must specify the desired field output length.
STYLE:
Displays all cells of this column with a style e.g. as pushbuttons. Constants "MC_STYLE..." of
the class "cl_gui_alv_grid" can be passed to this field.
TECH:
If this field is set, the relevant field is not displayed on the list and cannot be shown interactively.
The field is only known in the field catalog. (For example, it must not be specified as a sorting
criterion).
DECIMALS_O:
If a field has no currency, then you can use this field to determine the number of decimal places
to be displayed. This setting is kept even if you afterwards assign a currency field to this field or
assign a currency to the CURRENCY field of the field catalog.
DECMFIELD:
Defining the digits after the comma on a row-by-row basis. You can use an additional field in the
output table to determine how many digits are to be displayed after the comma in each row.
EDIT_MASK:
If you set a conversion exit (for example, conv = ' ==ALPHA ' for function module
CONVERSION_EXIT_ALPHA_OUTPUT ), you enforce output conversion for the associated
output field.
ICON:
If this field is set, the column contents of the output table are output as an icon. The column
contents must consist of valid icon strings ( (xx) or @xx\Q <Quickinfo> @ ). You should
consider the problem of printing icons.
JUST:
Relevant only to fields of data type CHAR or NUMC. Justifications:
• 'R': right justified
• 'L': left justified
• 'C': centered
How the column header is justified, depends on how the column contents are justified. You
cannot justify the column header separately.
LZERO:
Relevant only to fields of data type NUMC. In the default setting, the
ALV Grid Control displays these fields right justified without leading zeros. If you set LZERO,
leading zeros are displayed.
NO_SIGN:
Relevant only to value fields. If you set NO-SIGN, values are displayed without signs.
NO_ZERO:
If NO_ZERO is set, no zeros are displayed for initial value fields. The cell remains empty.
COLDDICTXT:
Relevant only to fields with reference to the Data Dictionary. You use values 'L', 'M', 'S' or 'R' to
determine if SCRTEXT_L, SCRTEXT_M, SCRTEXT_S or REPTEXT is used as the column
header.
COLTEXT:
Determines the column header of the column. You should assign a value to this field if it does not
have a Data Dictionary reference.
REPTEXT:
Relevant only to fields with reference to the Data Dictionary. For such fields, the ALV Grid
Control copies the field label for the header of the corresponding data element into this field.
SCRTEXT_L:
Relevant only to fields with reference to the Data Dictionary. For such fields, the ALV Grid
Control copies the long field label of the corresponding data element into this field.
SCRTEXT_M:
Relevant only to fields with reference to the Data Dictionary. For such fields, the ALV Grid
Control copies the medium field label of the corresponding data element into this field.
SCRTEXT_S:
Relevant only to fields with reference to the Data Dictionary. For such fields, the ALV Grid
Control copies the short field label of the corresponding data element into this field.
SELDDICTXT:
Relevant only to fields with reference to the Data Dictionary. You use values 'L', 'M', 'S' or 'R' to
determine if SCRTEXT_L, SCRTEXT_M, SCRTEXT_S or REPTEXT is used as the text for
column selection.
SELTEXT:
Determines the text to be used in the column selection for the column. You should assign a value
to this field if it does not have a Data Dictionary reference.
TIPDDICTXT:
Relevant only to fields with reference to the Data Dictionary. You use values 'L', 'M', 'S' or 'R' to
determine if SCRTEXT_L, SCRTEXT_M, SCRTEXT_S or REPTEXT is used as the tool tip.
TOOLTIP:
Determines the text to be used as the tool tip for the column. You should assign a value to this
field if it does not have a Data Dictionary reference.

Check :

https://help.sap.com/saphelp_nw70/helpdata/en/ef/a2e9eff88311d2b48d006094192fe3/frameset.htm

For more details

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy