ALV Ejemplo Completo

46
ALV PROGRAMMING IN ABAP

Transcript of ALV Ejemplo Completo

Page 1: ALV Ejemplo Completo

ALV PROGRAMMING

IN

ABAP

Page 2: ALV Ejemplo Completo

Contents1. Introduction...........................................................................................................32. Different Kinds of ALV outputs...............................................................................43. Features of ALV.....................................................................................................54. Benefits of ALV......................................................................................................65. Steps to create a simple ALV Report.....................................................................7

5.1. Initialize ALV..............................................................................................85.2. Setting the ALV Layout..............................................................................9

5.2.1. Layout Settings....................................................................................95.3. Setting Field Catalog...............................................................................16

5.3.1. Generating field catalog Automatically..............................................185.3.2. Generating field catalog Manually.....................................................185.3.3. Generating field catalog Semi-Automatically.....................................185.3.4. Field Catalog Settings........................................................................19

5.4. Setting Sort criteria.................................................................................275.4.1. Sort Settings......................................................................................27

5.5. Grid Settings...........................................................................................295.5.1. Grid Settings......................................................................................295.5.2. Grid Title............................................................................................29

5.6. Events in ALV..........................................................................................305.6.1. PF-STATUS in ALV..............................................................................325.6.2. Variants in ALV..................................................................................32

5.7. Filter Settings..........................................................................................335.8. Display ALV.............................................................................................34

1. Introduction

What is ALV? Application List Viewer/ALV Grid Control (ALV = SAP List Viewer)

Page 2 of 36

Page 3: ALV Ejemplo Completo

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.

2. Different Kinds of ALV outputsThe following are the different kinds of ALV outputs.

Page 3 of 36

Page 4: ALV Ejemplo Completo

ALV tree using Objects

ALV using Grid Function Modules

ALV using List Function modules

ALV using GRID Objects(Methods)

3. Features of ALV Built-in functionality

a. Sorting

Page 4 of 36

Page 5: ALV Ejemplo Completo

b. Summingc. Subtotalsd. Filteringe. Download to external applicationsf. Excel, Word, Text,etc

Navigation to SAP transactions Standardized Report Presentation

a. ALV Grid Presentationb. ALV List Presentation

4. Benefits of ALVo Reduced Report Development Time and Cost

Developer doesn’t have to spend as much time on report layout (columns, spacing, sorting, totals, subtotals).

o More users friendly

Page 5 of 36

Sort Filter Total

Print Prev Excel Word

Local File

Page 6: ALV Ejemplo Completo

5. Steps to create a simple ALV Report

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

Page 6 of 36

Page 7: ALV Ejemplo Completo

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 .

5.1. Initialize ALVThis is the initial step where the ALV control is initialized using the FM:’REUSE_ALV_BLOCK_LIST_INIT’

*&-----------------------------------------------------------------**& Form init_alv **&-----------------------------------------------------------------*

Page 7 of 36

Page 8: ALV Ejemplo Completo

* 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

Page 9: ALV Ejemplo Completo

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

5.2.1. Layout SettingsThe following are some of the most important layout settings.

Field name Short description

Purpose Value Range

CTAB_FNAME Field name of table with cell color codes

Field name in output table for coloring cells

Character string of 30 characters at most

CWIDTH_OPT Optimize column width

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.

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

Page 9 of 36

Page 10: ALV Ejemplo Completo

GRID_TITLE Text of title bar

Title between grid control and toolbar

Character string of 70 characters at most

INFO_FNAME Name of field with row color codes

Field name in output table for coloring rows

Character string of 30 characters at most

KEYHOT Key columns as hotspot

If this field is set, all key fields are hotspot-sensitive. If a key field is clicked once, event hotspot click is triggered.

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'

Page 10 of 36

Page 11: ALV Ejemplo Completo

NO_ROWMARK

Hide row marks

If this field is set, the button at the beginning of a row is hidden in selection modes cell selection ( SEL_MODE = 'D' ) and column/row selection ( SEL_MODE = 'A' ).

SPACE, 'X'

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

SPACE, 'X'

Page 11 of 36

Page 12: ALV Ejemplo Completo

has been expanded or not. Set this parameter to suppress this icon.

NO_TOTLINE Do not display totals line

If this field is set, only subtotals, but no totals, are displayed.

SPACE, 'X'

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

Mode Possible selections

Comment

SPACE

same as 'B'

see 'B' Default setting

'A' Column and row

Multiple The user selects the

Page 12 of 36

Page 13: ALV Ejemplo Completo

selection(see graphic)

columns

Multiple rows

rows through pushbuttons at the left border of the grid control.

'B' Simple selection, list box

Multiple columns

Multiple rows

 

'C' Multiple selection, list box

Multiple columns

Multiple rows

 

'D' Cell selection

Multiple columns

Multiple rows

Any cells

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

SPACE, 'X'

Page 13 of 36

Page 14: ALV Ejemplo Completo

rows in the grid control. Subtotals are displayed before a new value of the subtotals criterion.

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

Page 15: ALV Ejemplo Completo

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

Page 16: ALV Ejemplo Completo

5.3. 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 catalogso Generating field catalog Automaticallyo Generating filed catalog Manuallyo 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

Page 17: ALV Ejemplo Completo

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

Page 18: ALV Ejemplo Completo

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

5.3.2. Generating field catalog ManuallyWhen 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.

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

Page 19: ALV Ejemplo Completo

5.3.4. Field Catalog Settings

The following are some of the most important field catalog settings.

Field name Short description

Purpose Value Range

CFIELDNAME Field name for currency unit referenced

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.

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

SPACE, 'X'

COL_ID Numerical column identification (read-only)

You can only access this field in read-only mode. As of Release 4.6C, this field is used (instead of the field name) to access columns of the output table.

Number

COL_POS Position of output column

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.

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 Dictionary reference.

Freely definable text

CURRENCY Currency unit Explicitly specifying a currency (such as name of a

Page 19 of 36

Page 20: ALV Ejemplo Completo

DEM , USD ). The ALV displays the values for the column specified in FIELDNAME according to the conventions for this currency.

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

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

Drag & Drop handle

EDIT_MASK EditMask for output

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.

SPACE, conv (conversion exit)

EMPHASIZE Column color 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 have the following meaning:

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

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

Page 20 of 36

Page 21: ALV Ejemplo Completo

EXPONENT Exponent for float representation

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 Assign hyperlink

Handle to which an URL is assigned. The ALV Grid Control displays all cells of the column as hyperlinks

Natural number

ICON Output as icon

If this field is set, the column contents of the output table are output as an icon. The column contents must consist of valid icon strings ( @xx@ or @xx\Q <Quickinfo> @ ).

SPACE, 'X'

INTLEN Internal length in bytes

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

0 (initial), n

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

Only required for field without reference to the Data Dictionary.

ABAP data type, see value range of domain INTTYPE

JUST Justification 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.

SPACE, 'R', 'L','C'

KEY Key column 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

SPACE, 'X'

LOWERCASE Lower case If this field is set, the ALV Grid Control SPACE, 'X'

Page 21 of 36

Page 22: ALV Ejemplo Completo

allowed/not allowed

recognizes upper/lower case in the output table.

LZERO Display leading zeros

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'

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 Supress sign in display

Relevant only to value fields. If you set NO-SIGN , values are displayed without signs

SPACE, 'X'

NO_SUM No totals calculation for column values

If you set this field, you lock totals calculation for the relevant field.

SPACE, 'X'

NO_ZERO Suppress zeros in display

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:

If the field has a reference to the Data Dictionary, you can leave the field set to its initial value. In this case, the ALV adopts the output length of the relevant domain.

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

0 (default setting), n

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

Page 22 of 36

Page 23: ALV Ejemplo Completo

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.

If the field names are identical, it is sufficient to specify the DDIC structure or table in field REF_TABLE of the field catalog.

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

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 interface

'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'

REPTEXT 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

SPACE, name of a data element of the Data Dictionary

Page 23 of 36

Page 24: ALV Ejemplo Completo

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.

ROUND ROUND value 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.

initial, natural number

ROUNDFIELD Field name with ROUND specification

Defining scaled output on a row-by-row-basis. You can use an additional field in the output table to determine how the relevant field is scaled in each row.

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

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 You use the group key to group several fields together. On the dialog box for defining a layout, the user can then

SPACE, four-digit group key

Page 24 of 36

Page 25: ALV Ejemplo Completo

limit the list of hidden columns to this group.

SYMBOL Output as symbol

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, '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 field, the ALV Grid Control displays the descriptions in the field assigned.

SPACE, field name of the output table

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 25 of 36

Page 26: ALV Ejemplo Completo

Page 26 of 36

Page 27: ALV Ejemplo Completo

5.4. Setting Sort criteriaThe 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.

5.4.1. Sort Settings

The following are some important sort settings options available.

Field name DescriptionSPOS Sort order if the list is sorted by multiple columnsFIELDNAME Field name in the internal output tableUP 'X' = Sorted in ascending orderDOWN 'X' = Sorted in descending orderSUBTOT 'X' = Subtotal at group level changeGROUP 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

Page 27 of 36

Page 28: ALV Ejemplo Completo

when 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

Page 29: ALV Ejemplo Completo

5.5. Grid SettingsThe 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.

5.5.1. Grid SettingsThe structure lvc_s_glay has following fields in it.

Field Name Datatype

Length Description

COLL_TOP_P CHAR 1 Minimize TOP_OF_PAGECOLL_END_L CHAR 1 Minimize END_OF_LISTTOP_P_ONLY CHAR 1 Top_Of_Page only at printingEOL_P_ONLY CHAR 1 END_OF_LIST only at printingNO_COLWOPT CHAR 1 ALV control: Do not optimize

column width for printingEDT_CLL_CB CHAR 1 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.

5.5.2. Grid TitleThe 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

Page 30: ALV Ejemplo Completo

5.6. 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 listREUSE_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.* Register Top-of-Page event. READ TABLE xyt_events WITH KEY name = slis_ev_top_of_page

Page 30 of 36

Page 31: ALV Ejemplo Completo

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*" VALUE(IT_LIST_COMMENTARY) TYPE SLIS_T_LISTHEADER*" REFERENCE(I_LOGO) OPTIONAL*" REFERENCE(I_END_OF_LIST_GRID) OPTIONAL

Page 31 of 36

Page 32: ALV Ejemplo Completo

*"----------------------------------------------------------------------

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

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

5.7. Filter SettingsFilter settings are used to have a output which has certain filter criteria/selectionoptions which are applied by default.The following are the different filter options available.

Page 32 of 36

Page 33: ALV Ejemplo Completo

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,

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.

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

Page 33 of 36

Page 34: ALV Ejemplo Completo

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)*" REFERENCE(ES_EXIT_CAUSED_BY_USER) TYPE SLIS_EXIT_BY_USER*" TABLES*" T_OUTTAB*" EXCEPTIONS*" PROGRAM_ERROR

Page 34 of 36

Page 35: ALV Ejemplo Completo

*"----------------------------------------------------------------------

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*"----------------------------------------------------------------------

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

Page 35 of 36

Page 36: ALV Ejemplo Completo

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