Enhancing ALV Grid Displays with Top-of-Page Events: A Comprehensive Guide

 

Top of Page :-

  • In a reusable ALV grid display, the "top of page" event refers to a specific event triggered during the rendering of the ALV grid. This event allows developers to insert custom logic or modify the appearance of the ALV grid at the beginning of each new page.
  • Within the TOP_OF_PAGE method, you can perform various tasks such as adding headers, inserting additional rows, setting page titles, customizing toolbar elements, or any other actions required to enhance the presentation or functionality of the ALV grid.

Function Module Use :

  • REUSE_ALV_COMMENTARY_WRITE

Various Options available available in REUSE_ALV_COMMENTARY_WRITE :-

  1. H(Header) :- Only the contents of INFO are output and the key is ignored. Bold followed by empty line
  2. S(Selection) :- Key is in Bold and the Info is in normal followed by empty line.
  3. A(Action) :- Only the contents of INFO are output and the KEY is ignored. Normal intensity

Implementation :-

  • Step 1 :- Uncomment the I_CALLBACK_TOP_PAGE exporting parameter in the REUSE_ALV_GRID_DISPLAY and give a suitable name to it.



  • Step 2 :- Create a subroutine at the end of program

    • Note :- All the subroutines must be written at the end of the program.
  • Step 3 :- Call the function module REUSE_ALV_COMMENTARY_WRITE and write the below logic.



  • Step 4 :- Pass the name of program or system variable ‘SY_REPID’ in I_CALLBACK_PROGRAM in REUSE_ALV_GRID_DISPLAY.



Code :-

******************************************************************************
*Start of Program
*Type Strcuture fo Both header and Item table
TYPES : BEGIN OF ty_vbak,
          vbeln TYPE vbeln_va,
          erdat TYPE erdat,
          erzet TYPE erzet,
          ernam TYPE ernam,
          vbtyp TYPE vbtypl,
        END OF ty_vbak.
TYPES : BEGIN OF ty_vbap,
          vbeln TYPE vbeln_va,
          posnr TYPE posnr_va,
          matnr TYPE matnr,
        END OF ty_vbap.

********************************************
*Type structure for final table.
TYPES : BEGIN OF ty_final,
          vbeln TYPE vbeln_va,
          erdat TYPE erdat,
          erzet TYPE erzet,
          ernam TYPE ernam,
          vbtyp TYPE vbtypl,
          posnr TYPE posnr_va,
          matnr TYPE matnr,
        END OF ty_final.

*************************************************
*Declaring the internal table and work area
DATA : lt_vbak  TYPE TABLE OF ty_vbak,
       ls_vbak  TYPE ty_vbak,
       lt_vbap  TYPE TABLE OF ty_vbap,
       ls_vbap  TYPE ty_vbap,
       lt_final TYPE TABLE OF ty_final,
       ls_final TYPE ty_final,
       lv_vbeln TYPE vbeln_va.

***************
*Declaring a select option.
SELECT-OPTIONS : s_vbeln FOR lv_vbeln.

START-OF-SELECTION.
  SELECT vbeln erdat erzet ernam vbtyp
    FROM vbak INTO TABLE lt_vbak
    WHERE vbeln IN s_vbeln.

  IF lt_vbak IS NOT INITIAL.
    SELECT vbeln posnr matnr
      FROM vbap
      INTO TABLE lt_vbap
      FOR ALL ENTRIES IN lt_vbak
      WHERE vbeln = lt_vbak-vbeln.

    LOOP AT lt_vbap INTO ls_vbap.
      ls_final-posnr = ls_vbap-posnr.
      ls_final-matnr = ls_vbap-matnr.

      READ TABLE lt_vbak INTO ls_vbak WITH KEY vbeln = ls_vbap-vbeln.
      IF sy-subrc EQ 0.
        ls_final-vbeln = ls_vbak-vbeln.
        ls_final-erdat = ls_vbak-erdat.
        ls_final-erzet = ls_vbak-erzet.
        ls_final-ernam = ls_vbak-ernam.
        ls_final-vbtyp = ls_vbak-vbtyp.
      ENDIF.

      APPEND ls_final TO lt_final.
      CLEAR : ls_final, ls_vbak, ls_vbap.
    ENDLOOP.

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
 EXPORTING
*   I_INTERFACE_CHECK                 = ' '
*   I_BYPASSING_BUFFER                = ' '
*   I_BUFFER_ACTIVE                   = ' '
   I_CALLBACK_PROGRAM                = sy-repid
*   I_CALLBACK_PF_STATUS_SET          = ' '
*   I_CALLBACK_USER_COMMAND           = ' '
   I_CALLBACK_TOP_OF_PAGE            = 'TOP_OF_PAGE'
*   I_CALLBACK_HTML_TOP_OF_PAGE       = ' '
*   I_CALLBACK_HTML_END_OF_LIST       = ' '
   I_STRUCTURE_NAME                  = 'ZAR_ORDER_DETAILS'
*   I_BACKGROUND_ID                   = ' '
*   I_GRID_TITLE                      =
*   I_GRID_SETTINGS                   =
*   IS_LAYOUT                         =
*   IT_FIELDCAT                       =
*   IT_EXCLUDING                      =
*   IT_SPECIAL_GROUPS                 =
*   IT_SORT                           =
*   IT_FILTER                         =
*   IS_SEL_HIDE                       =
*   I_DEFAULT                         = 'X'
*   I_SAVE                            = ' '
*   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
*   I_HTML_HEIGHT_TOP                 = 0
*   I_HTML_HEIGHT_END                 = 0
*   IT_ALV_GRAPHICS                   =
*   IT_HYPERLINK                      =
*   IT_ADD_FIELDCAT                   =
*   IT_EXCEPT_QINFO                   =
*   IR_SALV_FULLSCREEN_ADAPTER        =
*   O_PREVIOUS_SRAL_HANDLER           =
* IMPORTING
*   E_EXIT_CAUSED_BY_CALLER           =
*   ES_EXIT_CAUSED_BY_USER            =
  TABLES
    t_outtab                          = lt_final
 EXCEPTIONS
   PROGRAM_ERROR                     = 1
   OTHERS                            = 2
          .
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.

  ENDIF.

  FORM TOP_OF_PAGE.
    DATA : lt_heading type table of slis_listheader.
    DATA : ls_heading type slis_listheader.
    clear lt_heading.

    ls_heading-typ = 'H'.
    ls_heading-info = 'Sales Order Display'.
    APPEND ls_heading to lt_heading.
    clear ls_heading.

    CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
      EXPORTING
        it_list_commentary       = lt_heading
              .

  ENDFORM.

*****************
*End of Program
*******************************************************************

Execute the code :-




Comments

Popular posts from this blog

Understanding Different Types of SAP Function Modules: Normal, RFC, and Update

Unlocking SAP ABAP Secrets: Interactive Classical Reports with GET CURSOR, At User Command, and a Comparison of HIDE Statements

Mastering ABAP: A Step-by-Step Guide to Function Modules and Groups for Modularized Programming