+ All Categories
Home > Documents > ALV_StepByStep_12Aug20083211281700880

ALV_StepByStep_12Aug20083211281700880

Date post: 09-Apr-2018
Category:
Upload: karthik-reddy
View: 218 times
Download: 0 times
Share this document with a friend

of 35

Transcript
  • 8/7/2019 ALV_StepByStep_12Aug20083211281700880

    1/35

    ALV DOCUMENTATION AND EXAMPLES11 Rajagopalan. M

    ALV (ABAP LIST VIEWER)

    Sap provides a set of ALV (ABAP LIST VIEWER) function modules, which can be put intouse to embellish the output of a report. This set of ALV functions is used to enhance the

    readability and functionality of any report output. Cases arise in sap when the output of areport contains columns extending more than 255 characters in length. In such cases, this setof ALV functions can help choose selected columns and arrange the different columns from areport output and also save different variants for report display. This is a very efficient toolfor dynamically sorting and arranging the columns from a report output. The report output cancontain upto 90 columns in the display with the wide array of display options.

    The commonly used ALV functions used for this purpose are;

    1. REUSE_ALV_VARIANT_DEFAULT_GET2. REUSE_ALV_VARIANT_F43. REUSE_ALV_VARIANT_EXISTENCE4. REUSE_ALV_EVENTS_GET5. REUSE_ALV_COMMENTARY_WRITE6. REUSE_ALV_FIELDCATALOG_MERGE7. REUSE_ALV_LIST_DISPLAY8. REUSE_ALV_GRID_DISPLAY9. REUSE_ALV_POPUP_TO_SELECT

    The different steps used for getting the above function modules into use are :

    Step 1

    DATA DECLARATION

    Sap standard type pools: SLIS , KKBLO .

    Sap standard tables types taken from the type pools are: SLIS_LAYOUT_ALV ,SLIS_T_FIELDCAT_ALV,SLIS_T_LISTHEADER,SLIS_T_EVENT,SLIS_SELFIELD.

    Internal tables to used in the program declared based on the above table types

    DATA: I_LAYOUT TYPE SLIS_LAYOUT_ALV,I_FIELDTAB TYPE SLIS_T_FIELDCAT_ALV,I_HEADING TYPE SLIS_T_LISTHEADER,I_EVENTS TYPE SLIS_T_EVENT.

    TYPES: KKBLO_SELFIELD TYPE SLIS_SELFIELD.

    Step 2 (Optional)

    1 of 35

  • 8/7/2019 ALV_StepByStep_12Aug20083211281700880

    2/35

    ALV DOCUMENTATION AND EXAMPLES22 Rajagopalan. M

    SELECTING THE VARIANTS FOR INITIAL LIST DISPLAY (DEFAULTVARIANT)

    The variants in the list display can be both user-specific and general. The user can programmatically setthe initial (default) variant for list display.The default variant can be found using the function module'REUSE_ALV_VARIANT_DEFAULT_GET'.

    Sample code:

    CALL FUNCTION 'REUSE_ALV_VARIANT_DEFAULT_GET'EXPORTING

    i_save = variant save condition ( A=all, U = user-specific )CHANGING

    cs_variant = internal table containing the program name (and the default variant---optional )EXCEPTIONS

    not_found = 2.

    The user can also choose from the list of existing variants using the function moduleREUSE_ALV_VARIANT_F4.

    Step 3

    DEFININING OUTPUT CHARACTERISTICS: PREPARING DISPLAY FIELDSCATALOG

    A field catalog is prepared using the internal table (I_FIELDCAT) of typeSLIS_T_FIELDCAT_ALV. Field catalog containing descriptions of the list output fields(usually a subset of the internal output table fields).

    A field catalog is required for every ALV list output to add desired functionality (i.e. Key,Hotspot, Specific headings, Justify, Col. position etc) to certain fields of the output. If notmentioned specifically, then the defaults are taken. The possible values and defaults are listed

    below.The field catalog for the output table is built-up in the caller's coding. The build-up can becompletely or partially automated by calling the REUSE_ALV_FIELDCATALOG_MERGEmodule.The minimal field catalog is documented below. This can be done in a routine using a localvariable. The user can use the other optional parameters to assign output attributes to differentfields in the output, which differ from the default.

    A field catalog need not be built-up and passed explicitly only under the followingconditions:

    1. The internal table to be output has the same structure as a Data Dictionarystructure which is referred to in the internal table declaration using LIKE or INCLUDE STRUCTURE. In this case the attributes of the different fields is takendirectly from the table and the attributes (key fields, length, texts etc) need to stateexplicitly.

    2. all fields in this structure are to be output

    3. The structure name is passed to ALV in the parameter I_STRUCTURE_NAME of the function module REUSE_ALV_LIST_DISPLAY.

    2 of 35

  • 8/7/2019 ALV_StepByStep_12Aug20083211281700880

    3/35

    ALV DOCUMENTATION AND EXAMPLES33 Rajagopalan. M

    All the values entered in the catalog is specific to the particular field whose name is entered inthe fieldname FIELDNAME of the fieldcat structure. The name of the table is also entered inthe corr. Fieldname TABNAME of the structure.The different possible attributes are:

    Row_pos (row position): Only relevant if the list output is to be multi-line (two or three lines) by default. So, this attribute can be used maintain certain level of alignment in the output.Value set: 0, 1 3

    Col_pos (column position): This parameter is relevant when the fields in theoutput are to be different from the sequence of the fields in the internal table usedfor display. The parameter specifies the relative column position of the fieldin the list output. The column order can be changed interactively by the user. If this parameter is initial for all field catalog entries, columns appear in the internaltable field sequence.Value set: 0, 1 60

    Fieldname (field name): This is the name of the internal table field for which the parameters are passed in the catalog.Value set: internal output table field name (required parameter)

    Tabname (internal output table): Name of the internal output table that contains

    the field FIELDCAT-FIELDNAME above.Value set: SPACE, internal output table name.

    Ref_fieldname (reference field name): Name of the Data Dictionary field referredto. This parameter is only used when the internal output table field described bythe current field catalog entry has a reference to the Data Dictionary (not a

    program field), and the field name in the internal output table is different from thename of the field in the Data Dictionary. If the field names are identical,naming the Data Dictionary structure or table in the FIELDCAT-REF_TABNAME parameter is sufficient.Value set: SPACE, Data Dictionary field name.

    Ref_tabname (reference table/structure field name): Structure or table name of the referred Data Dictionary field. This parameter is only used when theinternal output table field described by the current field catalog entry has a DataDictionary reference (not a program field).Value set: SPACE, name of a Data Dictionary structure or table

    Link to currency unit Cfieldname (currency unit field name): This is used for currency fields that have

    a reference to any unit field. This is only relevant for amount columns withassociated unit. This parameter contains the Name of the internal output tablefield containing the currency unit associated with the amount field FIELDCAT-FIELDNAME. The field in FIELDCAT-CFIELDNAME must have its own fieldcatalog entry.Value set: SPACE, output table field name

    Ctabname (internal currency unit field output table): Name of the internal outputtable containing the FIELDCAT-CFIELDNAME field.

    Value set: SPACE, output table field name.

    3 of 35

  • 8/7/2019 ALV_StepByStep_12Aug20083211281700880

    4/35

    ALV DOCUMENTATION AND EXAMPLES44 Rajagopalan. M

    Link to measurement unit Qfieldname (measurement unit field name): Only relevant for quantity columns

    with unit link. Name of the internal output table field containing the measurementunit associated with the quantity field FIELDCAT-FIELDNAME. The field inFIELDCAT-QFIELDNAME must have its own field catalog entry.

    Value set: SPACE, output table field name. Qtabname (internal measurement unit field output table): Name of the internal

    output table containing the FIELDCAT-QFIELDNAME field.Value set: SPACE, output table field name.

    Outputlen (column width): This parameter is used if the desired output length for a field is desired to be different from the internal output table field. For fieldswith a Data Dictionary link this parameter can be left initial. For fields without aData Dictionary link (program field) the parameter must be given the value of thedesired field list output length (column width).Initial = column width is the output length of the referred Data Dictionary field

    (domain). N = column width is n characters.Value set: 0 (initial), n.

    Key (key column): By default, the system makes some fields in the output as keyfields, provided the fields are key fields in their referencing table. Using this

    parameter, fields other than key fields of the referencing table can be made keyfield. This parameter is most important if the output needs to contain some fieldwhich are not scrollable or cannot be hidden.If the internal output table contains fields that are key fields from different tables,then all those fields in the report output becomes unscrollable and cannot behidden. So, the fields in the output internal table should not be referenced fromtables in which they are key fields. Instead, they should be referenced to thetables in which they are not key fields, incase they are not desired as key field inthe output.'X' = key field (key field output in color) and Key fields can not be interactivelyhidden. Parameter FIELDCAT-NO_OUT must be left initial.Value set: SPACE, 'X'.

    Key_sel (hideable key column): This parameter is only relevant for the fieldswhich are made key fields using FIELDCAT-KEY = 'X'. Using this parameter theKey field can be hidden interactively.The key column sequence cannot be changed interactively by the user. The

    output is controlled by the FIELDCAT-NO_OUT parameter analogously to non-key fields.Value set: SPACE, 'X'.

    No_out (field in field list): This parameter is used to remove certain fields fromthe output during initial display. The user can however interactively choose thefield for output from the field list in the display variant.'X' = field is not displayed in the current list.Value set: SPACE, 'X'.

    Tech (technical field): This parameter is used to make certain field display onlyin the field catalog. The fields with this parameter set cannot be output in the list

    nor can they be displayed interactively from the catalog.'X' = technical field.

    4 of 35

  • 8/7/2019 ALV_StepByStep_12Aug20083211281700880

    5/35

  • 8/7/2019 ALV_StepByStep_12Aug20083211281700880

    6/35

    ALV DOCUMENTATION AND EXAMPLES66 Rajagopalan. M

    Lzero (leading zeros): By default ALV outputs NUMC fields right-justifiedwithout leading zeros. Using this parameter only the NUMC fields can bedisplayed with leading zeroes.Value set: SPACE, 'X'.'X' = output with leading zeros.

    No_sign (no +/- sign): This parameter is used to suppress the signs of the outputfields. It is only relevant for the value fields.Value set: SPACE, 'X'.'X' = value output without +/ sign.

    No_zero (suppress zeros): Only relevant for value fields.Value set: SPACE, 'X'.'X' = suppress zeros.

    Edit_mask (field formatting): To apply the report output formatting options sameas in the WRITE statement in report writing.

    Value set: SPACE, template. The following parameters are used for customizing the texts in the heading of the output of the columns. The texts are taken from the Data Dictionary for fields with a Data Dictionaryreference. If this is not desired, the text parameters can also be specified. The Data Dictionarytexts are then ignored.If the user changes the column width interactively, the column header text with theappropriate length is always used.The interactive function 'Optimize column width' takes account of both the fieldcontents and the column headers: if all field contents are shorter than the shortestcolumn header, the column width depends on the column header.

    The 'long field label' is also used in display variant definition,Sort, etc. Popup.

    seltext_l (long field label)

    seltext_m (medium field label)

    seltext_s (short field label)

    reptext_ddic(header) Analogous to the Data element main header

    Ddictxt (specify text) : You can specify with values 'L', 'M', and 'S', the keywordthat should always be used as column header. If the column width changes, noattempt is made in this case to find an appropriate header for the new outputwidth.Value set: SPACE, 'L', 'M', and S.

    Sample code:Suppose I_PO_DETAILS is an internal table containing two fields EBELN (PO number) andEBELP (PO item no).DATA: L_FIELDCAT TYPE SLIS_FIELDCAT_ALV. Local variable to hold the

    parametersfor a particular field of the field

    catalog

    6 of 35

  • 8/7/2019 ALV_StepByStep_12Aug20083211281700880

    7/35

  • 8/7/2019 ALV_StepByStep_12Aug20083211281700880

    8/35

    ALV DOCUMENTATION AND EXAMPLES88 Rajagopalan. M

    Only relevant for hierarchical-sequential lists using the layout parameter IS_LAYOUT-EXPAND_FIELDNAME of the structure IS_LAYOUT. Exit for

    passing item entries (ITEM table) for a header record that was expandedinteractively by the user.

    2. Slis_ev_reprep_sel_modify TYPE slis_formname VALUE'REPREP_SEL_MODIFY'.

    RS_SELFIELD-TABINDEX contains the header table index for which the itementries are to be put in the global item output table (T_OUTTAB_SLAVE). TheCallback is only called if ALV has no items for a header that is to be expanded.RFLG_ALL is passed with 'X' if the user shows all items. The application mustensure that entries are not repeated in the item table.RS_SELFIELD is initial in this case.

    3. Slis_ev_caller_exit_at_start TYPE slis_formname VALUE 'CALLER_EXIT'.Is called at the beginning of the function module to make special settings. It is notusually used.

    4. Slis_ev_user_command TYPE slis_formname VALUE 'USER_COMMAND'.As this is a frequently-used Callback event, the form routine can also be passed

    directly in the interface by passing the user command in the IMPORTING parameter I_CALLBACK_USER_COMMAND.5. Slis_ev_top_of_page TYPE slis_formname VALUE 'TOP_OF_PAGE'.

    Equivalent to the list processing TOP-OF-PAGE event. 6. Slis_ev_top_of_coverpage TYPE slis_formname VALUE 'TOP_OF_COVERPAGE'.

    The selection information and list status are output together (if they exist) ona separate page by default

    7. Slis_ev_end_of_coverpage TYPE slis_formname VALUE'END_OF_COVERPAGE'.

    Analogously to TOP_OF_COVERPAGE the user can add other informationto the information output by ALV (selection information, list status) at thisevent.

    8. Slis_ev_foreign_top_of_page TYPE slis_formname VALUEFOREIGN_TOP_OF_PAGE'.

    The Top-of-page event is always processed in ALV and is only passed to thecaller via the Callback mechanism. This is still the case if the caller, e.g. by auser action, processes a branch list which was not formatted by ALV (e.g. a

    popup with additional information about the list record selected anddisplayed by ALV).In this case, top-of-page cannot be formatted by ALV analogously to the

    basic list, it must be handled completely by the caller. The event top-of-pagestill occurs in ALV. When ALV notices a top-of-page which was not caused

    by an ALV output, the form routine in FOREIGN_TOP_OF_PAGE is called.

    9. Slis_ev_foreign_end_of_page TYPE slis_formname VALUE'FOREIGN_END_OF_PAGE'.

    The event end-of-page is always processed in ALV and only passed to thecaller via callback. This is still the case, e.g. when the caller processes adetails list which was not formatted by ALV (e.g. a popup with further information about selected list records which were displayed by ALV).In this case, end-of-page cannot be formatted by ALV analogously to the

    basic list, it must be handled completely by the caller. The event end-of-pagestill occurs in ALV. When ALV notices an end-of-page that was not caused

    by an ALV output, the form routine in FOREIGN_END_OF_PAGE is called.10. Slis_ev_pf_status_set TYPE slis_formname VALUE 'PF_STATUS_SET'.

    If a user list status is to be set, it must be done in the form routine assigned tothis event. The ALV function codes, which must not be active, are in the

    8 of 35

  • 8/7/2019 ALV_StepByStep_12Aug20083211281700880

    9/35

    ALV DOCUMENTATION AND EXAMPLES99 Rajagopalan. M

    Parameter RT_EXTAB. This table must be passed with the SET PF-STATUScommand (with inactive user function codes as well, if necessary).The STANDARD status of the function group SALV should be used as atemplate for a user-specific status. As this is a frequently used Callback event, its form routine can also be passed directly in the interface in theIMPORTING parameter I_CALLBACK_PF_STATUS_SET.

    11. Slis_ev_list_modify TYPE slis_formname VALUE 'LIST_MODIFY'.LIST_MODIFY USING R_TABNAME TYPE SLIS_TABNAME

    R_INDEX LIKE SY-TABIXR_INDEX_ITEM LIKE SY-TABIXR_INDEX_SUM LIKE SY-TABIX.

    12. Slis_ev_top_of_list TYPE slis_formname VALUE 'TOP_OF_LIST'.Information output at the start of the list

    13. Slis_ev_end_of_page TYPE slis_formname VALUE 'END_OF_PAGE'.Information output at the end of a page. This is only called for printing.

    14. Slis_ev_end_of_list TYPE slis_formname VALUE 'END_OF_LIST'.Information output at the end of the list

    15. Slis_ev_after_line_output TYPE slis_formname VALUE'AFTER_LINE_OUTPUT'.Output information after each output line. Should only be used in justifiedcases because it costs a lot of performance.

    16. Slis_ev_before_line_output TYPE slis_formname VALUE'BEFORE_LINE_OUTPUT'.

    Output information before each output line. Should only be used in justifiedcases because it costs a lot of performance.

    17. Slis_ev_subtotal_text TYPE slis_formname VALUE 'SUBTOTAL_TEXT'.

    This event table (I_EVENTS) is now checked with the desired constants. If the desiredconstant is found, then the corresponding field for the FORM NAME is populated with the

    name of the routine containing the corresponding event.

    Sample code :

    FORMNAME_TOP_OF_PAGE TYPE SLIS_FORMNAME VALUE 'TOP_OF_PAGE',FORMNAME_END_OF_PAGE TYPE SLIS_FORMNAME VALUE 'END_OF_PAGE',FORMNAME_USER_COMMAND TYPE SLIS_FORMNAME VALUE'USER_COMMAND'.

    DATA: L_I_EVENT TYPE SLIS_ALV_EVENT.

    CALL FUNCTION 'REUSE_ALV_EVENTS_GET'EXPORTING

    I_LIST_TYPE = 0IMPORTING

    ET_EVENTS = I_EVENTS.

    READ TABLE I_EVENTS WITH KEY NAME = SLIS_EV_TOP_OF_PAGEINTO L_I_EVENT.

    IF SY-SUBRC = 0.MOVE FORMNAME_TOP_OF_PAGE TO L_I_EVENT-FORM.APPEND L_I_EVENT TO I_EVENTS.

    ENDIF.

    READ TABLE I_EVENTS WITH KEY NAME = SLIS_EV_END_OF_PAGEINTO L_I_EVENT.

    9 of 35

  • 8/7/2019 ALV_StepByStep_12Aug20083211281700880

    10/35

    ALV DOCUMENTATION AND EXAMPLES1010Rajagopalan. M

    IF SY-SUBRC = 0.MOVE FORMNAME_END_OF_PAGE TO L_I_EVENT-FORM.APPEND L_I_EVENT TO I_EVENTS.

    ENDIF.CLEAR L_I_EVENT.READ TABLE I_EVENTS WITH KEY NAME = SLIS_EV_USER_COMMAND

    INTO L_I_EVENT.IF SY-SUBRC = 0.

    MOVE FORMNAME_USER_COMMAND TO L_I_EVENT-FORM.APPEND L_I_EVENT TO I_EVENTS.

    ENDIF.

    This will prepare the events table for the report.The report will contain three forms for the above events:1. FORM TOP_OF_PAGE : This form will contain the top of page event for the report i.e

    header etcUsing the function module REUSE_ALV_COMMENTARY_WRITE, the internal table

    containing the headings for top of page event can be passed to the list output. Also, anylogo specific to the report can be passed to the function module.2. FORM END_OF_PAGE : This form will contain the end of page event for the report i.e

    footer etc3. FORM USER_COMMAND : This form will contain the desired user command i.e

    pick/line selection

    Step 5

    A layout is build for the report output list description USING the internal table declared above(I_LAYOUT).

    Output list description structure.The parameters are described under the following heads:

    Display options Exceptions Totals Interaction Detail screen Display variants (only for hierarchical-sequential lists) Color Other

    The layout table is of type slis_layout_alv_spec and has the following fields:

    Display options1. Colwidth_optimize (1) TYPE c: This parameter optimizes the length of thedifferent columns in the output. The width of the different col. now depends on themax. Length of the data in the column.Value set: SPACE, 'X''X' = optimizes the column width so that all contents are displayed completely.

    2. No_colhead(1) TYPE c : This parameter suppresses the column headingsValue set: SPACE, 'X'.'X' = column headers are not output

    3. No_hotspot(1) TYPE c : The heading of the report output are not output ashotspot.

    10 of 35

  • 8/7/2019 ALV_StepByStep_12Aug20083211281700880

    11/35

    ALV DOCUMENTATION AND EXAMPLES1111Rajagopalan. M

    Value set: SPACE, 'X'.'X' = column headers are not output as hotspot

    4. Zebra(1) TYPE c : The report is output in the striped pattern.Value set: SPACE, 'X'.'X' = striped pattern (e.g. for wide lists)

    5. No_vline(1) TYPE c : The report output contains columns only separated by spaceand no lines. It is not relevant for: hierarchical-sequential lists and multiple-line lists.Value set: SPACE, 'X'.'X' = columns separated by SPACE

    6. No_min_linesize(1) TYPE c : The report line size is equal to the width of the list.It is not relevant for block lists.Value set: SPACE, 'X.'X' = line size depends on list width' ' = Line size is set to 80 or MIN_LINESIZE (if > 0) .

    7. Min_linesize LIKE sy-linsz: The report output contains a minimum possible lengthof line. If initial min_linesize is set to 80 by default, then this parameter is used tocustomize it. The prerequisite for this is that the parameter no_min_linesize should be' '.Value set: 0, 10 - 250If the list is wider, the format uses the list width (maximum 250 or MAX_LINESIZE(if > 0)).

    8. Max_linesize LIKE sy-linsz: The default max. Linesize is 250. To change thisdefault value, this parameter can interactively-define the maximum list width setting.Value set: 0, 80 - 1020

    9. Window_titlebar LIKE rsmpe-tittext: To set the titlebar on the report output.10. No_uline_hs(1) TYPE c.

    Exceptions

    11. Lights_fieldname TYPE slis_fieldname: Internal output table field containing thecodes of exceptions to be output.

    Output table field code: '1' = red traffic light'2' = yellow traffic light'3' = green traffic light Fieldname for exception

    Value set: SPACE, internal output table field name.

    12. Lights_tabname TYPE slis_tabname: Name of the internal output table thatcontains the field in the parameter LIGHTS_FIELDNAME. If LIGHTS_FIELDNAME is not empty, this field must also be filled for hierarchical-sequential lists. Only relevant for hierarchical-sequential lists.

    . Value set: SPACE, internal output table name.

    13. Lights_rollname LIKE dfies-rollname: The documentation of this data element isdisplayed when you call F1 help for an exception column.Value set: SPACE, data element name.

    14. Lights_condense(1) TYPE c : If a list record is output with 'red traffic light', eachSubtotal that includes this record is also output with 'red traffic light'.Value set: SPACE, 'X''X' = the 'maximum' exception of the items in the subtotal is output at subtotal level.

    11 of 35

  • 8/7/2019 ALV_StepByStep_12Aug20083211281700880

    12/35

    ALV DOCUMENTATION AND EXAMPLES1212Rajagopalan. M

    Sums15. No_sumchoice(1) TYPE c : This parameter allows the choice for summing upOnly by fieldcatalog.Value set: SPACE, 'X''X' = fields which are to be summed, passed by the calling program (FIELDCAT-

    DO_SUM = 'X'). The user should not be able to change this value interactively.

    16. No_totalline(1) TYPE c : Removes the option of having totals after sub-totals.Value set: SPACE, 'X''X' = no total record is to be output. Subtotals can still be calculated and output. Thefields in the subtotals are flagged DO_SUM = 'X' in the field list.

    17. No_subchoice(1) TYPE c : Does not allow the user to interactively change thefield chosen for subtotals.Value set: SPACE, 'X''X' = value whose change triggers subtotals, provided by the calling program. The

    user should not be able to change this value interactively. 18. No_subtotals(1) TYPE c : No subtotals possibleValue set: SPACE, 'X''X' = no subtotals.

    19. Numc_sum(1) TYPE c : Totals only possible for NUMC-Fields.

    20. No_unit_splitting TYPE c: No separate total lines by inh.units

    21.totals_before_items TYPE c: Display totals before the items

    22. Totals_only(1) TYPE c : Show only totalsValue set: SPACE, 'X''X' = only total records are output.

    23. Totals_text(60) TYPE c : Text for 1st col. in totalsValue set: SPACE, string (max.60)' ' = The first column in the total record contains an appropriate number of '*'s toindicate the total by default. If the first column is wide enough, the string 'Total' isoutput after the asterisks.'String = The string passed is output after the total indicated by '*', if the column iswide enough.

    24. Subtotals_text(60) TYPE c : Texts for subtotalsValue set: SPACE, string (max.60)' ' = In the first column of subtotal records, the subtotal is indicated by an appropriatenumber of '*' by default. If the first column is not a subtotal criterion, the string 'Total'is output after the asterisks, if the column is wide enough.'String = the string passed is output after the subtotal indicated by '*', if the column iswide enough and the first column is not a subtotal criterion. If it is a subtotalcriterion, its value is repeated after the total, if the column is wide enough.

    Interaction25. Box_fieldname TYPE slis_fieldname: Fieldname for checkbox in the reportoutput. If the list has checkboxes at the start of records (for selecting several records),this parameter contains the internal output table field name indicated by the checkbox

    12 of 35

  • 8/7/2019 ALV_StepByStep_12Aug20083211281700880

    13/35

    ALV DOCUMENTATION AND EXAMPLES1313Rajagopalan. M

    selection column. The field is a checkbox at the start of list records without a listheader.Value set: SPACE, internal output table field name 26. Box_tabname TYPE slis_tabname: Name of the internal output table that containsthe field in the parameter BOX_FIELDNAME. If BOX_FIELDNAME is not empty,this field must also be filled for hierarchical-sequential lists.Value set: SPACE, internal output table name.

    27. Box_rollname LIKE dd03p-rollname: rollname for checkbox

    28. Expand_fieldname TYPE slis_fieldname: fieldname flag expand. The user canshow or hide the items by clicking on the folder symbol (hotspot). If the items for aheader entry are only to be read by the calling program and passed to ALV when aheader has been expanded interactively, this can be controlled via the CALLBACK event 'ITEM_DATA_EXPAND'.

    29. Hotspot_fieldname TYPE slis_fieldname: Used to make the fieldname flaghotspot.

    30. No_input(1) TYPE c : The fields are only display fields.Value set: SPACE, 'X''X' = all ready-for-input fields in a list are displayed as not ready-for-input. (Record

    selection checkboxes and fields which can be made ready-for-input via the field list parameter FIELDCAT-INPUT = 'X')

    31. F2code LIKE sy-ucomm: To assign an ALV standard function code to double-click (F2), assign the function code to this parameter. Ex.: to assign the ALV standardfunction 'Detail' ('&ETA') to F2.

    => LAYOUT-F2CODE = '&ETA'.Value set: SPACE, function code 32. Confirmation_prompt: confirm. Prompt when leavingValue set: SPACE, 'X''X' = if one of the functions Back (F03)', Exit (F15)' or Cancel (F12)' occurs, a

    confirmation prompt appears.

    33. Key_hotspot(1) TYPE c : The key fields are displayed as hotspot. The columnsdefined in the field catalog as key fields (FIELDCAT-KEY = 'X') are output ashotspots, i.e. clicking on a key column (highlighted in color in the list) calls thefunction under F2.Value set: SPACE, 'X'.

    34. Reprep(1) TYPE c : report report interface active.

    35. Group_buttons(1) TYPE c : group-buttons for COL1 - COL5 . Group outputfields via FIELDCAT-SP_GROUP in the field list, and pass the group name to thelist module in the interface parameter IT_SPECIAL_GROUPS.Value set: SPACE, 'X'.

    36. No_keyfix(1) TYPE c : Used to make the key fields scrollable.Value set: SPACE, 'X'.' ' = The key columns defined in the field catalog by FIELDCAT-KEY = 'X' are fixedin the list output. These columns do not scroll horizontally. The item table key

    13 of 35

  • 8/7/2019 ALV_StepByStep_12Aug20083211281700880

    14/35

    ALV DOCUMENTATION AND EXAMPLES1414Rajagopalan. M

    columns are fixed in hierarchical-sequential lists. The header table key fields are notconsidered here.'X' = key columns not fixed

    37. Get_selinfos(1) TYPE c : To read selection screen.Value set: SPACE, 'X'.If the calling program is a report with an ABAP/4 selection screen, setting this

    parameter makes ALV read the selection screen again. If the selections are readsuccessfully, a pushbutton, via which the user can call a popup which lists the reportselections in a simple form, becomes active on the results list output by ALV.

    38. group_change_edit(1) TYPE c : Settings by user for new groupValue set: SPACE, 'X''X' = the user can enter a format option for each sort criterion in the sort/subtotal

    popup, for the list format when this value changes (e.g. new page or underline).

    39. No_scrolling(1) TYPE c : Does not allow scrolling of the list to the right.

    Value set: SPACE, 'X'.

    40. Expand_all(1) TYPE c : Expand all positions

    Detailed screen40. Detail_popup(1) TYPE c : show detail in popup.Value set: SPACE, 'X'' ' = List record detail display in full-screen mode, with top-of-page.'X' = list record detail display in popup (without top-of-page).

    41. Detail_initial_lines(1) TYPE c : show also initial linesValue set: SPACE, 'X'

    ' ' = Only fields whose contents are not initial are output in the detail view.'X' = initial field contents are also output in detail.

    41. detail_titlebar(30) type c : Titlebar for detail screenValue set: SPACE, string (max.30)` ' = ' Detail: Display' is output as the title of the detail window.'String = the string passed is output as the title of the detail window.

    Display variants42. Header_text (20) TYPE c: Text for header button. Only relevant for hierarchical-sequential lists. You can toggle between display field and field list views via

    pushbuttons in the display variant definition popup for hierarchical-sequential lists.The views refer to the hierarchy level of the fields. This is technically a toggle

    between the header table and item table fields.Value set: SPACE, CHAR (20)' ' = The header table field pushbutton text is 'Header' by default.CHAR (20) = header table field pushbutton text.

    43.item_text(20) TYPE c : Text for item button. Only relevant for hierarchical-sequential lists. You can toggle the view between the display fields and the field listvia pushbuttons in the display variant definition popup for hierarchical-sequentiallists. The views refer to the hierarchy level of the fields. This is technically a toggle

    between the header table and item table fields.Value set: SPACE, CHAR (20)' ' = The pushbutton text for the item table fields is 'Item' by default.CHAR (20) = item table field pushbutton text.

    14 of 35

  • 8/7/2019 ALV_StepByStep_12Aug20083211281700880

    15/35

    ALV DOCUMENTATION AND EXAMPLES1515Rajagopalan. M

    44.default_ item(1) TYPE c : Items as default. Only relevant for hierarchical-sequential lists.Value set: SPACE, 'X'' ' = The header table fields are displayed by default in the display variant definition

    popup. The user can switch to the item table fields interactively.'X' = the item table fields are displayed by default in the display variant DefinitionPopup. The user can switch to the header table fields interactively.

    Colour 45. Info_fieldname TYPE slis_fieldname: infofield for listoutput. A whole list recordcan be colored individually using a color code in a column of the internal output tablefor the record. Assign the name of the field containing the color code to this

    parameter.Value set: SPACE, internal output table field nameThe internal output table field must be of type CHAR(3).The code must have the following syntax: 'Cxy':

    C = color (all codes must start with 'C')X = color number ('1'-'9')Y = bold ('0' = off, '1' = on)

    46. Coltab_fieldname TYPE slis_fieldname: Cells can be colored individually using acolor code which is contained in a column of the internal output table for the recordcontaining the cell. Assign the name of the field to this parameter.

    Others47. List_append(1) TYPE c : no call screen. It is only useful to output block-listswithout specifying the above modules if the number of list blocks exceeds, or mayexceed, the maximum number specified in the block module documentation. These

    operations are not possible for user-defined block lists.

    Example code :

    I_LAYOUT-f2code = ws_fcode.I_LAYOUT-zebra = 'X'.I_LAYOUT-colwidth_optimize = 'X'.I_LAYOUT-no_keyfix = 'X'.I_LAYOUT-get_selinfos = 'X'.I_LAYOUT-no_hotspot = 'X'.I_LAYOUT-no_input = 'X'.I_LAYOUT-hotspot_fieldname = FIELDNAME.I_LAYOUT-no_input = X.I_LAYOUT-no_vline = `X.I_LAYOUT-no_colhead = .I_LAYOUT-lights_condense = ` `.I_LAYOUT-totals_text = ` `.I_LAYOUT-subtotals_text = ` `.I_LAYOUT-totals_only = ` `.I_LAYOUT-key_hotspot = X.I_LAYOUT-detail_popup = X.I_LAYOUT-group_change_edit = X.I_LAYOUT-GROUP_BUTTONS = X.

    Step 6

    15 of 35

  • 8/7/2019 ALV_StepByStep_12Aug20083211281700880

    16/35

    ALV DOCUMENTATION AND EXAMPLES1616Rajagopalan. M

    This step is required to get the selection screen information in the report output.The prerequisite for this is to set the parameter LAYOUT-GET_SELINFOS of theIMPORTING structure.The parameters to be passed in the IS_SEL_HIDE table are:o mode: 'R' = only the entries passed in the internal table IS_SEL_HIDE-T_ENTRIES

    Are output in the pop up. Selection info, which the list tool read in theselection screen (when called by a report with a selection screen), isreplaced by the values passed.

    'S' = the selection info which the list tool read in the selection screen of thecalling report are modified by the entries in the table IS_SEL_HIDE-T_ENTRIES.

    o t_entries: Selection info table

    o t_entries-mode: 'A' = output the selection info for the current table record in the info popup.

    'D' = do not output select option or SELNAME parameter selection infoin the popup.

    o t_entries-selname: (only used in t_entries-mode = 'D') : Name of the select option or parameter.

    The following table fields are only used in t_entries-mode = 'A'. They contain the selectioninformation to be added.

    t_entries-field: DDIC field name of the field for which selection informationis to be output. t_entries-table: DDIC table names of t_entries-field. t_entries-stext: Field name in info popup. If t_entries-field and t_entries-table have been entered, this text is taken fromDDIC. t_entries-valuf: Selection condition 'from' value (external format) t_entries-valut: Selection condition 'to' value (external format) t_entries-sign0: (I)nclusive (E)xclusive t_entries-option: All values of the select options Option field allowed.

    Step 6

    The Table IT_SORT is populated with the sort criteria for the different fields.The caller specifies the sorting and/or subtotaling of the basic list in the internal tableIT_SORT.

    This internal table has the following fields:o spos : Sort sequenceo fieldname : Internal output table field name

    o tabname : Only relevant for hierarchical-sequential lists. Name of the internal outputtable.

    o up : 'X' = sort in ascending order o down : 'X' = sort in descending order o subtot : 'X' = subtotal at group value change

    o group : '* ' = new page at group value change ,'UL' = underline at group value change

    16 of 35

  • 8/7/2019 ALV_StepByStep_12Aug20083211281700880

    17/35

    ALV DOCUMENTATION AND EXAMPLES1717Rajagopalan. M

    Step 7

    The final step in the output of the report is the use of two ALV functions modules.1. REUSE_ALV_FIELDCATALOG_MERGE2. REUSE_ALV_LIST_DISPLAY

    The first function module is used to pass the field catalog to thereport output and merge it with the internal output table.

    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*" CHANGING*" VALUE(CT_FIELDCAT) TYPE SLIS_T_FIELDCAT_ALV*" EXCEPTIONS*" INCONSISTENT_INTERFACE*" PROGRAM_ERROR *"---------------------------------------------------------------------Import parametersI_PROGRAM_NAME: Program in which the internal output table is declared and populatedI_INTERNAL_TABNAME: Internal output table nameI_STRUCTURE_NAME: Structure name (structure, table, and view)I_CLIENT_NEVER_DISPL: Hide client fields default XI_INCLNAME: Data declarations include name

    CHANGING parameter CT_FIELDCAT: Field catalog with field descriptions

    The variant based on a program-internal table should only be used for rapid prototyping sincethe following restrictions apply:

    1. Performance is affected since the code of the table definition must always be read andinterpreted at runtime.

    2. Dictionary reference are only considered if the keywords LIKE or INCLUDESTRUCTURE (not TYPE) are used.

    Step 8

    The other function module is used to display the internal output table with the contentsFUNCTION reuse_alv_list_display.*"----------------------------------------------------------------------*"*"Lokale Schnittstelle:* IMPORTING

    17 of 35

  • 8/7/2019 ALV_StepByStep_12Aug20083211281700880

    18/35

    ALV DOCUMENTATION AND EXAMPLES1818Rajagopalan. M

    *" VALUE(I_INTERFACE_CHECK) 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 DEFAULT SPACE" 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

    Import parametersI_INTERFACE_CHECK: Interface consistency check log output.I_CALLBACK_PROGRAM: Name of the calling programI_CALLBACK_PF_STATUS_SET: Set EXIT routine to status.I_CALLBACK_USER_COMMAND: EXIT routine for command handlingI_STRUCTURE_NAME: Internal output table structure nameIS_LAYOUT: List layout specificationsIT_FIELDCAT: Field catalog with field descriptionsIT_EXCLUDING: Table of inactive function codesIT_SPECIAL_GROUPS: Grouping fields for column selectionIT_SORT: Sort criteria for first list displayIT_FILTER: Filter criteria for first list outputIS_SEL_HIDE : Selection information modificationI_DEFAULT: Initial variant active/inactive logicI_SAVE: Variants can be savedIS_VARIANT : Variant information

    IT_EVENTS: Table of events to performIT_EVENT_EXIT : Standard fcode exit requests tableIS_PRINT: Print information

    18 of 35

  • 8/7/2019 ALV_StepByStep_12Aug20083211281700880

    19/35

    ALV DOCUMENTATION AND EXAMPLES1919Rajagopalan. M

    IS_REPREP_ID: Initialization keys for Re/Re interfaceI_SCREEN_START_COLUMN: Coordinates for list in dialog boxI_SCREEN_START_LINE: Coordinates for list in dialog boxI_SCREEN_END_COLUMN: Coordinates for list in dialog boxI_SCREEN_END_LINE: Coordinates for list in dialog boxIT_EVENT_EXIT: Standard fcode exit requests tableIS_PRINT: Print informationIS_REPREP_ID: Initialization keys for Re/Re interfaceI_SCREEN_START_COLUMN: Coordinates for list in dialog boxI_SCREEN_START_LINE: Coordinates for list in dialog boxI_SCREEN_END_COLUMN: Coordinates for list in dialog boxI_SCREEN_END_LINE: Coordinates for list in dialog box

    Export parametersE_EXIT_CAUSED_BY_CALLER: Delete list in CALLBACK_USER_COMMANDES_EXIT_CAUSED_BY_USER: How the user left the list TablesT_OUTTAB: Table with data to be displayed ---mandatory

    Example Code

    WS_REPNAME = SY-REPID.

    CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'EXPORTING

    I_PROGRAM_NAME = WS_REPNAMEI_INTERNAL_TABNAME = Internal output table field nameI_INCLNAME = WS_REPNAME

    CHANGINGCT_FIELDCAT = I_FIELDTAB.

    IF SY-SUBRC 0.WRITE: 'SY-SUBRC: ', SY-SUBRC, 'REUSE_ALV_FIELDCATALOG_MERGE'.

    ENDIF.CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'

    EXPORTINGI_CALLBACK_PROGRAM = WS_REPNAMEI_STRUCTURE_NAME = Internal output table field nameIS_LAYOUT = I_LAYOUTIT_FIELDCAT = I_FIELDTABI_DEFAULT = 'A'I_SAVE = 'A'IS_VARIANT = 'X'IT_EVENTS = I_EVENTS[]

    IT_SORT = I_SORTIS_SEL_HIDE = I_SELINFO

    TABLEST_OUTTAB = Internal output table field name.

    IF SY-SUBRC 0.

    WRITE: 'SY-SUBRC: ', SY-SUBRC, 'REUSE_ALV_LIST_DISPLAY'.ENDIF

    THIS IS THE POP UP TO ALLOW THE USER TO DYNAMICALLY SELECT THE FIELDS FOR DISPLAY. HE CAN CHOOSE FROM THIS FIELDS ACC. TO REQUIREMENT AND HIDE THEOTHER FIELDS

    19 of 35

  • 8/7/2019 ALV_StepByStep_12Aug20083211281700880

    20/35

    ALV DOCUMENTATION AND EXAMPLES2020Rajagopalan. M

    Example report output based prior to selection of the field

    20 of 35

    output.html

  • 8/7/2019 ALV_StepByStep_12Aug20083211281700880

    21/35

    ALV DOCUMENTATION AND EXAMPLES2121Rajagopalan. M

    THE USER HAS HIDDEN SOME OF THE FIELD FROM THE TOTAL FIELDS TO CUSTOMIZETHE REPORT OUTPUT

    Example report output after hiding some of the fields

    21 of 35

    output1.html

  • 8/7/2019 ALV_StepByStep_12Aug20083211281700880

    22/35

    ALV DOCUMENTATION AND EXAMPLES2222Rajagopalan. M

    USER CAN CHOOSE A PARTICULAR SET OF FIELD FROM THE OUTPUT AND CAN SAVEIT AS VARIANTS

    22 of 35

  • 8/7/2019 ALV_StepByStep_12Aug20083211281700880

    23/35

  • 8/7/2019 ALV_StepByStep_12Aug20083211281700880

    24/35

    ALV DOCUMENTATION AND EXAMPLES2424Rajagopalan. M

    Sample code

    1 Simple list output :

    REPORT Y_DEMO_ALV NO STANDARD PAGE HEADING.** Data to be displayedDATA: I_SFLIGHT TYPE TABLE OF SFLIGHT.

    *---------------------------------------------------------------------** Selection

    SELECT * FROM SFLIGHT INTO TABLE I_SFLIGHT.

    * Call ABAP List Viewer (ALV)CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'

    EXPORTINGI_STRUCTURE_NAME = 'SFLIGHT'

    TABLEST_OUTTAB = I_SFLIGHT.

    2.Simple grid output:

    REPORT Y_DEMO_ALV_1.*

    * Data to be displayedDATA: I_SFLIGHT TYPE TABLE OF SFLIGHT.*---------------------------------------------------------------------*

    * SelectionSELECT * FROM SFLIGHT INTO TABLE I_SFLIGHT.

    * Call ABAP List Viewer (ALV)CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

    EXPORTINGI_STRUCTURE_NAME = 'SFLIGHT'

    TABLEST_OUTTAB = I_SFLIGHT.

    3. Demo for 'REUSE_ALV_POPUP_TO_SELECT'

    REPORT y_demo_alv_3.

    TYPE-POOLS: slis.

    DATA: BEGIN OF i_outtab OCCURS 0.INCLUDE STRUCTURE sflight.

    DATA: w_chk TYPE c. "For multiple selectionDATA: END OF i_outtab.

    24 of 35

  • 8/7/2019 ALV_StepByStep_12Aug20083211281700880

    25/35

  • 8/7/2019 ALV_StepByStep_12Aug20083211281700880

    26/35

    ALV DOCUMENTATION AND EXAMPLES2626Rajagopalan. M

    * ALV related data declarationTYPE-POOLS: slis.* DB-TableTABLES sflight.* IncludesINCLUDE .INCLUDE .*CONSTANTS:c_formname_top_of_page TYPE slis_formname VALUE 'TOP_OF_PAGE'.

    DATA: i_fieldcat TYPE slis_t_fieldcat_alv,i_layout TYPE slis_layout_alv,i_sp_group TYPE slis_t_sp_group_alv,i_events TYPE slis_t_event,i_print TYPE slis_print_alv,i_sort TYPE slis_t_sortinfo_alv.

    *internal table for data to be displayedDATA: BEGIN OF i_sflight OCCURS 0.

    INCLUDE STRUCTURE sflight.DATA: box,

    lights.DATA: END OF i_sflight.*DATA: w_repid LIKE sy-repid.DATA: i_list_top_of_page TYPE slis_t_listheader.* Report SelectionsSELECT-OPTIONS s_carrid FOR sflight-carrid.

    SELECT-OPTIONS s_connid FOR sflight-connid.SELECT-OPTIONS s_fldate FOR sflight-fldate.*SELECTION-SCREEN SKIP 1.* ParametersPARAMETERS: p_maxrow TYPE i DEFAULT 30."to limit the selectionSELECTION-SCREEN SKIP 1.

    * Variant for ALV displaySELECTION-SCREEN BEGIN OF BLOCK 0 WITH FRAME TITLE text-000.PARAMETERS: p_varnt LIKE disvariant-variant.SELECTION-SCREEN END OF BLOCK 0.* Layout of the report displaySELECTION-SCREEN BEGIN OF BLOCK a WITH FRAME TITLE text-001.PARAMETERS: p_zebra AS CHECKBOX DEFAULT ' ', "Striped pattern

    p_nocolh AS CHECKBOX DEFAULT ' ', "No column headingp_novlin AS CHECKBOX DEFAULT ' ', "No vertical linesp_colopt AS CHECKBOX DEFAULT ' ', "Optimizes col. wdp_keyhot AS CHECKBOX DEFAULT ' ', "Key fields hotp_noinpt AS CHECKBOX DEFAULT ' '. "No field for input

    SELECTION-SCREEN END OF BLOCK a.

    SELECTION-SCREEN BEGIN OF BLOCK b WITH FRAME TITLE text-002.PARAMETERS: p_lights AS CHECKBOX DEFAULT 'X',

    p_lightc AS CHECKBOX DEFAULT 'X'.SELECTION-SCREEN END OF BLOCK b.

    26 of 35

  • 8/7/2019 ALV_StepByStep_12Aug20083211281700880

    27/35

    ALV DOCUMENTATION AND EXAMPLES2727Rajagopalan. M

    SELECTION-SCREEN BEGIN OF BLOCK c WITH FRAME TITLE text-003.PARAMETERS: p_totonl AS CHECKBOX DEFAULT ' ',

    p_totext(60),p_sttext(60).

    SELECTION-SCREEN END OF BLOCK c.

    SELECTION-SCREEN BEGIN OF BLOCK d WITH FRAME TITLE text-004.PARAMETERS: p_chkbox AS CHECKBOX DEFAULT 'X',

    p_detpop AS CHECKBOX DEFAULT 'X',p_groupb AS CHECKBOX DEFAULT ' ',p_groups AS CHECKBOX DEFAULT ' '.

    SELECTION-SCREEN END OF BLOCK d.

    SELECTION-SCREEN BEGIN OF BLOCK e WITH FRAME TITLE text-005.PARAMETERS: p_print AS CHECKBOX DEFAULT ' ',

    p_nosinf AS CHECKBOX DEFAULT ' ',p_nocove AS CHECKBOX DEFAULT ' ',

    p_nonewp AS CHECKBOX DEFAULT ' ',p_nolinf AS CHECKBOX DEFAULT ' ',p_reserv TYPE i.

    SELECTION-SCREEN END OF BLOCK e.

    DATA: w_boxnam TYPE slis_fieldname VALUE 'BOX',w_f2code LIKE sy-ucomm VALUE '&ETA',w_lignam TYPE slis_fieldname VALUE 'LIGHTS',w_save(1) TYPE c,w_default(1) TYPE c,w_exit(1) TYPE c,i_variant LIKE disvariant,

    i_variant1 LIKE disvariant.

    *---------------------------------------------------------------------*INITIALIZATION.

    w_repid = sy-repid.

    PERFORM fieldcat_init USING i_fieldcat.PERFORM eventtab_build USING i_events.PERFORM comment_build USING i_list_top_of_page.PERFORM sp_group_build USING i_sp_group.PERFORM t_sort_build USING i_sort.

    * Set Options: save variant userspecific or general**** 'A or 'U' are for user-specific variants list**** 'X' or 'space' for general

    w_save = 'A'.

    PERFORM variant_init.* Get default variant

    i_variant1 = i_variant.

    CALL FUNCTION 'REUSE_ALV_VARIANT_DEFAULT_GET'EXPORTING

    i_save = w_saveCHANGING

    cs_variant = i_variant1

    27 of 35

  • 8/7/2019 ALV_StepByStep_12Aug20083211281700880

    28/35

    ALV DOCUMENTATION AND EXAMPLES2828Rajagopalan. M

    EXCEPTIONSnot_found = 2.

    IF sy-subrc = 0.p_varnt = i_variant1-variant.

    ENDIF.

    * Process on value request (list of possible variants)AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_varnt.

    PERFORM f4_for_variant.

    * PAIAT SELECTION-SCREEN.

    PERFORM pai_of_selection_screen.

    START-OF-SELECTION.

    PERFORM selection.

    END-OF-SELECTION.

    PERFORM layout_build USING i_layout. "wg. ParametersPERFORM print_build USING i_print. "wg. Parameters

    CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'EXPORTING

    i_program_name = w_repid* i_internal_tabname = 'I_SFLIGHT'

    i_structure_name = 'SFLIGHT'

    i_client_never_display = 'X'i_inclname = w_repid

    CHANGINGct_fieldcat = i_fieldcat[]

    EXCEPTIONSinconsistent_interface = 1program_error = 2OTHERS = 3.

    IF sy-subrc 0.MESSAGE ID sy-msgid TYPE 'S' NUMBER sy-msgno

    WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.ENDIF.

    * Call ABAP/4 List Viewer CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

    EXPORTING* I_INTERFACE_CHECK = ' '

    i_callback_program = w_repid* I_CALLBACK_PF_STATUS_SET = ' '* I_CALLBACK_USER_COMMAND = ' '* I_CALLBACK_TOP_OF_PAGE = ' '* I_CALLBACK_HTML_TOP_OF_PAGE = ' '* I_CALLBACK_HTML_END_OF_LIST = ' '

    i_structure_name = 'SFLIGHT'i_background_id = 'ALV_BACKGROUND'

    28 of 35

  • 8/7/2019 ALV_StepByStep_12Aug20083211281700880

    29/35

    ALV DOCUMENTATION AND EXAMPLES2929Rajagopalan. M

    * I_GRID_TITLE =* I_GRID_SETTINGS =

    is_layout = i_layoutit_fieldcat = i_fieldcat[]

    * IT_EXCLUDING =it_special_groups = i_sp_group[]it_sort = i_sort[]

    * IT_FILTER =* IS_SEL_HIDE =* I_DEFAULT = 'X'

    i_save = w_saveis_variant = i_variantit_events = i_events[]

    * IT_EVENT_EXIT =is_print = i_print

    * IS_REPREP_ID =* I_SCREEN_START_COLUMN = 0

    * I_SCREEN_START_LINE = 0* I_SCREEN_END_COLUMN = 0* I_SCREEN_END_LINE = 0* IMPORTING* E_EXIT_CAUSED_BY_CALLER =* ES_EXIT_CAUSED_BY_USER =

    TABLESt_outtab = i_sflight

    EXCEPTIONSprogram_error = 1OTHERS = 2.

    IF sy-subrc 0.* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

    ENDIF.

    * CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'* EXPORTING* i_callback_program = w_repid* i_structure_name = 'SFLIGHT'* is_layout = i_layout* it_fieldcat = i_fieldcat[]** IT_EXCLUDING =* it_special_groups = i_sp_group[]* it_sort = i_sort[]** IT_FILTER =** IS_SEL_HIDE =** i_default = W_DEFAULT* i_save = w_save* is_variant = i_variant* it_events = i_events[]** IT_EVENT_EXIT =* is_print = i_print** I_SCREEN_START_COLUMN = 0** I_SCREEN_START_LINE = 0** I_SCREEN_END_COLUMN = 0** I_SCREEN_END_LINE = 0

    29 of 35

  • 8/7/2019 ALV_StepByStep_12Aug20083211281700880

    30/35

    ALV DOCUMENTATION AND EXAMPLES3030Rajagopalan. M

    ** IMPORTING** E_EXIT_CAUSED_BY_CALLER =* TABLES* t_outtab = i_sflight.

    *---------------------------------------------------------------------** FORM FIELDCAT_INIT **---------------------------------------------------------------------** --> L_FIELDCAT **---------------------------------------------------------------------*FORM fieldcat_init USING l_fieldcat TYPE slis_t_fieldcat_alv.

    DATA: ls_fieldcat TYPE slis_fieldcat_alv.*

    CLEAR ls_fieldcat.ls_fieldcat-fieldname = 'SEATSOCC'.

    *The field is not displayed in the initial output, can be interactively

    * chosen for displayls_fieldcat-no_out = 'X'.*This field is assigned to a special group with tech. key 'A' and can be*displayed using the special group buttons

    ls_fieldcat-sp_group = 'A'.*The field cannot be summed irrespective of its data type

    ls_fieldcat-no_sum = 'X'.APPEND ls_fieldcat TO l_fieldcat.

    *CLEAR ls_fieldcat.ls_fieldcat-fieldname = 'SEATSMAX'.ls_fieldcat-no_out = 'X'.

    ls_fieldcat-sp_group = 'A'.APPEND ls_fieldcat TO l_fieldcat.

    *CLEAR ls_fieldcat.ls_fieldcat-fieldname = 'PRICE'.ls_fieldcat-no_out = 'X'.ls_fieldcat-sp_group = 'B'.APPEND ls_fieldcat TO l_fieldcat.

    *CLEAR ls_fieldcat.ls_fieldcat-fieldname = 'CARRID'.ls_fieldcat-outputlen = 7.APPEND ls_fieldcat TO l_fieldcat.

    ENDFORM.

    *---------------------------------------------------------------------** FORM DATA_ADD **---------------------------------------------------------------------** --> L_SFLIGHT*---------------------------------------------------------------------*FORM data_add TABLES l_sflight STRUCTURE i_sflight.

    LOOP AT l_sflight.

    IF sy-tabix > 10.

    30 of 35

  • 8/7/2019 ALV_StepByStep_12Aug20083211281700880

    31/35

    ALV DOCUMENTATION AND EXAMPLES3131Rajagopalan. M

    l_sflight-box = 'X'.l_sflight-lights = '3'.

    ELSE.IF sy-tabix = 1.

    l_sflight-lights = '2'.ELSE.

    l_sflight-lights = '1'.ENDIF.

    ENDIF.

    MODIFY l_sflight.

    ENDLOOP.

    ENDFORM.

    *---------------------------------------------------------------------*

    * FORM EVENTTAB_BUILD **---------------------------------------------------------------------** --> l_EVENTS **---------------------------------------------------------------------*FORM eventtab_build USING l_events TYPE slis_t_event.

    DATA: ls_event TYPE slis_alv_event.*

    CALL FUNCTION 'REUSE_ALV_EVENTS_GET'EXPORTING

    i_list_type = 0IMPORTING

    et_events = l_events.

    READ TABLE l_events WITH KEY name = slis_ev_top_of_page INTO ls_event.

    IF sy-subrc = 0.MOVE c_formname_top_of_page TO ls_event-form.APPEND ls_event TO l_events.

    ENDIF.

    ENDFORM.

    *---------------------------------------------------------------------** FORM COMMENT_BUILD **---------------------------------------------------------------------** --> L_TOP_OF_PAGE **---------------------------------------------------------------------*FORM comment_build USING l_top_of_page TYPE slis_t_listheader.

    DATA: ls_line TYPE slis_listheader.

    ***Header CLEAR ls_line.ls_line-typ = 'H'.

    * LS_LINE-KEY: not used for this typels_line-info = 'Heading list'.APPEND ls_line TO l_top_of_page.

    31 of 35

  • 8/7/2019 ALV_StepByStep_12Aug20083211281700880

    32/35

    ALV DOCUMENTATION AND EXAMPLES3232Rajagopalan. M

    ***SelectionCLEAR ls_line.ls_line-typ = 'S'.ls_line-key = 'Key 1'.ls_line-info = 'Information'.APPEND ls_line TO l_top_of_page.ls_line-key = 'Key 2'.APPEND ls_line TO l_top_of_page.

    ***ActionCLEAR ls_line.ls_line-typ = 'A'.

    * LS_LINE-KEY: not used for this typeLs_line-info = 'Status list'.APPEND ls_line TO l_top_of_page.

    ENDFORM.

    *---------------------------------------------------------------------** FORM LAYOUT_BUILD **---------------------------------------------------------------------** LS_LAYOUT **---------------------------------------------------------------------*FORM layout_build USING ls_layout TYPE slis_layout_alv.

    ls_layout-f2code = w_f2code.ls_layout-zebra = p_zebra.ls_layout-colwidth_optimize = p_colopt.

    IF p_chkbox = 'X'.*Fieldname for check box on the report output

    ls_layout-box_fieldname = w_boxnam.ELSE.

    ls_layout-box_fieldname = space.ENDIF.ls_layout-no_input = p_noinpt.ls_layout-no_vline = p_novlin.ls_layout-no_colhead = p_nocolh.IF p_lights = 'X' OR p_lightc = 'X'.

    **Fieldname for lights on the report outputls_layout-lights_fieldname = w_lignam.

    ELSE.CLEAR ls_layout-lights_fieldname.

    ENDIF.

    ls_layout-lights_condense = p_lightc.ls_layout-totals_text = p_totext.ls_layout-subtotals_text = p_sttext.ls_layout-totals_only = p_totonl.ls_layout-key_hotspot = p_keyhot.ls_layout-detail_popup = p_detpop.ls_layout-group_change_edit = p_groups.

    * E05_LS_LAYOUT-GROUP_BUTTONS = P_GROUPB.* ls_layout-group_buttons = 'X'.

    32 of 35

  • 8/7/2019 ALV_StepByStep_12Aug20083211281700880

    33/35

    ALV DOCUMENTATION AND EXAMPLES3333Rajagopalan. M

    ENDFORM.

    *---------------------------------------------------------------------** FORM SP_GROUP_BUILD **---------------------------------------------------------------------** --> L_SP_GROUP **---------------------------------------------------------------------*FORM sp_group_build USING l_sp_group TYPE slis_t_sp_group_alv.

    DATA: ls_sp_group TYPE slis_sp_group_alv.*Fields are assigned to the special group

    CLEAR ls_sp_group.ls_sp_group-sp_group = 'A'.ls_sp_group-text = 'Reservation status'.APPEND ls_sp_group TO l_sp_group.

    CLEAR ls_sp_group.

    ls_sp_group-sp_group = 'B'.ls_sp_group-text = 'Flight charges'.APPEND ls_sp_group TO l_sp_group.

    ENDFORM.

    *---------------------------------------------------------------------** FORM SELECTION **---------------------------------------------------------------------*FORM selection.

    SELECT * FROM sflight INTO CORRESPONDING FIELDS OF TABLE i_sflight

    UP TO p_maxrow ROWS WHERE carrid IN s_carridAND connid IN s_connid AND fldate IN s_fldate.

    PERFORM data_add TABLES i_sflight.ENDFORM.

    *---------------------------------------------------------------------** FORM TOP_OF_PAGE **---------------------------------------------------------------------** ........ **---------------------------------------------------------------------*FORM top_of_page.*

    CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'EXPORTING

    i_logo = 'ENJOYSAP_LOGO'it_list_commentary = i_list_top_of_page.

    ENDFORM.

    *---------------------------------------------------------------------** FORM F4_FOR_VARIANT **---------------------------------------------------------------------*FORM f4_for_variant.*

    CALL FUNCTION 'REUSE_ALV_VARIANT_F4'

    33 of 35

  • 8/7/2019 ALV_StepByStep_12Aug20083211281700880

    34/35

    ALV DOCUMENTATION AND EXAMPLES3434Rajagopalan. M

    EXPORTINGis_variant = i_varianti_save = w_save

    * it_default_fieldcat =IMPORTING

    e_exit = w_exites_variant = i_variant1

    EXCEPTIONSnot_found = 2.

    IF sy-subrc = 2.MESSAGE ID sy-msgid TYPE 'S' NUMBER sy-msgno

    WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.ELSE.

    IF w_exit = space.p_varnt = i_variant1-variant.

    ENDIF.ENDIF.

    ENDFORM.

    *&---------------------------------------------------------------------**& Form PAI_OF_SELECTION_SCREEN*&---------------------------------------------------------------------** to check whether right variant is entered on the selection scr *----------------------------------------------------------------------*FORM pai_of_selection_screen.*

    IF NOT p_varnt IS INITIAL.MOVE i_variant TO i_variant1.MOVE p_varnt TO i_variant1-variant.

    CALL FUNCTION 'REUSE_ALV_VARIANT_EXISTENCE'EXPORTING

    i_save = w_saveCHANGING

    cs_variant = i_variant1.

    i_variant = i_variant1.ELSE.

    PERFORM variant_init.ENDIF.

    ENDFORM. " PAI_OF_SELECTION_SCREEN

    *&---------------------------------------------------------------------**& Form VARIANT_INIT*----------------------------------------------------------------------*FORM variant_init.*

    CLEAR i_variant.i_variant-report = w_repid.

    ENDFORM. " VARIANT_INIT

    *---------------------------------------------------------------------** FORM PRINT_BUILD *

    34 of 35

  • 8/7/2019 ALV_StepByStep_12Aug20083211281700880

    35/35

    ALV DOCUMENTATION AND EXAMPLES3535Rajagopalan. M

    *---------------------------------------------------------------------** ........ **---------------------------------------------------------------------*FORM print_build USING l_print TYPE slis_print_alv.*

    l_print-print = p_print.l_print-no_print_selinfos = p_nosinf.l_print-no_coverpage = p_nocove.l_print-no_new_page = p_nonewp.l_print-no_print_listinfos = p_nolinf.l_print-reserve_lines = p_reserv.l_print-print = p_print.

    ENDFORM.

    *---------------------------------------------------------------------** FORM T_SORT_BUILD *

    *---------------------------------------------------------------------*FORM t_sort_build USING l_sort TYPE slis_t_sortinfo_alv.

    DATA: ls_sort TYPE slis_sortinfo_alv.

    ls_sort-fieldname = 'CARRID'.ls_sort-spos = 1.ls_sort-up = 'X'.ls_sort-subtot = 'X'.APPEND ls_sort TO l_sort.

    ENDFORM.