You are on page 1of 60

0

ALV Grid Control

Contents:
Features Constructor, methods and events Data descriptions

SAP AG 1999

(C) SAP AG

BC412

5-1

0.2
ALV Grid Control: Unit Objectives

At the conclusion of this unit, you will be able to: Describe the features of the ALV Grid Control Display list data in the ALV Grid Control Read and change properties of the ALV Grid Control Format print lists with the ALV Grid Control Generate a field catalog

SAP AG 1999

(C) SAP AG

BC412

5-2

0.3
Course Overview Diagram BC412

Unit 1

Course Overview

Unit 2

Introduction to the Control Framework

Unit 3

SAP Container

Unit 4

SAP Tree Control

Unit 5

ALV Grid Control

SAP AG 1999

(C) SAP AG

BC412

5-3

0.4
ALV Grid Control Overview: Features

Features Features Method overview Method overview Event overview Event overview The field catalog The field catalog

SAP AG 1999

(C) SAP AG

BC412

5-4

0.5
ALV Grid Control
Properties Display of nonhierarchical lists

Typical list functions:


Air... Flight.. Date Curr... Price 17 2000-01-17 513,69 USD AA 17 2000-02-20 513,69 USD AA 17 2000-03-11 513,69 USD AA 64 2000-05-19 369,00 USD AA 400 2000-01-13 1234,56 DEM LH 400 2000-02-16 1234,56 DEM LH 400 2000-03-21 1234,56 DEM LH 400 2000-03-04 1234,56 DEM LH 402 2000-05-28 1234,56 DEM LH - Find - Filter - Sort - Totals/subtotals

Numerous interfaces:
- Report-Report - Mail - Excel/Word - File, ...

Display variants
supported - User-specific and / or global save mode

SAP AG 1999

The ALV Grid Control is a tool with which you can output non-hierarchical lists in a standardized format. The list data is displayed as a table on the screen. The ALV Grid Control offers a range of interactive standard list functions that users need frequently (find, sort, filter, calculate totals and subtotals, print, print preview, send list, export list (in different formats), and so on. These functions are implemented in the proxy object class. You as the programmer have the possibility to turn off functions not needed. In most cases the implementations of the standard functions provided by the control are sufficient. However, if required, you can adjust these implementations to meet application-specific needs. You can add self-defined functions to the toolbar, if necessary. The ALV Grid Control allows users to adjust the layout of lists to meet their individual requirements (for example, they can swap columns, hide columns, set filters for the data to be displayed, calculate totals, and so on). The settings (list customizing) made by a specific user are called a display variant. Display variants can be saved on a user-specific or on a global basis. If such display variants exist for a list, they can be offered to the user for selection. If a display variant is set as the default variant, the associated list is always displayed based on the settings of this variant.

(C) SAP AG

BC412

5-5

0.6
Standard Pushbuttons
Display list row details in a dialog box Sort in ascending order (by columns selected) Sort in descending order (by columns selected) Find items in the list Set filter: determine data to be displayed based on a condition (row selection) Calculate totals for selected columns Subtotals Print, print preview Transfer data --> spreadsheet, word-processing, local file, send, ... Display variants: customize column selection, select, change, save variants, and so on
SAP AG 1999

The control toolbar provides the following standard functions: Details: Select a row on the list. If you choose Details, the system displays the content of all list fields (including hidden columns) in a modal list window. Sort in ascending order: Select one or more columns. If you choose Sort in ascending order, the system sorts the list content by the columns selected. The sort order is determined by the display order of the columns on the screen. If you do not select a column beforehand, the system displays a dialog box on which you can select the column (sort order depends on the order of the columns selected). Sort in descending order: This function is analogous to Sort in ascending order. Find: You can determine a search term and the search order (columns or rows). Set filter: You can determine the amount of data displayed by defining value selections (SELECTOPTIONs) for each column (column selection: see Sort in ascending order). Total: The system calculates totals for the columns selected. Subtotal: This function is analogous to Total. (Note: You can only display subtotals if totals are calculated). Print: The options available are Print (print dialog ->Print) and Print preview. Export: The options available are Spreadsheet, Word processing, Local file, Send, Office and ABC Analysis.

(C) SAP AG

BC412

5-6

Display variants: The functions available are Choose display variant, Change display variant, and Manage display variant.

(C) SAP AG

BC412

5-7

0.7
Features Overview: Technical View

Features Features Technical view Technical view Screen and print list Screen and print list Method overview Method overview Event overview Event overview The field catalog The field catalog

SAP AG 1999

(C) SAP AG

BC412

5-8

0.8
ALV Grid Control: Technical View

ALV Grid Control Frontend

Printer/spool

Application server ALV proxy object

ABAP program List data Field catalog Additional info

SAP AG 1999

The class cl_gui_alv_grid encapsulates the technical details of the communication with the frontend control of the ALV Grid Control. From a technical point of view, the "wrapper" (cl_gui_alv_grid) does more than encapsulate the dialog with the frontend control, since the proxy objects communicate with three partners: Frontend Grid Control: Display of the list data as a table ABAP program: User Spool system / printer: Output of the list data as an ABAP print list Communication through the ABAP program - proxy object - ALV Grid Control chain takes place interactively at runtime. The spool system is used for the output of the associated ABAP print lists. The standard functions provided for screen output and the creation of the ABAP print list are implemented in proxy class cl_gui_alv_grid. The proxy class is an "application wrap" around the technical "wrapper" of the control communication. ALV proxy objects maintain only a minimum amount of information on the data to be displayed. The data to be displayed and the rules according to which the data is to be displayed (field catalog) must be held in the program in global data objects.

(C) SAP AG

BC412

5-9

0.9
ALV Grid Control: List Data

ALV Grid Control Frontend

Printer/spool

Application server ALV proxy object

ABAP program List data Field catalog Additional info

SAP AG 1999

Data that is to be output on the screen or as an ABAP print list is called list data.

(C) SAP AG

BC412

5-10

0.10
Creating List Data and Holding Data
ALV Grid Control

Printer/spool

ALV proxy object

Proxy object holds only


a pointer to the data object

ABAP program Internal table

Internal table must be a global data


object in the program or a class or object attribute Sorting (using Grid Control button) is applied to the program data Read access for all other standard functions of the ALV Grid Control

List data
SAP AG 1999

To display the data in the ALV Grid Control (or print the data using the control), you must pass the data in an internal table to the proxy object. The proxy object does not have a copy of the data, but maintains a reference to the internal table passed. To improve performance, the proxy object performs all interactive actions in the frontend control (sort, filter, and so on) on the internal table in the calling program. For this reason, the internal table that contains the list data must be declared as global in the program (or as a static variable in a class). Sort processes in the ALV Grid Control change the state of the internal table in the calling program; all other actions perform only read access to the data.

(C) SAP AG

BC412

5-11

0.11
ALV Grid Control: The Field Catalog

ALV Grid Control Frontend

Printer/spool

Application server ALV proxy object

ABAP program List data Field catalog Additional info

SAP AG 1999

The field catalog is dealt with in more detail in the following.

(C) SAP AG

BC412

5-12

0.12
Functions of the Field Catalog

ALV Grid Control / print list

er op Pr

Co nt en

s t ie

Internal table itab with data carrid connid fldate AA AZ LH QA 0603 1702 0400 ... ...

Field catalog: column properties

20001010 . . . 20000105 . . . 20000312 . . . ... ...

carrid connid fldate ...

Properties of column carrid Properties of column connid Properties of column fldate Properties of column . . .

SAP AG 1999

The internal table with the data to be displayed that was passed to the proxy object can have any row type which can be chosen as required. So that the proxy object can properly format the data passed during screen output or creation of the print list, the object needs information on how the columns of the internal table are to be presented (properties of the fields of the internal table row type). You use another internal table to pass this information to the proxy object. This internal table is called the field catalog. For each column of the data table, the field catalog must contain a row that determines the technical properties and additional formatting information of the column. Depending on the row type of the data table, the field catalog can be generated differently. For row types defined in the ABAP Dictionary, you need only pass the name of the structure in the ABAP Dictionary to the proxy object. The proxy object copies all properties of the fields of the Dictionary structure and generates the field catalog automatically. This is the most common procedure and is called Automatically generated field catalog. If you use other row types, you must use different procedures referred to as Semi-Automatically Generated Field Catalog or Manually Generated Field Catalog. For more details, see the section The Field Catalog of this unit.

(C) SAP AG

BC412

5-13

0.13
Data Descriptions: The Field Catalog

LVC_T_FCAT

Table type in the ABAP Dictionary for the field catalog

LVC_S_FCAT

Row type in the ABAP Dictionary

Structure Properties of column 1 Properties of column 2 Properties of column 3 ... Internal table with column/ field properties

SAP AG 1999

Internal tables that contain field catalogs must be typed with reference to table type LVC_T_FCAT (type of an internal table; defined in the ABAP Dictionary, new for Release 4.6). Table type LVC_T_FCAT uses the global row type LVC_S_FCAT.

(C) SAP AG

BC412

5-14

0.14
Information in the Field Catalog (Structure)

LVC_S_FCAT

Structure type in the ABAP Dictionary for the field catalog

Column indicator Unit-specific formatting Output properties of columns Formatting of column contents Texts Technical column properties Other fields For details, see the section on the field catalog

SAP AG 1999

Row type LVC_S_FCAT contains the following information: Column indicator (names of the fields, names of the reference fields in the ABAP Dictionary, ...) Formatting options for currency and quantity fields Output properties of the columns (order, ...) Formatting of the column contents (decimal place formatting, ...) Texts for column headers, detail screens and output in hotspot format Technical column properties Other fields For more detailed information, see the section The field catalog of this unit.

(C) SAP AG

BC412

5-15

0.15
ALV Grid Control: Additional Information

ALV Grid Control Frontend

Printer/spool

Application server ALV proxy object

ABAP program List data Field catalog Additional info

SAP AG 1999

In addition to the list data and the field catalog, you can pass additional information to the proxy object.

(C) SAP AG

BC412

5-16

0.16
ALV Grid Control: Function of Additional Information

Additional info
Control layout info Print list layout info

Formatting information for data output


(data-independent)

Data info

Rules for data output


(data-dependent)

SAP AG 1999

The additional information comprises: Layout information For the frontend control For the print list Information that contains the display rules for the data to be output Sort criteria Filter criteria Texts for field groups

(C) SAP AG

BC412

5-17

0.17
Function of Additional Information in Detail
ALV Grid Control

Printer/spool

ALV proxy object

ABAP program Data area (grid) Toolbar Print list

Layout info

Sort

Filter

Field groups Data info

SAP AG 1999

You can use the following data object types to pass additional information to the ALV proxy object: Layout of the frontend control: Settings for the data area are passed using a structure. You can use an internal table to control the composition of the toolbar. Layout of the print list: You can use the fields of a structure to control parts of the list layout. You use internal tables to pass information about sort criteria, filter options, and field group texts to the proxy object.

Normally, you do not set up filter and sort criteria manually since they can be changed interactively by the user. The proxy object automatically modifies the associated internal tables in case of user interactions. Sort and filter criteria are usually handled (saved and read) as parts of display variants. You can find more information on the structure of the internal tables for the sort and filter criteria in the online documentation. If the table to be displayed contains many fields, the user may be overwhelmed by the structure of the dialog boxes for selecting fields (columns) which are presented during interactions. For this reason, you can use the field catalog to group fields into logical groups (field groups). Using an internal table, you can pass texts for the field groups to the proxy object.
BC412 5-18

(C) SAP AG

0.18
Layout Information for the Data Area: Overview

LVC_S_LAYO

Structure type in the ABAP Dictionary for the control layout

General display options Grid customizing Totals options Exceptions Interactive control Drag&Drop control settings Colors

Optimize column width, title size, ... Gridlines on/off, column headers off, ... Totals display before single records yes/no, ... Indicate with traffic-light symbols yes/no, ... Detail screen properties, key columns ... Drag&Drop control settings List colors

SAP AG 1999

You can influence the control layout using a structure of type LVC_S_LAYO (structure type in the ABAP Dictionary). The structure type LVC_S_LAYO contains the following information: General display options (optimize column width, title size, ...) Grid customizing (horizontal/vertical gridlines on/off, use column headers, ...) Totals options (totals display before single records, ...) Exception handling (use traffic light symbols, ...) Interactive control (properties of the detail screen, ...) Drag&Drop settings Colors (print lists with striped pattern, ...) For more details, see the online documentation.

(C) SAP AG

BC412

5-19

0.19
Layout Information for the Toolbar

UI_FUNCTIONS

Table type in the ABAP Dictionary

ui_func (C70)

Row type in the ABAP Dictionary: data element

Structure f_code1 f_code2 f_code3 f_code4

Internal table of type UI_FUNCTION


(only one column)

Contains the function codes of the standard functions


to be disabled (hidden)

SAP AG 1999

You can control the set of functions that are active in the toolbar using an internal table of type UI_FUNCTIONS (table type in the ABAP Dictionary). Table type UI_FUNCTIONS uses the field ui_func as the row type. Using the internal table, you can set standard functions to inactive. To do this, you fill the internal table with the function codes of the functions that you want to disable. Inactive functions that have originally be assigned to icons in the toolbar will not be displayed. Inactive functions that have originally be assigned to a menu item are displayed disabled. To set a value for field ui_func, you should use class constants of the class cl_gui_alv_grid. The class cl_gui_alv_grid has one class constant for each standard function. The class constants each begin with mc_fc_.... To hide the entire toolbar, you can use the field no_toolbar of structure LVC_S_LAYO.

(C) SAP AG

BC412

5-20

0.20
Layout Information for the Print List

LVC_S_PRNT

Structure type in the ABAP Dictionary: print parameters

print reservelns grpchgedit prntlstinf

Print output yes/no Line number for END-OF-PAGE Group change formatting yes/no Do not print list info yes/no

SAP AG 1999

Using the fields print, reservelns, grpchedit and prntlsinf of structure LVC_S_PRNT, you can make settings for the print list, If you set parameter print to value 'X', you can use the ALV Grid Control as the default interface for printing: The table passed is directly formatted as an ABAP print list and placed into the spool; in this context, any interactive screen output is not processed. You do not need this parameter if you print lists interactively using the frontend control. Using parameter reservelns, you can determine the number of lines required for the page footer (END-OF-PAGE). Using field grpchgedit, you can determine if you want to print a line after a group change (default setting) or if you want to have a page break (if you want to have a page break, you must set the field to 'X'). The parameter applies for print lists only. If you set the field prntlstinf to 'X', any settings made interactively such as filter criteria, and the total number of list lines also appear on the print list. The other fields of the structure are not used for the ALV Grid Control.

(C) SAP AG

BC412

5-21

0.21
Features Overview: Screen/Print List

Features Features Technical view Technical view Screen and print list Screen and print list Method overview Method overview Event overview Event overview The field catalog The field catalog

SAP AG 1999

(C) SAP AG

BC412

5-22

0.22
Screen Layout of the ALV Grid Control

Toolbar List header

Toolbar Functions can be hidden Pushbuttons and menu options can be added Functions are triggered as events List header Optional Single-line Data area Further structured

Data display area (grid)

SAP AG 1999

The ALV Grid Control screen consists of three areas: In the header area of the control area, you can display a toolbar. The calling program determines which functions are active. You can hide the toolbar completely. Below the toolbar, you can display a single-line list header. Below the header is the area in which the list data is displayed (data area).

(C) SAP AG

BC412

5-23

0.23
Data Area Layout
Column headers (can be hidden) Area for scrollable columns

Colors can be used Striped patterns can be


used (only print list) User can select (based on setting): - Single cells - Entire rows/columns Column headers can be used Gridlines can be shown/ hidden Context menus Drag&Drop ... Selection keys (optional)
SAP AG 1999

Area for key columns (fixable)

Scroll bars

The data area itself also has a structure of its own. The data passed as an internal table is displayed as a table. You can determine if you want to have horizontal and vertical gridlines for the cell structure. The columns can have headers. You can hide the column headers. If the data table contains more rows and more columns than can be displayed in the control area, horizontal and vertical scroll bars are available to go to a specific list position. You can logically group columns into key columns and non-key columns. Key columns have another color than non-key columns. Key columns have a fixed position and therefore remain unchanged when the user scrolls horizontally through the list. You can make any column in your data table a key column. You can define the items users can select. It is possible to select cells (cell areas), entire rows and/or entire columns. Optionally, you can display a selection column as the first column in the data area that can be used to select entire rows. Drag&Drop operations are supported. The ALV Grid control supports context menu handling. For more information, see the online documentation.

(C) SAP AG

BC412

5-24

0.24
Print List Layout
Complete layout Page layout List properties List can be organised in pages - Cover page - Pages - Final page Each page can be organised in - Page header - Page body - Page footer This is controlled through events and layout information for the list Subtotals can also be output by means of an event (control levels)

Cover page Page header Page 1 Page body Page footer Page

Page n

Final page

SAP AG 1999

The print list layout is similar to the list layout of "classic" reporting: The list can consist of a logical cover page, a logical final page and any number of other pages in between that contain the actual list data. In addition to the page body, each page can have a page header and a page footer. The logical organization of the complete list into cover page, pages, final page, and the organization of the individual pages into page header, page body and page footer is made possible by events (details to follow later).

(C) SAP AG

BC412

5-25

0.25
ALV Grid Control Overview: Method Overview

Features Features Method overview Method overview Event overview Event overview The field catalog The field catalog

SAP AG 1999

(C) SAP AG

BC412

5-26

0.26
Inheritance Hierarchy

cl_gui_object

cl_gui_control

cl_gui_alv_grid_base

cl_gui_alv_grid

SAP AG 1999

Class cl_gui_alv_grid has the inheritance hierarchy specified. Only class cl_gui_alv_grid is instantiated by applications.

(C) SAP AG

BC412

5-27

0.27
ALV Grid Control: Method Overview (1)

Elementary methods Read/change Grid Control properties Read/ Layout and structure information Operations on / information about Filter criteria Sort criteria Variants Event handling / function codes Report / report interface

SAP AG 1999

The methods of the ALV Grid Control can be subdivided into: Elementary methods Methods for changing/reading the properties of the Grid Control Methods for changing/reading the layout Methods for operations on filter criteria, sort criteria, and variants Methods for event handling and function code handling Methods for connecting the control to the report-report interface For details on methods and interfaces, see the online documentation.

(C) SAP AG

BC412

5-28

0.28
ALV Grid Control: Elementary Methods

Elementary methods constructor set_table_for_first_display refresh_table_display Link with container, event type, ... Send data, data descriptions, layout information to control Inform control that data, data descriptions or layout have been changed

SAP AG 1999

The ALV Grid Control has three elementary methods: The constructor Method set_table_for_first_display Method refresh_table_display.

(C) SAP AG

BC412

5-29

0.29
The Constructor

DATA: my_alv TYPE REF TO cl_gui_alv_grid. ... CREATE OBJECT my_alv EXPORTING * i_shellstyle = * i_lifetime = i_parent = * i_appl_events = EXCEPTIONS ...

Container reference

All registered events as application events: ' ' : Yes 'X' : No

SAP AG 1999

Optional parameters are shown as (ABAP) comments. The constructor for ALV Grid Control instances has four interface parameters: i_shellstyle: You use this parameter to determine the general appearance of the control (for details, see the online documentation). i_lifetime: You use this parameter to influence the lifetime of the frontend control. Possible values are: lifetime_imode (default), lifetime_dynpro (for details, see the online documentation). i_parent: You use this parameter to pass a container reference. i_appl_events: You use this parameter to determine if all events of your ALV Grid Control instance should be registered as system events (default) or as application events (value 'X'). The proxy object registers the ALV controls at the Control Framework.

(C) SAP AG

BC412

5-30

0.30
Method SET_TABLE_FOR_FIRST_DISPLAY

CALL METHOD my_alv->set_table_for_first_display EXPORTING * i_structure_name = Field catalog: name of a Dictionary structure catalog: * is_variant = * i_save = Variant control parameter * i_default = * is_layout = Structure for control layout * is_print = Structure for print list layout * it_special_groups = Internal table with texts for the field groups * it_toolbar_excluding = Internal table with functions to be hidden CHANGING it_outtab = Internal table with list data * it_fieldcatalog = Internal table with the field catalog * it_sort = Internal table with initial sort criteria * it_filter = Internal table with initial filter criteria EXCEPTIONS ...

SAP AG 1999

You can use method set_table_for_first_display to pass the list data, the field catalog, and any additional information to the ALV Grid Control instance. To pass the list data to be displayed, you use parameter it_outtab. You pass the name of the row structure of the data table using parameter i_structure_name. The proxy object then generates the field catalog automatically. If you want to pass a field catalog that was generated manually or semi-automatically, you must additionally use parameter it_fieldcatalog. (For details, see the section The field catalog of this unit). You use parameters is_variant and i_save to control the use of display variants. Using parameter i_default, you can determine that a display variants should be loaded as default variant. This is the default setting of the parameter. Parameters is_layout, is_print, it_special_groups and it_toolbar_excluding allow you to pass your settings for the control layout and the print list, as well as the names of the field groups and the names of the functions to be disabled in the toolbar. Using parameters it_filter and it_sort, you can pass initial filter and sort criteria to your proxy object. The interface parameters use the following name conventions: i_ = single field, is_ = structure, it_ = internal table. For details on the method and the interface parameters, see the online documentation.
BC412 5-31

(C) SAP AG

0.31
Method REFRESH_TABLE_DISPLAY

CALL METHOD my_alv->refresh_table_display EXPORTING * is_stable = Refresh with stable columns/rows columns/ * i_soft_refresh = Update data only, no sort criteria, and so on only, criteria, .

Informs proxy object that the

Content of the internal table with list data and/or Data objects for additional information
have changed Update display at the frontend

SAP AG 1999

If you use method refresh_table_display, the proxy object sends the list data and the display information once more to the frontend control. Using parameter i_soft_refresh, you can determine that only the data content is to be sent again (filter and sort criteria remain unchanged). Using the fields of parameter is_stable, you can determine that any scroll positions that may exist should be kept (with reference to rows and columns) when the data is refreshed. Important: If you change the structure of your data table you have to call method set_table_for_first_display again.

(C) SAP AG

BC412

5-32

0.32
Display Variants

MODE

Parameter value in method SET_TABLE_FOR_FIRST_DISPLAY is_variant = SPACE. i_save = SPACE. is_variant = <structure_name>. i_save = SPACE. is_variant i_save i_save i_save = = = = <structure_name>. 'U'. " Only user-specific 'X'. " Only global 'A'. " Global and user-specific

Change current display variant Select and change current display variant

Select, change and save current display variant

DATA: <structure_name> TYPE disvariant.


SAP AG 1999

Using parameters is_variant and i_save, you can determine the behavior of your proxy object with regard to display variant handling. There are three modes which you can set with the help of these two parameters: The user can change the current display variant: To set this mode, you set both parameters to SPACE (default value). The user can select and change display variants: To set this mode, you pass a structure of the type disvariant to parameter is_variant in which the field report has the value sy-repid, and set parameter i_save to SPACE. The user can select, change, and save display variants: To set this mode, you assign the same value to parameter is_variant as with the above mode. The value you assign to parameter i_save allows you to control the user save mode for display variants: U: The user can save display variants only as user-specific. X: The user can save display variants only as global. A: The user can save display variants both as user-specific and as global.

(C) SAP AG

BC412

5-33

0.33
ALV Grid Control: Method Overview (2)

Read/change properties of the Grid Control Read/ Cells Scroll bars Columns Rows Layout and structure information Field catalog Layout Frames

SAP AG 1999

The ALV Grid Control has methods for the following subobjects that allow you to access the properties of these subobjects in change or read mode: Cells Scroll bars Columns Rows The methods for the layout and the structure information can be subdivided as follows: Methods for the field catalog Methods for the layout Methods for the general control layout (frames) For details on the method names and the interfaces, see the online documentation.

(C) SAP AG

BC412

5-34

0.34
ALV Grid Control Overview: Event Overview

Features Features Method overview Method overview Event overview Event overview The field catalog The field catalog

SAP AG 1999

(C) SAP AG

BC412

5-35

0.35
ALV Grid Control: Events
Events during print list creation Mouse operations double_click hotspot_click User-defined functions User-defined before_user_command user_command after_user_command toolbar menu_button Context menus Drag&Drop Drag&
SAP AG 1999

Double-click on a cell Click on a cell hotspot

Before execution of a standard function User-defined function code is triggered After execution of a standard function Toolbar is changed A menu option is changed

The ALV Grid Control has the following event types: Events that mark a specific point during print list creation Events for mouse operations Double-clicks on a cell Click on a hotspot of a cell Events that allow you to Execute implementations for self-defined functions Change the process flow of the standard functions Events for context menus Events for Drag&Drop operations For details on the event names and interfaces, see the online documentation.

(C) SAP AG

BC412

5-36

0.36
BEFORE_USER_COMMAND and AFTER_USER_COMMAND
Frontend control Proxy instance ABAP program

User triggers standard function

before_user_command before_ user_ Implementation 1 Implementation of standard function after_user_command after_user_ Implementation 2

SAP AG 1999

The events before_user_command and after_user_command allow you to run self-defined processes directly before and after the execution of a standard function. You can suppress the standard implementation of a standard function. To achieve this call the instance method set_user_command at the event for before_user_command and pass SPACE to the parameter i_ucomm.

(C) SAP AG

BC412

5-37

0.37
ALV Grid Control: Print List Events

Events during print list creation print_end_of_list print_top_of_list print_end_of_page print_top_of_page subtotal_text Corresponds to event END-OF-SELECTION for list Corresponds to event START-OF-SELECTION for list Corresponds to list event END-OF-PAGE Corresponds to list event TOP-OF-PAGE Subtotals texts of suppressed lines

SAP AG 1999

You can use events print_top_of_list, print_end_of_list, print_top_of_page, and print_end_of_page to implement the logical processing steps that correspond to the events START-OF-SELECTION, END-OF-SELECTION, TOP-OF-PAGE and END-OF-PAGE in "classic" reporting. You can use event subtotal_text to output texts for subtotals lines that are not shown. For more details, see the online documentation.

(C) SAP AG

BC412

5-38

0.38
ALV Grid Control Overview: The Field Catalog

Features Features Method overview Method overview Event overview Event overview The field catalog The field catalog

SAP AG 1999

(C) SAP AG

BC412

5-39

0.39
Recap: Functions of the Field Catalog

ALV Grid Control / print list

er op Pr

Co nt en

s t ie

Internal table itab with data carrid connid fldate AA AZ LH QA 0603 1702 0400 ... ...

Field catalog: column properties

20001010 . . . 20000105 . . . 20000312 . . . ... ...

carrid connid fldate ...

Properties of column carrid Properties of column connid Properties of column fldate Properties of column . . .

SAP AG 1999

Recap: the field catalog is an internal table containing the properties of all columns of the data table.

(C) SAP AG

BC412

5-40

0.40
Overview: Information in the Field Catalog

LVC_S_FCAT

Structure type in the ABAP Dictionary for the field catalog

Column indicator Unit-specific formatting Output properties of columns Formatting of column contents Texts Technical column properties Other fields

SAP AG 1999

(C) SAP AG

BC412

5-41

0.41
Field Catalog Overview: Information in the Field Catalog in Detail

Features Features Method overview Method overview Event overview Event overview The field catalog The field catalog Information in the field catalog in detail Information in the field catalog in detail Generating the field catalog Generating the field catalog
SAP AG 1999

(C) SAP AG

BC412

5-42

0.42
Field Catalog: Column Indicators

Column indicators fieldname ref_field ref_table Example Internal table itab with data carrid . . . seatsfree . . . AA AZ LH QA ... ... ... ... 12 . . . 30 . . . 70 . . . 0 ... Entries in the field catalog fieldname CARRID ... SEATSFREE ... ... ... ... ref_field ref_table SFLIGHT ... Column name in data table Column with Dictionary reference: field name Column with Dictionary reference: structure name

SAP AG 1999

The column fieldname in the field catalog contains the names of the data table columns. Each column of the data table has a row in the field catalog. If a field is typed with reference to the ABAP Dictionary (automatically generated entry in the field catalog), fields ref_field and ref_table contain the names of the reference field and the reference structure. For more details, see the online documentation.

(C) SAP AG

BC412

5-43

0.43
Field Catalog: Unit-Specific Formatting

Unit-specific formatting cfieldname currency qfieldname quantity Name of column for currency formatting Explicit currency ID for entire column Name of column for unit of measure formatting Explicit unit of measure for entire column

SAP AG 1999

Currency formatting: If the content of a column is to be formatted based on the formatting options of a currency unit that is contained in another column of the data table, then you must specify the name of the column with the currency units in the field cfieldname. If all values of a column are to be formatted according to a fixed currency, you must enter the ID of that currency in the column currency. If a value is assigned to the field currency, entries in the field cfieldname are ignored. Unit of measure formatting: If the content of a column is to be formatted based on the formatting options of a unit of measure that is contained in another column of the data table, then you must specify the name of the column with the units of measure in the field qfieldname. If all values of a column are to be formatted according to a fixed unit of measure, you must enter the ID of that unit of measure in the column quantity. If a value is assigned to the field quantity, entries in the field qfieldname are ignored. For more details, see the online documentation.

(C) SAP AG

BC412

5-44

0.44
Example: Currency Formatting

Internal table itab with data carrid . . . AA AZ ... ... ... ... price currency 300 USD 7000 ITL ... ...

Entries in the field catalog fieldname CARRID ... PRICE ... ... cfieldname ... ... ... ... ... CURRENCY ...

Screen output / printing Fli... . . . AA AZ ...


SAP AG 1999

Price Currency 300,00 USD 7000 ITL ... ...

... ... ...

The above graphic shows the following: The data table contains the two columns price (amount to be paid for the flight) and currency (currency of price). The entry currency in field cfieldname for the column price in the field catalog determines that the entries of the column price are formatted according to the currency specified in the column currency (example: USD -> two decimal places, ITL -> no decimal place).

(C) SAP AG

BC412

5-45

0.45
Field Catalog: Output Properties for Columns

Output properties for columns checkbox col_pos do_sum hotspot no_sum emphasize key lowercase no_out outputlen tech
SAP AG 1999

Display of a checkbox (no entry) Column position Totals calculation for column yes/no Column hotspot-sensitive yes/no Suppress totals calculation for column yes/no Highlight column content (color, bright, inverse) Column is key column yes/no Upper/lower case yes/no Do not output column yes/no Column width Do not output column yes/no

The following difference exists between no_out and tech: no_out: The column is hidden in the list (screen or printout), but appears on the field selection dialog boxes for the standard functions (sort, filter, ...). tech: The column is hidden both in the list and on the field selection dialog boxes.

For more details, see the online documentation.

(C) SAP AG

BC412

5-46

0.46
Field Catalog: Formatting of Column Contents
Formatting of column contents decimals_o decmfield edit_mask exponent icon lzero just no_sign no_zero round roundfield symbol
SAP AG 1999

Number of decimal places (currencies) Column name in data table for number of dec. places Analogous to USING EDIT MASK for WRITE Window exponent for ABAP data type F Display column content as icon yes/no Leading zeros yes/no (NUMC) Adjust column content (' ', 'R', 'L', 'C') (CHAR, NUMC) Suppress plus/minus signs yes/no Value 0 ('zero') not output yes/no Analogous to ROUND for WRITE Column name in data table for ROUND Display column content as symbol yes/no

Similar to the formatting options for currency fields, you can use the fields decmfield and decimals_o to define the number of decimal places for numerical fields (ABAP data types P, I, F) either for individual column contents or for all entries of a column. For more details, see the online documentation.

(C) SAP AG

BC412

5-47

0.47
Field Catalog: Texts

Texts colddictxt coltext reptext scrtext_l scrtext_m scrtext_s selddictxt seltext tipddictxt tooltip Text selection for column headers ('L', 'M', 'S') Freely definable text (column header) Copy from ABAP Dictionary Long text Medium text Short text Text selection for selection dialog box ('L', 'M', 'S') Freely definable text (selection dialog box) Text selection for tooltip ('L', 'M', 'S') Freely definable text (tooltip)

SAP AG 1999

Similar to the texts of a data element in the ABAP Dictionary, the fields scrtext_l, scrtext_m and scrtext_s can contain three texts of different lengths for columns, selection screens, and tool tips (S = 'short', M = ''middle', L = 'long'). For fields with reference to the Dictionary, the texts are copied from the Dictionary. By assigning value 'L', 'M' or 'S' to field colddictext, you determine which text is to be used as the column header. Similarly, the values of fields selddictext and tipddictext determine which text is to be displayed on the dialog boxes (interactive standard functions) and as the tool tip. The fields coltext, seltext and tooltip allow you to use freely definable texts as column headers, dialog box texts and tool tips. If you assign values to these fields, these values override any entries in the fields colddictext, selddictext and tipddictext. For fields with reference to the Dictionary, the field reptext contains the headers from the data element (used for queries). For more details, see the online documentation.

(C) SAP AG

BC412

5-48

0.48
Field Catalog: Technical Column Properties

Used for fields without

reference to ABAP Dic tionary

types

Technical column properties dd_outlen intlen rollname Output length (width) of column Internal column width F1 help by data element documentation: name of data element ABAP data type

inttype

SAP AG 1999

For more details, see the online documentation.

(C) SAP AG

BC412

5-49

0.49
Field Catalog: Other Fields

Other fields dragdropid reprep Drag&Drop control Link of column to report-report interface yes/no

sp_group txt_field

Identifier for field groups Column name for substitute texts for totals calculation

SAP AG 1999

You can replace numeric fields with a corresponding text using the txt_field field. Example: Suppose column A contains plant numbers, and column B the corresponding long texts. On the list, you want to display the text instead of the plant number (for example, Hamburg instead of 0001. For column A, the field txt_field must contain the name of column B (txt_field = 'B').

For further details, refer to the online documentation.

(C) SAP AG

BC412

5-50

0.50
Summary: Structure of the Field Catalog

Column name

Dictionary relationship

Properties

FIELD CATALOG ref_field ref_table


Unit-specific formatting

Output Properties for Columns fieldname Formatting of Column Contents Texts Technical Column Properties Other Fields

SAP AG 1999

We can divide the fields in the field catalog into three groups according to their use in constructing the field catalog. The field fieldname contains the column name. The fields ref_field and ref_table establish the relationship to any global types (fields of structures in the ABAP Dictionary). All of the other fields contain values for the attributes of the columns.

(C) SAP AG

BC412

5-51

0.51
Field Catalog Overview: Generating the Field Catalog

Features Features Method overview Method overview Event overview Event overview The field catalog The field catalog Information in the field catalog in detail Information in the field catalog in detail Generating the field catalog Generating the field catalog
SAP AG 1999

(C) SAP AG

BC412

5-52

0.52
Generating the Field Catalog
List data List data List data

Row type of data table contains only Fields of a single Dictionary structure

Row type of data table contains

Row type of data table contains only Fields with local types

Fields of
Dictionary structures

Fields with
local types

Field catalog is generated automatically


SAP AG 1999

Field catalog can be generated semi-automatically semi-

Field catalog must be generated manually

Depending on the row type of the data table, the field catalog is generated according to a different procedure. We have to distinguish between three cases: Case 1: The row type of the data table is defined in the ABAP Dictionary. Example: Row type SFLIGHT. In this case, all information of the field catalog can be copied from the ABAP Dictionary. This is done independently by the proxy object: The field catalog is generated automatically. Case 2: The row type of the data table contains fields with types of fields of Dictionary structures and fields with local types. Example: The row type consists of the fields of structure SFLIGHT to which fields with types defined locally in the program have been added. In this case, you can have the entries of the fields with reference to the Dictionary generated automatically, while you must manually add the entries of the other columns to the field catalog (semiautomatic procedure). Case 3: The row type of the data table contains only fields with local types. In this case, the field catalog must be generated manually. This means that the program that uses the ALV Grid Control must generate the field catalog on its own.

(C) SAP AG

BC412

5-53

0.53
Fields of a Single Dictionary Structure
Internal table it_data with list data Row type: SFLIGHT AA AZ ... ... ... ... 300 7000 ... USD ITL ...

SFLIGHT

SPFLI ABAP Dictionary

CALL METHOD my_alv->set_table_for_first_display EXPORTING i_structure_name i_structure_name = 'SFLIGHT' i_structure_ ... CHANGING it_outtab = it_data it_outtab it_data it_ it_ ...
SAP AG 1999

If the line type of the data table contains all of the fields in a particular ABAP Dictionary structure, the ALV proxy object can create the field catalog automatically. To do this, specify the name of the ABAP Dictionary structure that corresponds to the line type of the data table in the i_structure_name parameter of the method set_table_for_first_display. The proxy object obtains all of the requisite information from the ABAP Dictionary and constructs the field catalog itself.

(C) SAP AG

BC412

5-54

0.54
Fields of a Dictionary Structure and Local Types
Field catalog it_fcat Local ABAP types fill Cn DDIC 'empty' ABAP Dictionary STRUC send Cn = Column name Properties

CALL METHOD my_alv->set_table_for_first_display EXPORTING i_structure_name = 'STRUC' i_structure_ ... CHANGING it_outtab = it_data it_ it_ it_fieldcatalog it_ ...
SAP AG 1999

= it_fcat it_

If the row type of your data table consists of all fields of a single Dictionary structure to which other fields have been added, you can generate the field catalog semi-automatically. To dothis, you: Declare an internal table for the field catalog DATA: it_fcat TYPE lvc_t_fcat. Create an entry in the field catalog for each column in your data table that has a type that you defined locally in the program. Enter the column name and define its attributes. Call the instance method set_table_for_first_display and pass the data table (it_data in the graphic) to the it_outtab parameter, the field catalog (it_fcat) to the it_fieldcatalog parameter, and the name of the ABAP Dictionary structure to the i_structure_name parameter. The proxy object then generates a full field catalog.

(C) SAP AG

BC412

5-55

0.55
Fields of Several Dictionary Structures
ABAP Dictionary SFLIGHT SPFLI Column fill
CARRID CONNID FLDATE DEPTIME CITY_F CITY_T ...

Field catalog it_fcat DDIC Relation


SFLIGHT SFLIGHT SFLIGHT SPFLI CITYFROM SPFLI CITYTO SPFLI ...

Properties

'empty'

send CALL METHOD my_alv->set_table_for_first_display ... CHANGING it_outtab it_ it_fieldcatalog it_ ...
SAP AG 1999

= it_data it_ = it_fcat it_

You can also generate the field catalog semi-automatically if the fields in the line type of your data table have data types from more than one ABAP Dictionary structure. To do this, you must: Declare an internal table for the field catalog: DATA: it_fcat TYPE lvc_t_fcat. Create an entry in the field catalog for each column in your data table. Fill the fieldname and ref_table fields for all of the columns that have the same name as the structure field to which you referred to define their types (fieldname contains the column name, ref_table the name of the reference table). For fields where the column name in the data table is different to the field name in the ABAP Dictionary structure (cityfrom and cityto in the graphic), you must also specify the name of the reference field. Call the instance method set_table_for_first_display and pass the data table (it_data in the example) to the it_outtab parameter and the field catalog (it_fcat) to the it_fieldcatalog parameter. The proxy object then creates the full field catalog.

(C) SAP AG

BC412

5-56

0.56
Fields With and Without Dictionary Relationships
ABAP Dictionary STRUC Cn Field catalog it_fcat DDIC Properties 'empty' 'empty' Cn = Column name send CALL METHOD my_alv->set_table_for_first_display ... CHANGING it_outtab it_ it_fieldcatalog it_ ...
SAP AG 1999

fill Local ABAP Types

= it_data it_ = it_fcat it_

You can also generate the field catalog semi-automatically if the line type of your data table consists of fields from more than one ABAP Dictionary structure along with additional fields that have types that you defined locally in the program. To do this, you must: Declare an internal table for the field catalog: DATA: it_fcat TYPE lvc_t_fcat. Create an entry in the field catalog for each column in your data table. For each column that has an ABAP Dictionary reference, fill the fieldname and ref_table columns (and ref_field if necessary). For each column in your data table that has a type that you defined locally in the program, create an entry in the field catalog by entering the column name and defining the attributes of the column. Call the instance method set_table_for_first_display and pass the data table (it_data in the example) to the it_outtab parameter and the field catalog (it_fcat) to the it_fieldcatalog parameter. The proxy object then generates the full field catalog.

(C) SAP AG

BC412

5-57

0.57
Fields With Local Types Only
Field catalog it_fcat fill Local ABAP types Cn DDIC 'empty' Properties

Cn = Column name send

CALL METHOD my_alv->set_table_for_first_display EXPORTING ... CHANGING it_outtab it_ it_fieldcatalog it_ ...
SAP AG 1999

= it_data it_ = it_fcat it_

If the line type of your data table consists exclusively of data types that you declared locally in the program, you must create the field catalog by hand. To do this, you must: Declare an internal table for the field catalog: DATA: it_fcat TYPE lvc_t_fcat. Create an entry in the field catalog for each column in your data table. Enter the column name and define the attributes for the columns. Call the instance method set_table_for_first_display and pass the data table (it_data in the example) to the it_outtab parameter and the field catalog (it_fcat) to the it_fieldcatalog parameter.

(C) SAP AG

BC412

5-58

0.58
Demo Programs Delivered

Dev. class

Programs

Demo for

SLIS

BCALV_GRID_01 BCALV_GRID_02 BCALV_GRID_03 BCALV_GRID_04 BCALV_GRID_05 BCALV_GRID_06 BCALV_GRID_07 BCALV_GRID_08 BCALV_GRID_09 BCALV_GRID_10

Events for print lists Basic and details lists with one instance Detail list in modal dialog box Exception handling (exceptions / traffic light symbols) Self-defined pushbuttons in the toolbar Context menus Self-defined menus in the toolbar Toolbar menu with standard pushbutton Control options for display variants Initial usage of display variants

SAP AG 1999

You can find demo programs for the ALV Grid Control in development class SLIS. This development class is delivered.

(C) SAP AG

BC412

5-59

0.59
ALV Grid Control: Unit Summary

Now you are able to: Describe the features of the ALV Grid Control Display list data in the ALV Grid Control Read and change properties of the ALV Grid Control Format print lists with the ALV Grid Control Generate a field catalog

SAP AG 1999

(C) SAP AG

BC412

5-60