Está en la página 1de 36

ALV PROGRAMMING IN ABAP

Contents
Introduction..................................................................................................................2 Different Kinds of ALV outputs.....................................................................................3 Features of ALV............................................................................................................4 Benefits of ALV.............................................................................................................5 Steps to create a simple ALV Report............................................................................6 Initialize ALV..........................................................................................................8 Setting the ALV Layout..........................................................................................9 Layout Settings...............................................................................................9 Setting Field Catalog...........................................................................................16 Generating field catalog Automatically.........................................................18 Generating field catalog Manually................................................................18 Generating field catalog Semi-Automatically................................................18 Field Catalog Settings...................................................................................19 Setting Sort criteria.............................................................................................27 Sort Settings.................................................................................................27 Grid Settings........................................................................................................29 Grid Settings.................................................................................................29 Grid Title.......................................................................................................29 Events in ALV......................................................................................................30 PF-STATUS in ALV.........................................................................................32 Variants in ALV.............................................................................................32 Filter Settings......................................................................................................33 Display ALV.........................................................................................................34 ...........................................................................................................................36

Introduction
What is ALV? Page 2 of 36

Application List Viewer/ALV Grid Control (ALV = SAP List Viewer) ALV is an output list viewer/control which is a more flexible/interactive tool for displaying lists. This is more user friendly than ordinary list output. More over, ALV grid control has built in functionalities like sorting, filtering, summing, etc. It also allows user to develop user defined buttons/function codes. It presents numerous interfaces like Excel and Crystal Reports.

The wrapper class implemented to encapsulate ALV Grid functionality is CL_GUI_ALV_GRID. There is another way to display lists with ALV utilizing REUSE_ALV... functions. Here in this document, we will see about how to implement an ALV using REUSE_ALV functions.

Different Kinds of ALV outputs


The following are the different kinds of ALV outputs.

Page 3 of 36

ALV tree using Objects

ALV using Grid Function Modules

ALV using List Function modules

ALV using GRID Objects(Methods)

Features of ALV
Built-in functionality Page 4 of 36

a. Sorting b. Summing c. Subtotals d. Filtering e. Download to external applications f. Excel, Word, Text,etc Navigation to SAP transactions Standardized Report Presentation a. ALV Grid Presentation b. ALV List Presentation

Sort

Filter

Total

Local File

Print Prev

Excel

Word

Benefits of ALV
o Reduced Report Development Time and Cost

Page 5 of 36

Developer doesnt have to spend as much time on report layout (columns, spacing, sorting, totals, subtotals). More users friendly

Steps to create a simple ALV Report


Page 6 of 36

The following are the steps to create a simple ALV Report, Initialize ALV Control Setting the ALV Layout Setting up the field catalog for the presentation of columns Setting up the Sort criteria to be applied in the output Setting up the Grid settings if the output is needed in Grid format Setting up ALV events and customize each event according to need Filter settings on the output Display the ALV output with defined settings

The above mentioned steps are common for both ALV creation methods (through class CL_GUI_ALV_GRID or through REUSE_ALV function module). The general template which we can follow to develop any method of ALV report is
************************ Initiate ALV ***************************** * Initialization to display ALV in block mode PERFORM init_alv. * ALV Grid setting. PERFORM grid_setting USING gs_grid_settings. ********************** Layout setting logic *********************** * Build a layout for the ALV Grid. PERFORM layout_init USING gs_layout. ******************* Field List Catalog logic ********************** * Load field list catalog for detailed structure MOVE gc_fcat_structure TO gv_fcat_structure. * Build field catalog for ALV display PERFORM fieldcat_build CHANGING gt_fcat[]. ********************* Set field option logic ********************** * Set field options for ALV display PERFORM customize_fieldcatalog CHANGING gt_fcat[]. ********************* Sort settings logic ************************* * Sort settings for the ALV output. PERFORM sort_output TABLES gt_sort_list. * Build List Header for EVENT Top-of-Page. PERFORM comment_build USING gt_top_of_page[]. * Build an Event table PERFORM eventtab_build USING gt_events[]. ********************** Display ALV ******************************* * Display The ALV PERFORM display_alv .

Page 7 of 36

Initialize ALV
This is the initial step where the ALV control is initialized using the FM:REUSE_ALV_BLOCK_LIST_INIT
*&-----------------------------------------------------------------* *& Form init_alv * *&-----------------------------------------------------------------* * Initialize ALV Grid * *&-----------------------------------------------------------------* FORM init_alv. DATA lv_repid LIKE sy-repid. CLEAR lv_repid. lv_repid = sy-repid. CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_INIT' EXPORTING i_callback_program = lv_repid. ENDFORM.

The import and export parameters for the FM: REUSE_ALV_BLOCK_LIST_INIT is as follows:
FUNCTION REUSE_ALV_BLOCK_LIST_INIT. *"---------------------------------------------------------------------*"*"Lokale Schnittstelle: *" IMPORTING *" VALUE(I_CALLBACK_PROGRAM) LIKE SY-REPID *" VALUE(I_CALLBACK_PF_STATUS_SET) TYPE SLIS_FORMNAME *" DEFAULT SPACE *" VALUE(I_CALLBACK_USER_COMMAND) TYPE SLIS_FORMNAME *" DEFAULT SPACE *" VALUE(IT_EXCLUDING) TYPE SLIS_T_EXTAB OPTIONAL *"----------------------------------------------------------------------

The ALV report name should be passed as the value for the import parameter i_callback_program.

Page 8 of 36

Setting the ALV Layout


The layout setting is generic to ALV output layout like ZEBRA settings used to have alternate striped colors for each output row, whereas field catalog settings are specific to particular field of output.

Layout Settings
The following are some of the most important layout settings.
Field name CTAB_FNAME Short description Field name of table with cell color codes Optimize column width Purpose Field name in output table for coloring cells If this field is set, the ALV Grid Control optimizes the column width. You can then see the column header and the contents of the cells of this column. Value Range Character string of 30 characters at most

CWIDTH_OPT

SPACE, 'X'

DETAILINIT

Display initial values on detail screen

If this field is set, the detail screen also shows columns with initial values.

SPACE, 'X'

DETAILTITL

Title bar of detail screen

Title in the title bar of the detail screen.

Character string of 30 characters at most

GRID_TITLE

Text of title bar

Title between

Character string of 70 characters at most

Page 9 of 36

grid control and toolbar

INFO_FNAME

Name of field with row color codes Key columns as hotspot

KEYHOT

Field name in output table for coloring rows If this field is set, all key fields are hotspotsensitive. If a key field is clicked once, event hotspot click is triggered.

Character string of 30 characters at most

SPACE, 'X'

NO_HEADERS

Hide column headers

If this field is set, column headers are hidden.

SPACE, 'X'

NO_HGRIDLN

Hide horizontal grid lines

If this field is set, columns are displayed without horizontal grid lines.

SPACE, 'X'

NO_MERGING

Disable cell merging

If this field is set, cells are not merged when a column is sorted.

SPACE, 'X'

NO_ROWMARK

Hide row marks

If this field is set, the button at the beginning of a row is hidden in selection

SPACE, 'X'

Page 10 of 36

modes cell selection ( SEL_MODE = 'D' ) and column/row selection ( SEL_MODE = 'A' ).

NO_TOOLBAR

Hide toolbar

If this field is set, the toolbar is hidden.

SPACE, 'X'

NO_TOTARR

Do not display totals arrrows

The ALV Grid Control displays arrows in the totals line and the subtotals line that additionally indicate the totalling area. Set this parameter to suppress these arrows.

SPACE, 'X'

NO_TOTEXP

Do not display expand icons

An icon displayed at the beginning of a (sub)totals line indicates whether the line has been expanded or not. Set this parameter to suppress this icon.

SPACE, 'X'

NO_TOTLINE

Do not display

If this field is set, only

SPACE, 'X'

Page 11 of 36

totals line

subtotals, but no totals, are displayed.

NO_VGRIDLN

Hide vertical grid lines

If this field is set, columns are displayed without vertical grid lines.

SPACE, 'X'

NUMC_TOTAL

Allow totals calculation for NUMC fields

If this field is set, the user can calculate totals for fields of data type NUMC (normally, users are not allowed to do this).

SPACE, 'X'

S_DRAGDROP

Drag & Drop control settings

Structure for Drag & Drop settings .

SEL_MODE

Selection mode

Set the selection mode

SPACE, 'A', 'B', 'C', 'D' Value SPACE 'A' Mode same as 'B' Column and row selection (see graphic) Possible selections see 'B' Comment Default setting The user selects the rows through pushbuttons at the left border of the grid control.

Multiple columns Multiple rows

'B'

Simple selection, list box

Multiple columns Multiple rows

Page 12 of 36

'C'

Multiple selection, list box

Multiple columns Multiple rows Multiple columns Multiple rows Any cells

'D'

Cell selection

The user selects the rows through pushbuttons at the left border of the grid contro

SGL_CLK_HD

Single click on column header

Enables the single click on column header function. This function sorts the list in ascending order when the column is clicked for the first time, and then in descending order when the column is clicked a second time.

SPACE, 'X'

TOTALS_BEF

Totals output before single records

If this field is set, the ALV displays totals calculated as the first rows in the grid control. Subtotals are displayed before a new value of the subtotals criterion.

SPACE, 'X'

Page 13 of 36

ZEBRA

Alternating cell color (zebra pattern) for print output

If this field is set, the list shows a striped pattern in the print preview and when it is printed.

SPACE, 'X'

The layout settings is done by configuring the Layout as given below


*&-----------------------------------------------------------------* *& Form LAYOUT_INIT * *&-----------------------------------------------------------------* *& LAYOUT Settings for ALV report * *&-----------------------------------------------------------------* *& xy_layout <-> ALV layout structure. * *&-----------------------------------------------------------------* FORM layout_init CHANGING xy_layout TYPE slis_layout_alv. * Detail pop-up xy_layout-detail_popup = gc_false. * Detail with initial lines xy_layout-detail_initial_lines = gc_false. * Zebra stripes xy_layout-zebra = gc_true. * Display totals at top of list xy_layout-totals_before_items = gc_false. * Only display fields xy_layout-no_input = gc_false. * Optimize column width xy_layout-colwidth_optimize = gc_true. * Merge Cells xy_layout-cell_merge = gc_true. ENDFORM.

Page 14 of 36

This configured layout structure (xy_layout TYPE slis_layout_alv) is then passed to import parameter is_layout of the REUSE_ALV FM.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY' EXPORTING i_callback_program = lv_repid i_grid_title = lv_alv_title i_grid_settings = gs_grid_settings is_layout = gs_layout it_fieldcat = gt_fcat i_default = gc_true i_save = 'A' it_sort = gt_sort_list TABLES t_outtab = gt_output_display EXCEPTIONS program_error =1 OTHERS = 2.

Page 15 of 36

Setting Field Catalog


The field catalog setting is very important use of ALV output. This is used to set the formatting or option for specific field/group of fields of output fields . E.g.: Suppose we need to display the values of a particular column in the ALV output with leading zeros then this can be achieved using this field catalog settings. There are 3 methods of generating ALV Field catalogs o Generating field catalog Automatically o Generating filed catalog Manually o Generating field catalog semi-automatically SAP generates the default field catalog internal table with default settings based on the output structure specified using FM:REUSE_ALV_FIELDCATALOG_MERGE. Finally, this field catalog internal table is then passed to import parameter it_fieldcat of the ALV display FM:REUSE_ALV_..._DISPLAY to have required output.
*&-----------------------------------------------------------------* *& Form FIELDCATALOG BUILD * *&-----------------------------------------------------------------* *& Build Field catalog in ALV format * *&-----------------------------------------------------------------* *& <-- xyt_fcat field catalog ALV * *&-----------------------------------------------------------------* FORM fieldcat_build CHANGING xyt_fcat TYPE slis_t_fieldcat_alv. * Get field catalog of table and pass to the ALV container CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE' EXPORTING i_structure_name = gv_fcat_structure CHANGING ct_fieldcat = xyt_fcat EXCEPTIONS inconsistent_interface = 1 program_error =2 OTHERS = 3. IF sy-subrc NE 0. * Error:Error while merging field catalog for ALV Display. ENDIF. " if: sy-subrc NE 0 ENDFORM.

Page 16 of 36

The import and export parameters of FM: REUSE_ALV_FIELDCATALOG_MERGE is as follows:


function reuse_alv_fieldcatalog_merge. *"---------------------------------------------------------------------*"*"Lokale Schnittstelle: *" IMPORTING *" VALUE(I_PROGRAM_NAME) LIKE SY-REPID OPTIONAL *" VALUE(I_INTERNAL_TABNAME) TYPE SLIS_TABNAME OPTIONAL *" VALUE(I_STRUCTURE_NAME) LIKE DD02L-TABNAME OPTIONAL *" VALUE(I_CLIENT_NEVER_DISPLAY) TYPE SLIS_CHAR_1 DEFAULT 'X' *" VALUE(I_INCLNAME) LIKE TRDIR-NAME OPTIONAL *" VALUE(I_BYPASSING_BUFFER) TYPE CHAR01 OPTIONAL *" VALUE(I_BUFFER_ACTIVE) TYPE CHAR01 OPTIONAL *" CHANGING *" VALUE(CT_FIELDCAT) TYPE SLIS_T_FIELDCAT_ALV *" EXCEPTIONS *" INCONSISTENT_INTERFACE *" PROGRAM_ERROR *"----------------------------------------------------------------------

The output structure name and field catalog internal table is passed to i_structure_name and ct_fieldcat of FM: REUSE_ALV_FIELDCATALOG_MERGE respectively. REUSE_ALV_FIELDCATALOG_MERGE: This function module is used to populate a fieldcatalog which is essential to display the data in ALV. If the output data is from a single dictionary table and all the columns are selected, then we need not exclusively create the field catalog. Its enough to mention the table name as a parameter(I_structure_name) in the REUSE_ALV_LIST_DISPLAY. But in other cases we need to create it. The important parameters are: 1. Export: a. I_program_name : report id b. I_internal_tabname : the internal output table c. I_inclname : include or the report name where all the dynamic forms are handled. 2. Changing ct_fieldcat : an internal table with the type SLIS_T_FIELDCAT_ALV which is declared in the type pool SLIS.

Page 17 of 36

Generating field catalog Automatically


When the field catalog internal table with default settings is passed to display ALV FM without any change then it is generation of field catalog automatically.

Generating field catalog Manually


When each settings of the field catalog are configured and field catalog internal table is created manually, then it is generation of field catalog manually.
FORM customize_fieldcatalog CHANGING xyt_fcat TYPE slis_t_fieldcat_alv. * Declare local field-symbol. FIELD-SYMBOLS <lv_fcat> TYPE slis_fieldcat_alv. LOOP AT xyt_fcat ASSIGNING <lv_fcat>. * Set field options CASE <lv_fcat>-fieldname. * * * * * Prepare the Field catalog WHEN 'VKONT'. Key Field property <lv_fcat>-key = gc_true. No Sign property <lv_fcat>-no_sign = gc_false. No Zero property <lv_fcat>-no_zero = gc_false. Fixed Column property <lv_fcat>-fix_column = gc_false.

ENDCASE. ENDLOOP. ENDFORM.

Generating field catalog Semi-Automatically


When the field catalog internal table with default setting created by FM: REUSE_ALV_FIELDCATALOG_MERGE is modified as required and then passed to display ALV FM. Then it is generating field catalog semi-automatically.

Page 18 of 36

Field Catalog Settings


The following are some of the most important field catalog settings.
Field name CFIELDNAME Short description Field name for currency unit referenced Purpose Defining a reference to currency units. The ALV links the field specified in FIELDNAME to the field for currency units specified in CFIELDNAME . The field specified in CFIELDNAME must have a separate entry in the field catalog. Value Range SPACE, name of a field in the output

CHECKBOX

Output as checkbox

Outputting a checkbox. The checkbox cannot be modified by the user. Parameter sel_mode of the layout structure allows the user to select multiple rows in the grid control You can only access this field in readonly mode. As of Release 4.6C, this field is used (instead of the field name) to access columns of the output table. 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.

SPACE, 'X'

COL_ID

COL_POS

Numerical column identification (read-only) Position of output column

Number

Number

COLDDICTXT

Definition of DDIC text reference

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.

SPACE, 'L', 'M', 'S' and 'R'

COLTEXT

Column label for dialog functions

Determines the column header of the column. You should assign a value to this field if it does not have a Data

Freely definable text

Page 19 of 36

Dictionary reference.

CURRENCY

Currency unit

Explicitly specifying a currency (such as DEM , USD ). The ALV displays the values for the column specified in FIELDNAME according to the conventions for this currency.

name of a currency

DD_OUTLEN

Output length in characters

You use this field to specify the field output length for external display. This is only relevant to fields without reference to the Data Dictionary for which you want to modify the output using a conversion exit The column width (field OUTPUTLEN of the field catalog) does not need to be identical to the output length for external display ( DD_OUTLEN ).

0 (initial), n

DECIMALS_O

Number of decimal places for output

Relevant only if no currency field is assigned to the field and if CURRENCY has a value. The value in this field determines the number of digits to be displayed after the comma.

initial, natural number

DECMLFIELD

Field name with DECIMALS specification

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.

SPACE, field name of output table

DO_SUM

Totals calculation for column values

If this field is set, the ALV uses this field to calculate the total (this corresponds to the generic totals function in the toolbar.)

SPACE, 'X'

DRAGDROPID

Drag & Drop handle for Drag & Drop object EditMask for output

You use this field to define a D&D Behavior for Special Columns.

Drag & Drop handle

EDIT_MASK

EMPHASIZE

Column color

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. If the field is set to 'X', the ALV uses a pre-defined color for highlighting the column. If the character field begins with 'C' (color code), the remaining numbers

SPACE, conv (conversion exit)

SPACE, 'X' or 'Cxyz' (x:'1'-'9'; y,z: '0'=off '1'=on)

Page 20 of 36

have the following meaning:


EXPONENT Exponent for float representation

x: color number y: intensified display on/off y: inverse display on/off

Determines a fixed exponent for the field. The field must be of internal type F. (See also F1 help for WRITE edit option EXPONENT ).

initial, integer

FIELDNAME

Field name of internal table field

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.

Field name of output table (required)

HOTSPOT

Single-click sensitive

If this field is set, all cells of this column are hotspot-sensitive.

SPACE, 'X'

HREF_HNDLE ICON

Assign hyperlink Output as icon

INTLEN

Internal length in bytes

INTTYPE

ABAP data type (C,D,N,...) Justification

Handle to which an URL is assigned. The ALV Grid Control displays all cells of the column as hyperlinks 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 use this field to specify the field output length for internal display. This is only relevant to fields without reference to the Data Dictionary, for which you want to modify the output using a conversion exit Only required for field without reference to the Data Dictionary.

Natural number SPACE, 'X'

0 (initial), n

ABAP data type, see value range of domain INTTYPE SPACE, 'R', 'L','C'

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.

Page 21 of 36

KEY

Key column

LOWERCASE LZERO

Lower case allowed/not allowed Display leading zeros

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 If this field is set, the ALV Grid Control recognizes upper/lower case in the output table. 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.

SPACE, 'X'

SPACE, 'X' SPACE, 'X'

NO_MERGING

Do not merge cells

If this field is set, cells with the same value are not merged into a single cell when this column is sorted.

SPACE, 'X'

NO_OUT

Do not display columns

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.

SPACE, 'X'

NO_SIGN NO_SUM

Supress sign in display No totals calculation for column values Suppress zeros in display

Relevant only to value fields. If you set NO-SIGN , values are displayed without signs If you set this field, you lock totals calculation for the relevant field.

SPACE, 'X' SPACE, 'X'

NO_ZERO

If NO_ZERO is set, no zeros are displayed for initial value fields. The cell remains empty.

SPACE, 'X'

OUTPUTLEN

Column width in characters

Determines the column width of the field:

0 (default setting), n

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

Page 22 of 36

domain. For fields without reference to the DDIC, you must specify the desired field output length.

QFIELDNAME

Field name for quantity unit referenced

Defining a reference to quantity units. The ALV links the field specified in FIELDNAME to the field for quantity units specified in QFIELDNAME . The field specified in QFIELDNAME must have a separate entry in the field catalog.

SPACE, name of a field in the output table

QUANTITY

Quantity unit

Explicitly specifying a unit (such as KG ). The ALV displays the values for the column specified in FIELDNAME according to the conventions for this unit.

SPACE, name of a unit

REF_FIELD

Reference field name for internal table 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.

SPACE, name of a field in the Data Dictionary that corresponds to a field in the output table

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

Reference table name for internal table field

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, for example.

SPACE, name of a structure or table from the Data Dictionary that corresponds to a field in the output table.

REPREP

Property is selection criterion for report/report

'X' = if the report/report interface is called, the value of this field is passed in the selected jump line of the interface as a selection criterion.

SPACE, 'X'

Page 23 of 36

REPTEXT

interface Header (DDIC text of the corresponding data element)

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.

Text copied from the Data Dictionary

ROLLNAME

Data element for F1 help

If you want to provide F1 help for an output field without Data Dictionary reference or if you want to define a different F1 help than that stored in the DDIC for a field with DDIC reference, you can use this field. If F1 help is called for this field, the documentation for the data element assigned is displayed. If ROLLNAME is initial for fields with Data Dictionary reference, the documentation for the data element of the referenced field of the Data Dictionary is displayed.

SPACE, name of a data element of the Data Dictionary

ROUND

ROUND value

ROUNDFIELD

Field name with ROUND specification

Displaying a value of type P scaled by the power of ten. For positive ROUND values, the ALV Grid Control moves the comma to the left; otherwise, it moves the comma to the right. Defining scaled output on a row-by-rowbasis. You can use an additional field in the output table to determine how the relevant field is scaled in each row.

initial, natural number

SCRTEXT_L

Long field label (DDIC text of the corresponding data element)

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.

Text copied from the Data Dictionary

SCRTEXT_M

Medium field label (DDIC text of the corresponding data element)

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.

Text copied from the Data Dictionary

SCRTEXT_S

Short field label (DDIC text of the corresponding data element)

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.

Text copied from the Data Dictionary

Page 24 of 36

SELDDICTXT

Definition of DDIC text reference

Relevant only to fields with reference to the. 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.

SPACE, 'L', 'M', 'S' and 'R'

SELTEXT

Column label for dialog function

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.

Freely definable text

SP_GROUP

Group key

SYMBOL

Output as symbol

You use the group key to group several fields together. On the dialog box for defining a layout, the user can then limit the list of hidden columns to this group. If this field is set, the column contents are displayed as a symbol. The column contents of the internal table must consist of valid symbol signs. The caller should consider the problem of printing symbols. (It is usually possible to print symbols, but they may not be output correctly depending on the printer configuration).

SPACE, fourdigit group key SPACE, 'X'

TECH

Technical fields

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).

SPACE, 'X'

TIPDDICTXT

Definition of DDIC text reference

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.

SPACE, 'L', 'M', 'S' and 'R'

TOOLTIP

Tool tip for column header

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.

Freely definable text

TXT_FIELD

Field name of internal table field

You can use this field to define a reference to a field that is used as the description for the current field. If a subtotal is calculated for the current

SPACE, field name of the output table

Page 25 of 36

field, the ALV Grid Control displays the descriptions in the field assigned.

WEB_FIELD

Field name of internal table field (for hyperlink)

You can use this field to define hyperlinks at cell level.

Name of a field of the output table

Page 26 of 36

Setting Sort criteria


The sort settings are used to have the output is specific sort order by default. The sort setting is achieved by creating the internal table of type slis_t_sortinfor_alv with sort field name and available sort options as given below.
*&-----------------------------------------------------------------* *& Form sort_output * *&-----------------------------------------------------------------* *& Sort settings for ALV Grid * *&-----------------------------------------------------------------* *& xyt_sort_list <-> Sort information table * *&-----------------------------------------------------------------* FORM sort_output CHANGING xyt_sort_list TYPE slis_t_sortinfo_alv. DATA: lv_sort TYPE slis_sortinfo_alv. CLEAR xyt_sort_list[]. * Sort the fields as required lv_sort-fieldname = 'ABLBELNR'. lv_sort-spos =2. lv_sort-up = gc_true. lv_sort-subtot = gc_true. APPEND lv_sort TO xyt_sort_list. CLEAR lv_sort. ENDFORM.

Finally , the internal table with sort settings is passed to the import parameter it_sort of the display ALV FM to output as defined in sort settings.

Sort Settings
The following are some important sort settings options available.
Field name SPOS FIELDNAME UP DOWN SUBTOT GROUP Description Sort order if the list is sorted by multiple columns Field name in the internal output table 'X' = Sorted in ascending order 'X' = Sorted in descending order 'X' = Subtotal at group level change Once a column is sorted, it is subdivided into groups. This means there is one group for each value of the column (in the default setting, the ALV Grid Control merges cells that have the same value in the sort column). If the value in the sort colulmn changes, this is called a group level change. You can use this field to determine the formatting of this value when

Page 27 of 36

the list is printed: '* ' = Page break at group level change 'UL' = Underline at group level change (The formatting options are fixed domain values of domain SLIS_CTRLS ).

Page 28 of 36

Grid Settings
The grid setting option is available for only ALV grid type output. In the case of ALV list type output the grid setting is not applied. In order to achieve the grid settings, modify the grid setting variable of type lvc_s_glay.
*&-----------------------------------------------------------------* *& Form GRID_SETTING * *&-----------------------------------------------------------------* *& ALV Grid setting for the ALV output * *&-----------------------------------------------------------------* *& xy_grid_setting <-> Structure for grid settings * *&-----------------------------------------------------------------* FORM grid_setting CHANGING xy_grid_settings STRUCTURE lvc_s_glay. * Minimize Header section xy_grid_settings-coll_top_p = gc_true. xy_grid_settings-coll_end_l = gc_true. ENDFORM.

Grid Settings
The structure lvc_s_glay has following fields in it.
Field Name COLL_TOP_P COLL_END_L TOP_P_ONLY EOL_P_ONLY NO_COLWOPT EDT_CLL_CB Datatype CHAR CHAR CHAR CHAR CHAR CHAR Length 1 1 1 1 1 1 Description Minimize TOP_OF_PAGE Minimize END_OF_LIST Top_Of_Page only at printing END_OF_LIST only at printing ALV control: Do not optimize column width for printing ALV control: Callback when leaving an edited cell

The grid setting variable with modified settings is then passed to the import parameter i_grid_settings of Display ALV FM.

Grid Title
The grid title which is the title to be displayed on the top of the ALV output is passed to the import parameter i_grid_title of the Display ALV FM. The grid title should be of datatype char (70).

Page 29 of 36

Events in ALV
All the possible events of ALV list is obtained using FM: REUSE_ALV_EVENTS_GET. REUSE_ALV_EVENTS_GET: Returns table of possible events for a list type Import: Et_Events : The event table is returned with all possible CALLBACK events for the specified list type (column NAME). For events to be processed by the Callback, their FORM field must be filled. If the field is initialized, the event is ignored. The entry can be read from the event table, the field FORM filled and the entry modified using constants from the type pool SLIS. Export: I_list_type: 0 = simple list 1 = hierarchical-sequential list 2 = simple block list 3 = hierarchical-sequential block list REUSE_ALV_COMMENTARY_WRITE : This is used in the Top-of-page event to print the headings and other comments for the list. 1. It_list_commentary : Internal table with the headings of the type slis_t_listheader. This internal table has three fields: Typ : H - header, S - selection, A - action Key : only when typ is S. Info : the text to be printed

The example code is given below

*&---------------------------------------------------------------------* *& FORM EVENTTAB_BUILD * *&---------------------------------------------------------------------* * Register for ALV Grid events * *----------------------------------------------------------------------* * <-> xyt_events ALV Events Table * *----------------------------------------------------------------------* FORM eventtab_build USING xyt_events TYPE slis_t_event. DATA: ls_event TYPE slis_alv_event. CALL FUNCTION 'REUSE_ALV_EVENTS_GET' EXPORTING i_list_type =0 IMPORTING et_events = xyt_events EXCEPTIONS list_type_wrong = 1 OTHERS = 2.

Page 30 of 36

* Register Top-of-Page event. READ TABLE xyt_events WITH KEY name = slis_ev_top_of_page INTO ls_event. IF sy-subrc EQ 0. MOVE gc_top_of_page TO ls_event-form. APPEND ls_event TO xyt_events. ENDIF. "if: sy-subrc NE 0 ENDFORM. "eventtab_build

Here in this example the FM: 'REUSE_ALV_EVENTS_GET' returns all possible values and the event TOP_OP_PAGE is activated by assigning a form name TOP_OF_PAGE to the event table which of type slis_t_event. So the form with name top_of_page is mandatory as that event with corresponding name is register in event table.
*&---------------------------------------------------------------------* *& FORM COMMENT_BUILD * *&---------------------------------------------------------------------* * Build the Top-of-Page commentary for the selection criteria * *----------------------------------------------------------------------* * <-> xyt_top_of_page ALV Top-of-page Table * *----------------------------------------------------------------------* FORM comment_build USING xyt_top_of_page LIKE gt_top_of_page[]. * List Heading Lines: Type 'H' CLEAR ls_line. ls_line-typ = 'H'. * ls_line-key = "not used for this type ls_line-info = text-h45. APPEND ls_line TO xyt_top_of_page. ENDFORM. "comment_build

*&---------------------------------------------------------------------* *& FORM TOP_OF_PAGE *&---------------------------------------------------------------------* * Top-of-Page ALV Grid Event sub-routine *----------------------------------------------------------------------* FORM top_of_page. CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE' EXPORTING it_list_commentary = gt_top_of_page. ENDFORM. "top_of_page

* *

Here the text to be displayed is populated in gt_top_of_page which is of type slis_t_listheader and the passed to the FM: 'REUSE_ALV_COMMENTARY_WRITE'. The import parameters of FM: : 'REUSE_ALV_COMMENTARY_WRITE' is as follows:
FUNCTION REUSE_ALV_COMMENTARY_WRITE. *"---------------------------------------------------------------------*"*"Lokale Schnittstelle: *" IMPORTING

Page 31 of 36

*" VALUE(IT_LIST_COMMENTARY) TYPE SLIS_T_LISTHEADER *" REFERENCE(I_LOGO) OPTIONAL *" REFERENCE(I_END_OF_LIST_GRID) OPTIONAL *"----------------------------------------------------------------------

PF-STATUS in ALV
Setting PF-STATUS in ALV is same as any other report where the internal table excltab is used to hide and unhide the gui items. * * Hide summary button isu_mac_excltab lv_button1. UnHide DELETE excltab WHERE fcode EQ BUTTON1.

Where excltab is internal table like BEGIN OF excltab OCCURS 999, fcode LIKE regen-okcode, END OF excltab. Eg: SET PF-STATUS '0100' EXCLUDING excltab. * Set PF-Status PERFORM pf_status_set USING lt_exttab.

Where lt_extab is internal table of type slis_t_extab. Then based on the lt_exttab value the PF status can be changed.

Variants in ALV
The default variants can be created and applied to the Display ALV FM by passing the variant value (which of type disvariant) to the import parameter is_variant of Display ALV FM.

Page 32 of 36

Filter Settings
Filter settings are used to have a output criteria/selectionoptions which are applied by default. The following are the different filter options available.
fieldname type slis_fieldname, tabname type slis_tabname, seltext(40), valuf(80), valut(80), valuf_int(80), valut_int(80), sign0(1), sign_icon(4), optio(2), stype(1), decimals like dfies-decimals, intlen like dfies-intlen, convexit like dfies-convexit, edit_mask type slis_edit_mask, lowercase like dfies-lowercase, inttype like dfies-inttype, datatype like dfies-datatype, exception(1) type c, no_sign(1) type c, or(1) type c, order type order, cqvalue(5) type c, ref_fieldname like dfies-fieldname, ref_tabname like dfies-tabname, ddic_outputlen like dfies-outputlen,

which

has

certain

filter

The following are the example code for filter settings.


lv_filter-fieldname = FIELDNAME. lv_filter-valuf_int = VALUE. lv_filter-sign0 = SIGN. lv_filter-optio = OPTION. APPEND lv_filter TO gt_filter_list.

Where gt_filter_list is of type slis_t_filter_alv. This populated internal table is then passed as the import parameter it_filter of the display ALV FM.

Page 33 of 36

Display ALV
All the above ALV settings should be passed to the standard SAP function modules REUSE_ALV in order to get the defined output. There are two different function modules REUSE_ALV_GRID_DISPLAY and REUSE_ALV_LIST_DISPLAY respectively. The import and export parameters of REUSE_ALV_GRID_DISPLAY is as follows,
function reuse_alv_grid_display. *"---------------------------------------------------------------------*"*"Globale Schnittstelle: *" IMPORTING *" REFERENCE(I_INTERFACE_CHECK) DEFAULT SPACE *" VALUE(I_BYPASSING_BUFFER) TYPE CHAR01 DEFAULT SPACE *" VALUE(I_BUFFER_ACTIVE) DEFAULT SPACE *" REFERENCE(I_CALLBACK_PROGRAM) LIKE SY-REPID DEFAULT SPACE *" REFERENCE(I_CALLBACK_PF_STATUS_SET) TYPE SLIS_FORMNAME DEFAULT *" SPACE *" REFERENCE(I_CALLBACK_USER_COMMAND) TYPE SLIS_FORMNAME DEFAULT *" SPACE *" REFERENCE(I_CALLBACK_TOP_OF_PAGE) TYPE SLIS_FORMNAME DEFAULT *" SPACE *" REFERENCE(I_CALLBACK_HTML_TOP_OF_PAGE) TYPE SLIS_FORMNAME *" DEFAULT SPACE *" REFERENCE(I_CALLBACK_HTML_END_OF_LIST) TYPE SLIS_FORMNAME *" DEFAULT SPACE *" REFERENCE(I_STRUCTURE_NAME) LIKE DD02L-TABNAME OPTIONAL *" REFERENCE(I_BACKGROUND_ID) TYPE SDYDO_KEY DEFAULT SPACE *" REFERENCE(I_GRID_TITLE) TYPE LVC_TITLE OPTIONAL *" REFERENCE(I_GRID_SETTINGS) TYPE LVC_S_GLAY OPTIONAL *" REFERENCE(IS_LAYOUT) TYPE SLIS_LAYOUT_ALV OPTIONAL *" REFERENCE(IT_FIELDCAT) TYPE SLIS_T_FIELDCAT_ALV OPTIONAL *" REFERENCE(IT_EXCLUDING) TYPE SLIS_T_EXTAB OPTIONAL *" REFERENCE(IT_SPECIAL_GROUPS) TYPE SLIS_T_SP_GROUP_ALV OPTIONAL *" REFERENCE(IT_SORT) TYPE SLIS_T_SORTINFO_ALV OPTIONAL *" REFERENCE(IT_FILTER) TYPE SLIS_T_FILTER_ALV OPTIONAL *" REFERENCE(IS_SEL_HIDE) TYPE SLIS_SEL_HIDE_ALV OPTIONAL *" REFERENCE(I_DEFAULT) DEFAULT 'X' *" REFERENCE(I_SAVE) DEFAULT SPACE *" REFERENCE(IS_VARIANT) LIKE DISVARIANT STRUCTURE DISVARIANT *" OPTIONAL *" REFERENCE(IT_EVENTS) TYPE SLIS_T_EVENT OPTIONAL *" REFERENCE(IT_EVENT_EXIT) TYPE SLIS_T_EVENT_EXIT OPTIONAL *" REFERENCE(IS_PRINT) TYPE SLIS_PRINT_ALV OPTIONAL *" REFERENCE(IS_REPREP_ID) TYPE SLIS_REPREP_ID OPTIONAL *" REFERENCE(I_SCREEN_START_COLUMN) DEFAULT 0 *" REFERENCE(I_SCREEN_START_LINE) DEFAULT 0 *" REFERENCE(I_SCREEN_END_COLUMN) DEFAULT 0 *" REFERENCE(I_SCREEN_END_LINE) DEFAULT 0 *" REFERENCE(IT_ALV_GRAPHICS) TYPE DTC_T_TC OPTIONAL *" REFERENCE(IT_HYPERLINK) TYPE LVC_T_HYPE OPTIONAL *" REFERENCE(IT_ADD_FIELDCAT) TYPE SLIS_T_ADD_FIELDCAT OPTIONAL *" REFERENCE(IT_EXCEPT_QINFO) TYPE SLIS_T_QINFO_ALV OPTIONAL *" REFERENCE(I_HTML_HEIGHT_TOP) TYPE I OPTIONAL *" REFERENCE(I_HTML_HEIGHT_END) TYPE I OPTIONAL *" EXPORTING *" REFERENCE(E_EXIT_CAUSED_BY_CALLER)

Page 34 of 36

*" REFERENCE(ES_EXIT_CAUSED_BY_USER) TYPE SLIS_EXIT_BY_USER *" TABLES *" T_OUTTAB *" EXCEPTIONS *" PROGRAM_ERROR *"----------------------------------------------------------------------

Similarly, the ALV List layout is achieved using the function module, REUSE_ALV_LIST_DISPLAY.
function reuse_alv_list_display. *"---------------------------------------------------------------------*"*"Lokale Schnittstelle: *" IMPORTING *" VALUE(I_INTERFACE_CHECK) DEFAULT SPACE *" VALUE(I_BYPASSING_BUFFER) TYPE CHAR01 OPTIONAL *" VALUE(I_BUFFER_ACTIVE) DEFAULT SPACE *" VALUE(I_CALLBACK_PROGRAM) LIKE SY-REPID DEFAULT SPACE *" VALUE(I_CALLBACK_PF_STATUS_SET) TYPE SLIS_FORMNAME DEFAULT *" SPACE *" VALUE(I_CALLBACK_USER_COMMAND) TYPE SLIS_FORMNAME DEFAULT SPACE *" VALUE(I_STRUCTURE_NAME) LIKE DD02L-TABNAME OPTIONAL *" VALUE(IS_LAYOUT) TYPE SLIS_LAYOUT_ALV OPTIONAL *" VALUE(IT_FIELDCAT) TYPE SLIS_T_FIELDCAT_ALV OPTIONAL *" VALUE(IT_EXCLUDING) TYPE SLIS_T_EXTAB OPTIONAL *" VALUE(IT_SPECIAL_GROUPS) TYPE SLIS_T_SP_GROUP_ALV OPTIONAL *" VALUE(IT_SORT) TYPE SLIS_T_SORTINFO_ALV OPTIONAL *" VALUE(IT_FILTER) TYPE SLIS_T_FILTER_ALV OPTIONAL *" VALUE(IS_SEL_HIDE) TYPE SLIS_SEL_HIDE_ALV OPTIONAL *" VALUE(I_DEFAULT) DEFAULT 'X' *" VALUE(I_SAVE) DEFAULT SPACE *" VALUE(IS_VARIANT) LIKE DISVARIANT STRUCTURE DISVARIANT *" OPTIONAL *" VALUE(IT_EVENTS) TYPE SLIS_T_EVENT OPTIONAL *" VALUE(IT_EVENT_EXIT) TYPE SLIS_T_EVENT_EXIT OPTIONAL *" VALUE(IS_PRINT) TYPE SLIS_PRINT_ALV OPTIONAL *" VALUE(IS_REPREP_ID) TYPE SLIS_REPREP_ID OPTIONAL *" VALUE(I_SCREEN_START_COLUMN) DEFAULT 0 *" VALUE(I_SCREEN_START_LINE) DEFAULT 0 *" VALUE(I_SCREEN_END_COLUMN) DEFAULT 0 *" VALUE(I_SCREEN_END_LINE) DEFAULT 0 *" EXPORTING *" VALUE(E_EXIT_CAUSED_BY_CALLER) *" VALUE(ES_EXIT_CAUSED_BY_USER) TYPE SLIS_EXIT_BY_USER *" TABLES *" T_OUTTAB *" EXCEPTIONS *" PROGRAM_ERROR *"----------------------------------------------------------------------

Page 35 of 36

The configured settings are passed to the ALV display function module as follows

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY' EXPORTING i_callback_program = lv_repid i_grid_title = lv_alv_title i_grid_settings = gs_grid_settings is_layout = gs_layout it_fieldcat = gt_fcat i_default = gc_true i_save = 'A' it_sort = gt_sort_list TABLES t_outtab = gt_output_display EXCEPTIONS program_error =1 OTHERS = 2. Or CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY' EXPORTING i_callback_program = lv_repid is_layout = gs_layout it_fieldcat = gt_fcat i_default = gc_true i_save = 'A' it_sort = gt_sort_list TABLES t_outtab = gt_output_display EXCEPTIONS program_error =1 OTHERS = 2.

Page 36 of 36

También podría gustarte