Alv diaplay

Embed Size (px)

Citation preview

  • 7/27/2019 Alv diaplay

    1/23

    Table of Contents

    1. WHY ALV?

    2. SCOPE OF THIS DOCUMENT

    3. TYPES OF ALV DISPLAY

    4. BUILDING FIELDCATALOG

    5. DISPLAY FM

    6. EVENT HANDLING IN ALV

    7. DISPLAY VARIANTS

    8. F4 HELP FOR DISPLAY VARIANTS

    9. HIERARCHIAL DISPLAY10. DISPLAYING MORE THAN ONE INTERNAL TABLES IN ALV

    11. SAMPLE CODES

    1 SAMPLE CODE FOR NORMAL LIST DISPLAY2 SAMPLE CODE FOR F4 HELP FOR DISPLAY VARIANTS

    3 SAMPLE CODE FOR HIERARCHICAL ALV DISPLAY4 SAMPLE CODE TO DISPLAY MORE THAN ONE INTERNAL TABLE IN ALV

    5 SAMPLE CODE FOR INTERACTIVE REPORTING IN ALV

    WHY ALV?

    ABAP List Viewer is a tool to standardize and simplify data display. With this, auniform user interface can be obtained for all the lists displayed.

    This tool can be used both for simple (consisting of non hierarchical, user defined

    columns) as well as hierarchical (consisting of the header and their subordinaterows) data display. Functions like sorting, filtering, totaling etc can be performed

    easily in both the simple or hierarchical display.

    ABAP list viewer really speeds up the report writing process. It's quite flexible in thatit allows the user to capture and process user commands easily. Unlike a standard

    ABAP list, ALV provides the end-user the flexibility to individually customize the dataoutput.

    SCOPE OF THIS DOCUMENT

    This document gives a clear view of how to use standard function modules to

    generate ALV displays. This document can also be used by the beginners who aretrying their first hand at ALV.

    TYPES OF ALV DISPLAY

  • 7/27/2019 Alv diaplay

    2/23

    1) ALV List Display2) ALV Grid Display

    ALV display (both LIST and GRID) can be easily implemented by using Standard

    Function modules. GRID display can also be implemented using classes (OOPConcept).

    Also Hierarchical display is possible only in LIST display.

    Both the above type provide almost with the same functionalities. But most of the

    time GRID display is preferred over the LIST display for the following reason. Apart

    from the basic LIST functionalities, the GRID provides with extra functions, which canbe enhanced by the users. Also HTML pages can be used as top of page for the

    GRID display.

    BUILDING FIELD CATALOG

    Field catalog is a table containing the properties and attributes columns/fields of theoutput internal table. This can be generated in three ways

    1) Automatic:

    In this method of generation of the field catalog, we use the function module

    REUSE_ALV_FIELDCATALOG_MERGE.

    This FM creates the field catalog from the dictionary structure of the internal table,which is to be displayed. The output internal table should be declared either in the

    TOP include or the include should be specified in the interface.

    Note: Dictionary references are only considered if the keywords LIKE or INCLUDESTRUCTURE (not TYPE) are used.

    This Function module returns a table having a row entry for all the columns in theinternal table to be displayed. This table has the attributes like column position, sort

    condition, Heading text etc of each column in the output. If the field catalogcontains more than 90 columns, then only the first 90 columns are displayed in the

    output. Other columns are available only in the field selection.

    Some of the important parameters of the above FM are:

    1) I_PROGRAM_NAME (Export Parameter)

    This is the name of the program from which the function module is called orthe program having the exit routines.

    2) I_INTERNAL_TABNAME (Export Parameter)

    This is the name of the internal table to be displayed.

    3) I_STRUCTURE_NAME (Export Parameter)If the internal table to be displayed is defined using a Dictionary structure

    (INCLUDE STRUCTURE xyz or LIKE xyz), then the field catalog can be built bypassing the structure name. The key fields of the structure will form the key

    fields of the list also.

    4) I_CLIENT_NEVER_DISPLAY (Export Parameter)

  • 7/27/2019 Alv diaplay

    3/23

    This parameter is used to handle the client field in the structure passed. Ifthis parameter is left blank, then client fields (type CLNT) in the structure

    passed are flagged as technical (=> no screen output) in the field catalog.

    5) I_INCLNAME (Export Parameter)If the output internal table is not declared in the TOP include, then the include

    in which this table is declared is to be passed here (If the structure is notpassed). If the output table is declared in the same program, pass theprogram name here.

    6) I_BYPASSING_BUFFER, I_BUFFER_ACTIVE (Export Parameters)When the program is run for the first time, the fields present in the output

    table and their positions are stored in a buffer. So the buffer is taken asreference for the successive executions. In order to bypass this buffer the

    above parameter values should be X and (space) respectively. If thesevalues are not passed to the function module, the changes made in the

    structure of the internal table MAY NOT be reflected in the output.

    7) CT_FIELDCAT (Import Parameter)

    Field catalog (table) containing the descriptions and properties of the outputfields.It has the following attributes for each of the column

    1) Positioning attributes like row position, column position etc2) Identification attributes like fieldname, reference fieldname etc

    3) Attributes pertaining to linking the fields with currency unit4) Attributes pertaining to linking the fields with measurement units

    5) Column output options like column width, whether it is a key field etc6) Formatting options

    7) Texts (headings)

    2) Manual

    The field catalog can also be built manually without using the above function

    module. This is done by building the internal table (like the one returned by theFM. Refer point 7 in the parameters of the FM) manually with all the details.

    3) Semi Automatic

    In this method, we first use the function module to get the basic properties of thefields. Then we modify the entries in this table according our requirements.

    DISPLAY REUSE_ALV_LIST_DISPLAY, REUSE_ALV_GRID_DISPLAY

    The above function modules are used to display the output list in either LIST displayor GRID display respectively. The interface for both these function module is same.

    We have to pass an internal table with the output data and a field catalog having theattributes of each field in the output table.

    Some of the important parameters of the above function modules are:

    1) I_INTERFACE_CHECK (Export Parameter)

  • 7/27/2019 Alv diaplay

    4/23

    If this parameter is 'X', the consistency of the interface is checked when thefunction module is called, and an error log is output. This parameter should

    only be set for development test purposes.

    2) I_BYPASSING_BUFFER, I_BUFFER_ACTIVE (Export Parameter)Refer the parameters of the FM REUSE_ALV_FIELDCATALOG_MERGE

    3) I_CALLBACK_PROGRAM (Export Parameter)The program, which calls the function module and has the exit routines.

    4) I_CALLBACK_PF_STATUS_SET (Export Parameter)Passing the parameter here tells the ALV that you want to set your own user

    status for the display. So in this case the ALV does not set the defaultstatus, but calls the form routine passed with I_CALLBACK_PF_STATUS_SET

    The interface of this form routine should be defined as follows

    FORM set_pf_status USING rt_extab TYPE slis_t_extab

    The table RT_EXTAB contains those function codes that are hidden on the

    standard interface of the ALV.

    If the user wants to implement functionalities other than that provided by

    standard ALV, he or she should copy the standard PF_STATUS from thefunction group SALV and make the necessary changes.

    If no exit routine is passed, then the ALV sets the standard status of the

    function group SALV as the default status.

    5) I_CALLBACK_USER_COMMAND (Export Parameter)Passing this parameter tells the ALV that the application should react to

    certain user defined function codes.

    The interface of the specified form routine must be defined as follows:

    FORM user_command USING r_ucomm LIKE sy-ucommrs_selfield TYPE slis_selfield.

    The parameter R_UCOMM contains the function code called.

    The structure RS_SELFIELD contains the information like:

    tabname : internal output table name on which curson is placed

    tabindex : internal output table index

    fieldname: field name of cursor position

    sel_tab_field: cell name of cursor position (internal ALV table namefield

    endsum : cursor is on the final total row sumindex : if >0, the cursor is on a subtotal row

    value : field value on the list

    refresh : (exporting) list is to be refreshed

    6) I_STRUCTURE_NAME (Export Parameter)

    If the output table is defined using dictionary structure, then pass the samehere

  • 7/27/2019 Alv diaplay

    5/23

    7) IS_LAYOUT (Export Parameter)This parameter (Output list description structure)is passed to modify the

    appearance of columns in the output.The various options can be described under the following headers:

    Display options

    Exceptions

    Totals Interaction

    Detail screen

    Display variants (only for hierarchical-sequential lists)

    Color

    8) IT_FIELDCAT (Export Parameter)

    Pass the field catalog here

    9) IT_EXCLUDING (Export Parameter)This is used if the user wants to deactivate certain functionalities of the

    standard interface. The user has to pass the function codes of the standardfunctions to be deactivated, in this internal table

    10)IT_SORT (Export Parameter)

    The user has to specify the sorting and/or subtotaling of the basic list in this

    internal table

    11)IT_FILTER (Export Parameter)This is the filter criteria table. Filter criteria which result, e.g. from explicitly

    loading an initial display variant, can be passed to list output in this

    parameter.This table should never be built-up 'manually'.

    12)I_DEFAULT (Export Parameter)

    If this parameter is SPACE, then no initial display variant can be defined.If this is passed as 'X' then the initial variant can be defined

    13)I_SAVE (Export Parameter)

    Set this parameter as A if you want to give the user an option to save anoutput layout user specifically or as a standard variant.

    Set this parameter as U if you want to give the user an option to save anoutput layout only user specifically

    Set this parameter as X for standard save onlyLeave it blank to provide no save option.

    14)IS_VARIANT (Export Parameter)

    Pass the display variant to be used ( if already saved) in this structure

    15)IT_EVENTS (Export Parameter)This internal table tells the ALV, which events are processed by the user

    CALLBACK.

    16)IT_EVENT_EXIT (Export Parameter)

    Table for passing ALV standard function codes, to return control to the Userbefore and/or after execution with the callback event USER_COMMAND.

  • 7/27/2019 Alv diaplay

    6/23

    17)IS_PRINT (Export Parameter)Print control parameter

    18)I_SCREEN_START_COLUMN (Export Parameter)

    Only to be used if the list is output in a popup. X coordinate of the top left-hand corner of the popup.

    19)I_SCREEN_START_LINE (Export Parameter)Only used if the list is output in a popup. Y coordinate of the top left-handcorner of the popup.

    20)I_SCREEN_END_COLUMN (Export Parameter)Only used if the list is output in a popup. X coordinate of the bottom right-

    hand corner of the popup.

    21)I_SCREEN_END_LINE (Export Parameter)Only used if the list is output in a popup. Y coordinate of the bottom right-

    hand corner of the popup.

    22)T_OUTTAB (Export Parameter)

    Output internal table having the data to be displayed

    EVENT HANDLING IN ALV ( REUSE_ALV_EVENTS_GET)

    Just as the case of normal reports we can have event handling in ALV also. We canhave drill downs when the user double clicks on a certain line of data and so on.

    There are a limited number of events that can be handled in ALV. We can get a list

    of the same by using the function module REUSE_ALV_EVENTS_GET. This functionmodule returns an internal table having two fields NAME and FORM. The NAME field

    will have the list of all the events that can be handled in ALV. The FORM field will be

    blank when the FM returns the internal table.

    We have to fill the name of the form in which we are going to handle a particularevent in the FORM field corresponding to the EVENT in the internal table returned by

    the FM.For e.g. TOP_OF_PAGE is an event that can be handled in ALV. For having a

    TOP_OF_PAGE event declare a form (say page_top). Modify the internal table

    returned by FM for the row having the event TOP_OF_PAGE with the form namePAGE_TOP.

    The FM REUSE_ALV_EVENTS_GET has the following parameters

    1. I_LIST_TYPE (type SLIS_LIST_TYPE) (Export Parameter)

    Pass any one of the following values0 = simple list REUSE_ALV_LIST_DISPLAY

    1 = hierarchical-sequential list REUSE_ALV_HIERSEQ_LIST_DISPLAY2 = simple block list REUSE_ALV_BLOCK_LIST_APPEND

    3 = hierarchical-sequential block listREUSE_ALV_BLOCK_LIST_HS_APPEND

    2. ET_EVENTS (type SLIS_T_EVENT) (Import Parameter)

  • 7/27/2019 Alv diaplay

    7/23

    This internal table is returned by the FM with the list of all possibleCALLBACK events for the particular ALV display.

    Pass this modified internal to the display function module through the correspondingparameter (IT_EVENTS explained earlier)

    DISPLAY VARIANTS

    We can change the display of the list by using the display variants. Basically thedisplay variants decide the appearance of the list. We can save display variants of

    the list by going Settings Display variant Save of the ALV display.

    We can ask the ALV to use a particular display variant for display. We have to pass

    the variant name to the display FM through the parameter IS_VARIANT (explainedearlier). We can also provide a selection to the user in the selection screen to select

    a particular display variant. The FM used to obtain the F4 help for the selection ofthe layout or the variant is explained next.

    F4 HELP FOR DISPLAY VARIANTS (REUSE_ALV_VARIANT_F4)

    The function module REUSE_ALV_VARIANT_F4 gives a popup to the user to selectthe display variant from a list of variants, which have been already saved.

    Some of the important parameters of the above function modules are:1. IS_VARIANT (Like DISVARIANT) (Export Parameter)

    Pass the program name in the field REPORT of this structure.

    2. I_SAVE (Export Parameter)

    As explained for the FM REUSE_ALV_LIST_DISPLAY

    3. ES_VARIANT (Like DISVARIANT) (Import Parameter)Pass the same variable as was passed for the first parameter.

    When we select a particular layout to be used, The FM returns thename of the variant in the field VARIANT of this structure.

    HIERARCHIAL DISPLAY - REUSE_ALV_HIERSEQ_LIST_DISPLAY

    Hierarchical display is possible only in LIST display. A typical example where such a

    display would be required will beHeader of the display would be the PO header details

    And items of the display would be line item details of the specific PO.

    For getting the hierarchical display use the FMREUSE_ALV_HIERSEQ_LIST_DISPLAY

    The interface of this FM is very much similar to that of the normal list display

    function module. This FM has some extra parameters which are related to thehierarchical display. The new parameters to be passed to this FM are

    1. I_TABNAME_HEADER (Export Parameter)

    Name of the internal table in the program containing the output data of the

    highesthierarchy level.

  • 7/27/2019 Alv diaplay

    8/23

    2. I_TABNAME_ITEM (Export Parameter)

    Name of the internal table in the program containing the output data of thelowest

    hierarchy level.

    3. I_STRUCTURE_NAME_HEADER (Export Parameter)Same as the I_STRUCTURE_NAME of the FM REUSE_ALV_LIST_DISPLAY. (forthe internal table containing the output data of the highest hierarchy level).

    4. I_STRUCTURE_NAME_ITEM (Export Parameter)Same as the I_STRUCTURE_NAME of the FM REUSE_ALV_LIST_DISPLAY. (for

    the internal table containing the output data of the lowest hierarchy level).

    5. IS_KEYINFO (Export Parameter)For the hierarchical display, the two tables should be linked using key fields.

    The key fields should be present in both the tables. These fields defined asthe key, will be displayed both in the header level and the item level and

    cannot be suppressed.

    The parameters IS_KEYINFO contains the field names which link the twotables. Enter the foreign key field names in the fields KEYINFO-HEADERxx

    and KEYINFO-ITEMxx.

    6. T_OUTTAB_HEADER (Export Parameter)The internal table in the program containing the output data of the highest

    hierarchy level.

    7. T_OUTTAB_ITEM (Export Parameter)The internal table in the program containing the output data of the lowest

    hierarchy level.

    DISPLAYING MORE THAN ONE INTERNAL TABLES IN ALV

    The above FMs is useful in displaying just one internal table at a time. More than

    one internal tables can be displayed in ALV using the FMREUSE_ALV_BLOCK_LIST_DISPLAY

    Follow the procedure explained below to get an ALV display with more than one

    internal tables.

    1) Call the FM REUSE_ALV_BLOCK_LIST_INIT.

    Pass the following parameters

    I_CALLBACK_PROGRAM

    I_CALLBACK_PF_STATUS_SET

    I_CALLBACK_USER_COMMAND

    IT_EXCLUDING

  • 7/27/2019 Alv diaplay

    9/23

    The functions of all the parameters are same as that in the FMREUSE_ALV_LIST_DISPLAY. At least the first parameter

    (I_CALLBACK_PROGRAM) has to be passed in this case.

    2) Call the FM REUSE_ALV_BLOCK_LIST_APPEND as many times as the numberof internal tables to be displayed, each time passing the details regarding the

    specific internal table under considerations

    The parameters that can be passed are

    IS_LAYOUT

    IT_FIELDCAT

    I_TABNAME

    IT_EVENTS

    IT_SORT

    T_OUTTAB

    The functions of all the parameters are same as that in the FM

    REUSE_ALV_LIST_DISPLAY.

    3) Finally Call the FM REUSE_ALV_BLOCK_LIST_DISPLAY

    The parameters that can be passed are

    I_INTERFACE_CHECK

    IS_PRINT

    I_SCREEN_START_COLUMN

    I_SCREEN_START_LINE

    I_SCREEN_END_COLUMN

    I_SCREEN_END_LINE

    The functions of all the parameters are same as that in the FM

    REUSE_ALV_LIST_DISPLAY.

    SAMPLE CODES

    1. Sample code for Normal List Display

    This code displays the material details for the materials selected by the user.

    TABLES : mara.

    SELECT-OPTIONS: s_matnr FOR mara-matnr.

    TYPE-POOLS: slis.

    DATA: BEGIN OF itab OCCURS 0,matnr LIKE mara-matnr,

    ernam LIKE mara-ernam,ersda LIKE mara-ersda,

    labor LIKE mara-labor,

  • 7/27/2019 Alv diaplay

    10/23

    END OF itab.

    DATA: i_fieldcat TYPE slis_t_fieldcat_alv,xevents TYPE slis_t_event,

    ls_event TYPE slis_alv_event,slis_ev_top TYPE slis_formname VALUE 'TOP_OF_PAGE'.

    DATA: v_repid LIKE sy-repid.

    START-OF-SELECTION.

    v_repid = sy-repid.

    SELECT matnr ernam ersda labor

    INTO TABLE itabFROM mara

    WHERE matnr IN s_matnr.

    CALL FUNCTION 'REUSE_ALV_EVENTS_GET'

    EXPORTINGi_list_type = 0

    IMPORTING

    et_events = xeventsEXCEPTIONS

    list_type_wrong = 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.

    READ TABLE xevents WITH KEY name = slis_ev_topINTO ls_event.

    IF sy-subrc = 0.MOVE slis_ev_top TO ls_event-form.

    APPEND ls_event TO xevents.ENDIF.

    CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'EXPORTING

    i_program_name = v_repidi_internal_tabname = 'ITAB'

    * I_STRUCTURE_NAME =* I_CLIENT_NEVER_DISPLAY = 'X'

    i_inclname = v_repidi_bypassing_buffer = 'X'

    i_buffer_active = ' 'CHANGING

    ct_fieldcat = i_fieldcatEXCEPTIONS

    inconsistent_interface = 1program_error = 2

    OTHERS = 3

  • 7/27/2019 Alv diaplay

    11/23

    .IF sy-subrc 0.

    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgnoWITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

    ENDIF.

    CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'EXPORTING

    * I_INTERFACE_CHECK = ' '

    i_bypassing_buffer = 'X'

    i_buffer_active = ' 'i_callback_program = v_repid

    * I_CALLBACK_PF_STATUS_SET = ' '* I_CALLBACK_USER_COMMAND = ' '

    * I_STRUCTURE_NAME =* IS_LAYOUT =

    it_fieldcat = i_fieldcat* IT_EXCLUDING =

    * IT_SPECIAL_GROUPS =

    * IT_SORT =* IT_FILTER =* IS_SEL_HIDE =

    * I_DEFAULT = 'X'i_save = 'A'

    * IS_VARIANT =IT_EVENTS = xevents

    * IT_EVENT_EXIT =* IS_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 =TABLES

    t_outtab = itab

    EXCEPTIONSprogram_error = 1

    OTHERS = 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.

    *&--------------------------------------------------------------------*

    *& Form top_of_page*&--------------------------------------------------------------------*

    * text*---------------------------------------------------------------------*

    FORM TOP_OF_PAGE.

  • 7/27/2019 Alv diaplay

    12/23

    WRITE:/ 'Top of page event triggered.

    WRITE:/ This report gives the material details'.

    ENDFORM. "top_of_page

    2. Sample Code for F4 help for the display variant

    This code retrieves all the display variants that have been stored under the current

    program

    PARAMETERS: p_vari LIKE disvariant-variant. "select variant

    DATA: v_st_variant LIKE disvariant,

    v_stx_variant LIKE disvariant,v_exit.

    CONSTANTS: c_save(1) VALUE A.

    AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_vari.

    v_st_variant-report = sy_repid.

    CALL FUNCTION 'REUSE_ALV_VARIANT_F4'EXPORTING

    is_variant = v_st_variant

    i_save = c_save* it_default_fieldcat =

    IMPORTINGe_exit = v_exit

    es_variant = v_stx_variantEXCEPTIONS

    not_found = 2.IF sy-subrc = 2.

    MESSAGE ID sy-msgid TYPE 'S' NUMBER sy-msgnoWITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

    ELSE.IF v_exit = space.

    p_vari = v_stx_variant-variant.ENDIF.

    ENDIF.

    3. Sample code for hierarchical display

    This program displays the PO details as the header and the Line details of the

    corresponding PO and the item details.

    TABLES : ekko,

    ekpo.

  • 7/27/2019 Alv diaplay

    13/23

    SELECT-OPTIONS: s_ebeln FOR ekko-ebeln.

    TYPE-POOLS: slis.

    DATA: BEGIN OF headertab OCCURS 0,ebeln LIKE ekko-ebeln,

    bstyp LIKE ekko-bstyp,bsart LIKE ekko-bsart,statu LIKE ekko-statu,

    END OF headertab.

    DATA: BEGIN OF itemtab OCCURS 0,

    ebeln LIKE ekpo-ebeln,ebelp LIKE ekpo-ebelp,

    matnr LIKE ekpo-matnr,werks LIKE ekpo-werks,

    menge LIKE ekpo-menge,netpr LIKE ekpo-netpr,

    peinh LIKE ekpo-peinh,

    netwr LIKE ekpo-netwr,END OF itemtab.

    DATA: i_fieldcat TYPE slis_t_fieldcat_alv.DATA: v_repid LIKE sy-repid.

    DATA: g_tabname_header TYPE slis_tabname,g_tabname_item TYPE slis_tabname,

    gs_keyinfo TYPE slis_keyinfo_alv.

    START-OF-SELECTION.

    v_repid = sy-repid.

    SELECT ebeln bstyp bsart statu

    INTO TABLE headertabFROM ekko

    WHERE ebeln IN s_ebeln.

    IF NOT headertab[] IS INITIAL.

    SELECT ebeln ebelp matnr werks menge netpr peinh netwrINTO TABLE itemtab

    FROM ekpoFOR ALL ENTRIES IN headertab

    WHERE ebeln = headertab-ebeln.ENDIF.

    CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'EXPORTING

    i_program_name = v_repidi_internal_tabname = 'HEADERTAB'

    * I_STRUCTURE_NAME =* I_CLIENT_NEVER_DISPLAY = 'X'

    i_inclname = v_repid

  • 7/27/2019 Alv diaplay

    14/23

    i_bypassing_buffer = 'X'i_buffer_active = ' '

    CHANGINGct_fieldcat = i_fieldcat

    EXCEPTIONSinconsistent_interface = 1

    program_error = 2OTHERS = 3

    .

    IF sy-subrc 0.

    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNOWITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

    ENDIF.

    CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'EXPORTING

    i_program_name = v_repidi_internal_tabname = 'ITEMTAB'

    * I_STRUCTURE_NAME =

    * I_CLIENT_NEVER_DISPLAY = 'X'i_inclname = v_repidi_bypassing_buffer = 'X'

    i_buffer_active = ' 'CHANGING

    ct_fieldcat = i_fieldcatEXCEPTIONS

    inconsistent_interface = 1program_error = 2

    OTHERS = 3.

    IF sy-subrc 0.

    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNOWITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

    ENDIF.

    gs_keyinfo-header01 = 'EBELN'.gs_keyinfo-item01 = 'EBELN'.

    g_tabname_header = 'HEADERTAB'.

    g_tabname_item = 'ITEMTAB'.

    CALL FUNCTION 'REUSE_ALV_HIERSEQ_LIST_DISPLAY'

    EXPORTING* I_INTERFACE_CHECK = ' '

    I_CALLBACK_PROGRAM = v_repid* I_CALLBACK_PF_STATUS_SET = ' '

    * I_CALLBACK_USER_COMMAND = ' '* IS_LAYOUT =

    IT_FIELDCAT = i_fieldcat* IT_EXCLUDING =

    * IT_SPECIAL_GROUPS =* IT_SORT =

    * IT_FILTER =

  • 7/27/2019 Alv diaplay

    15/23

    * IS_SEL_HIDE =* I_SCREEN_START_COLUMN = 0

    * I_SCREEN_START_LINE = 0* I_SCREEN_END_COLUMN = 0

    * I_SCREEN_END_LINE = 0* I_DEFAULT = 'X'

    I_SAVE = 'A'* IS_VARIANT =* IT_EVENTS =

    * IT_EVENT_EXIT =

    i_tabname_header = g_tabname_headeri_tabname_item = g_tabname_item

    * I_STRUCTURE_NAME_HEADER =* I_STRUCTURE_NAME_ITEM =

    is_keyinfo = gs_keyinfo* IS_PRINT =

    * IS_REPREP_ID =I_BYPASSING_BUFFER = 'X'

    I_BUFFER_ACTIVE = ' '

    * IMPORTING* E_EXIT_CAUSED_BY_CALLER =* ES_EXIT_CAUSED_BY_USER =

    tablest_outtab_header = headertab

    t_outtab_item = itemtabEXCEPTIONS

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

    4. Sample Code to display more than one internal table in ALV

    The two internal tables in the above example have been displayed separately in thiscode.

    TABLES : ekko,

    ekpo.

    SELECT-OPTIONS: s_ebeln FOR ekko-ebeln.

    TYPE-POOLS: slis.

    DATA: BEGIN OF headertab OCCURS 0,ebeln LIKE ekko-ebeln,

    bstyp LIKE ekko-bstyp,bsart LIKE ekko-bsart,

    statu LIKE ekko-statu,END OF headertab.

  • 7/27/2019 Alv diaplay

    16/23

    DATA: BEGIN OF itemtab OCCURS 0,ebeln LIKE ekpo-ebeln,

    ebelp LIKE ekpo-ebelp,matnr LIKE ekpo-matnr,

    werks LIKE ekpo-werks,menge LIKE ekpo-menge,

    netpr LIKE ekpo-netpr,peinh LIKE ekpo-peinh,netwr LIKE ekpo-netwr,

    END OF itemtab.

    DATA: i_fieldcat TYPE slis_t_fieldcat_alv,

    i_fieldcat1 TYPE slis_t_fieldcat_alv.

    DATA: v_repid LIKE sy-repid,v_layout TYPE slis_layout_alv,

    v_events TYPE slis_t_event,v_print TYPE slis_print_alv.

    START-OF-SELECTION.

    v_repid = sy-repid.

    SELECT ebeln bstyp bsart statuINTO TABLE headertab

    FROM ekkoWHERE ebeln IN s_ebeln.

    IF NOT headertab[] IS INITIAL.SELECT ebeln ebelp matnr werks menge netpr peinh netwr

    INTO TABLE itemtab

    FROM ekpoFOR ALL ENTRIES IN headertab

    WHERE ebeln = headertab-ebeln.ENDIF.

    CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'

    EXPORTINGi_program_name = v_repid

    i_internal_tabname = 'HEADERTAB'* I_STRUCTURE_NAME =

    * I_CLIENT_NEVER_DISPLAY = 'X'i_inclname = v_repid

    i_bypassing_buffer = 'X'i_buffer_active = ' '

    CHANGINGct_fieldcat = i_fieldcat

    EXCEPTIONSinconsistent_interface = 1

    program_error = 2OTHERS = 3

    .

  • 7/27/2019 Alv diaplay

    17/23

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

    EXPORTINGi_program_name = v_repidi_internal_tabname = 'ITEMTAB'

    * I_STRUCTURE_NAME =

    * I_CLIENT_NEVER_DISPLAY = 'X'i_inclname = v_repid

    i_bypassing_buffer = 'X'i_buffer_active = ' '

    CHANGINGct_fieldcat = i_fieldcat1

    EXCEPTIONSinconsistent_interface = 1

    program_error = 2

    OTHERS = 3.

    IF sy-subrc 0.

    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNOWITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

    ENDIF.

    CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_INIT'EXPORTING

    i_callback_program = v_repid* I_CALLBACK_PF_STATUS_SET = ' '

    * I_CALLBACK_USER_COMMAND = ' '

    * IT_EXCLUDING =.

    IF NOT headertab[] IS INITIAL.

    CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_APPEND'EXPORTING

    is_layout = v_layout

    it_fieldcat = i_fieldcati_tabname = 'HEADERTAB'

    it_events = v_events* IT_SORT =

    * I_TEXT = ' 'TABLES

    t_outtab = headertabEXCEPTIONS

    program_error = 1maximum_of_appends_reached = 2

    OTHERS = 3.

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

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

  • 7/27/2019 Alv diaplay

    18/23

    ENDIF.

    ENDIF.

    IF NOT itemtab[] IS INITIAL.

    CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_APPEND'EXPORTINGis_layout = v_layout

    it_fieldcat = i_fieldcat1

    i_tabname = 'ITEMTAB'it_events = v_events

    * IT_SORT =* I_TEXT = ' '

    TABLESt_outtab = itemtab

    EXCEPTIONSprogram_error = 1

    maximum_of_appends_reached = 2

    OTHERS = 3.

    IF sy-subrc 0.

    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgnoWITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

    ENDIF.

    ENDIF.

    IF NOT headertab[] IS INITIAL ORNOT itemtab[] IS INITIAL.

    CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_DISPLAY'* EXPORTING

    * I_INTERFACE_CHECK = ' '* IS_PRINT =

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

    EXCEPTIONSprogram_error = 1

    OTHERS = 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.

    ENDIF.

  • 7/27/2019 Alv diaplay

    19/23

    5. Sample code for interactive reporting in ALV

    This code displays the PO header details as the basic listing. On clicking on any POnumber, the item details are displayed.

    TABLES : ekko,

    ekpo.

    SELECT-OPTIONS: s_ebeln FOR ekko-ebeln.

    TYPE-POOLS: slis.

    DATA: BEGIN OF headertab OCCURS 0,ebeln LIKE ekko-ebeln,

    bstyp LIKE ekko-bstyp,bsart LIKE ekko-bsart,

    statu LIKE ekko-statu,END OF headertab.

    DATA: BEGIN OF itemtab OCCURS 0,

    ebeln LIKE ekpo-ebeln,ebelp LIKE ekpo-ebelp,

    matnr LIKE ekpo-matnr,werks LIKE ekpo-werks,

    menge LIKE ekpo-menge,netpr LIKE ekpo-netpr,

    peinh LIKE ekpo-peinh,

    netwr LIKE ekpo-netwr,END OF itemtab.

    DATA: BEGIN OF level2 OCCURS 0,

    ebeln LIKE ekpo-ebeln,ebelp LIKE ekpo-ebelp,matnr LIKE ekpo-matnr,

    werks LIKE ekpo-werks,menge LIKE ekpo-menge,

    netpr LIKE ekpo-netpr,peinh LIKE ekpo-peinh,

    netwr LIKE ekpo-netwr,END OF level2.

    DATA: i_fieldcat TYPE slis_t_fieldcat_alv,

    i_fieldcat1 TYPE slis_t_fieldcat_alv.

    DATA: v_repid LIKE sy-repid,v_layout TYPE slis_layout_alv,

    v_events TYPE slis_t_event,v_print TYPE slis_print_alv,

    l_fieldcat TYPE slis_fieldcat_alv.

    START-OF-SELECTION.

  • 7/27/2019 Alv diaplay

    20/23

    v_repid = sy-repid.

    SELECT ebeln bstyp bsart statu

    INTO TABLE headertabFROM ekko

    WHERE ebeln IN s_ebeln.

    IF NOT headertab[] IS INITIAL.

    SELECT ebeln ebelp matnr werks menge netpr peinh netwr

    INTO TABLE itemtabFROM ekpo

    FOR ALL ENTRIES IN headertabWHERE ebeln = headertab-ebeln.

    ENDIF.

    CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'

    EXPORTING

    i_program_name = v_repidi_internal_tabname = 'HEADERTAB'

    * I_STRUCTURE_NAME =

    * I_CLIENT_NEVER_DISPLAY = 'X'i_inclname = v_repid

    i_bypassing_buffer = 'X'i_buffer_active = ' '

    CHANGINGct_fieldcat = i_fieldcat

    EXCEPTIONSinconsistent_interface = 1

    program_error = 2

    OTHERS = 3.

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

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

    LOOP AT i_fieldcat INTO l_fieldcat.CASE l_fieldcat-fieldname.

    WHEN 'EBELN'.l_fieldcat-hotspot = 'X'.

    MODIFY i_fieldcat FROM l_fieldcat.ENDCASE.

    ENDLOOP.

    CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'EXPORTING

    * I_INTERFACE_CHECK = ' 'i_bypassing_buffer = 'X'

    i_buffer_active = ' 'i_callback_program = v_repid

    * I_CALLBACK_PF_STATUS_SET = ' '

  • 7/27/2019 Alv diaplay

    21/23

    i_callback_user_command = 'USER_COMMAND'* I_STRUCTURE_NAME =

    * IS_LAYOUT =it_fieldcat = i_fieldcat

    * IT_EXCLUDING =* IT_SPECIAL_GROUPS =

    * IT_SORT =* IT_FILTER =* IS_SEL_HIDE =

    * I_DEFAULT = 'X'

    i_save = 'A'* IS_VARIANT =

    * IT_EVENTS =* IT_EVENT_EXIT =

    * IS_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 =TABLES

    t_outtab = headertabEXCEPTIONS

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

    *&--------------------------------------------------------------------*

    *& Form USER_COMMAND*&--------------------------------------------------------------------*

    * text

    *---------------------------------------------------------------------** -->R_UCOMM text

    * -->RS_SELFIELDtext*---------------------------------------------------------------------*

    FORM user_command USING r_ucomm LIKE sy-ucommrs_selfield TYPE slis_selfield.

    IF rs_selfield-fieldname EQ 'EBELN'.

    CASE r_ucomm.

    WHEN '&IC1'.

    READ TABLE headertab INDEX rs_selfield-tabindex.

  • 7/27/2019 Alv diaplay

    22/23

    REFRESH level2.CLEAR level2.

    LOOP AT itemtab WHERE ebeln = headertab-ebeln.

    APPEND itemtab TO level2.ENDLOOP.

    CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'EXPORTING

    i_program_name = v_repid

    i_internal_tabname = 'LEVEL2'* I_STRUCTURE_NAME =

    * I_CLIENT_NEVER_DISPLAY = 'X'i_inclname = v_repid

    i_bypassing_buffer = 'X'i_buffer_active = ' '

    CHANGINGct_fieldcat = i_fieldcat1

    EXCEPTIONS

    inconsistent_interface = 1program_error = 2OTHERS = 3

    .IF sy-subrc 0.

    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgnoWITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

    ENDIF.

    CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'

    EXPORTING

    * I_INTERFACE_CHECK = ' 'i_bypassing_buffer = 'X'

    i_buffer_active = ' 'i_callback_program = v_repid

    * I_CALLBACK_PF_STATUS_SET = ' '* I_CALLBACK_USER_COMMAND =

    * I_STRUCTURE_NAME =

    * IS_LAYOUT =it_fieldcat = i_fieldcat1

    * IT_EXCLUDING =* IT_SPECIAL_GROUPS =

    * IT_SORT =* IT_FILTER =

    * IS_SEL_HIDE =* I_DEFAULT = 'X'

    i_save = 'A'* IS_VARIANT =

    * IT_EVENTS =* IT_EVENT_EXIT =

    * IS_PRINT =* IS_REPREP_ID =

    * I_SCREEN_START_COLUMN = 0

  • 7/27/2019 Alv diaplay

    23/23

    * 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 = level2

    EXCEPTIONS

    program_error = 1

    OTHERS = 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.

    ENDCASE.

    ENDIF.

    ENDFORM. "USER_COMMAND

    NOTE:

    To get more sample codes go to transaction SE38 and search for programs BALV*.This lists sample codes for many of the possible manipulations using ALV displays.