Skip to Content
avatar image
Former Member

ALV heading on top of page - set_table_for_first_display

hi,

I want to print the selection screen parameters in the heading of alv.

I am using set_table_for_first_display to display my ALV.

Please let me know all steps to print the heading on top of the page.

Regards,

Shital

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

7 Answers

  • Best Answer
    avatar image
    Former Member
    May 21, 2009 at 11:35 AM

    Hi,

    Declare your internal tables for ALV

    IF not select-options(what ever field there in selection screen) [] is initial.
        WA_HEADER-TYP = 'S'.
        WA_HEADER-KEY = (Selection screen field).
        IF select-options-high IS INITIAL.
          WA_HEADER-info = selection screen field-low.
          APPEND WA_HEADER to T_HEADER.
        ELSE.
          CONCATENATE  s_werks-low  s_werks-high
          APPEND WA_HEADER to T_HEADER.
        ENDIF.
        CLEAR: WA_HEADER.
      ENDIF.
    
      CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
        EXPORTING
          IT_LIST_COMMENTARY = t_header.
    ENDFORM.                    " ALV_TOP-OF-PAGE

    Hope it helps!

    Regards,

    Sandhya

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member

      I am using call function 'REUSE_ALV_COMMENTARY_WRITE'

      to display logo but no logo is displayed.

      REgards,

      Shital

  • avatar image
    Former Member
    May 21, 2009 at 09:52 AM

    Hello,

    Pass the values to the LAYOUT structure title field , to isplay the selection values in header ...

    otherwise

    keep separate inout fields outof ALV containner screen and pass the selections creen fields to the output screen fields in PBO of alv container screen ,

    regards

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    May 21, 2009 at 09:53 AM

    see demo program BCALV_GRID_01.

    otherwise

    Try this code,

    First add a handler method in your handler class definition as:

    e.g. METHOD handle_print_top_of_list FOR EVENT print_top_of_list OF cl_gui_alv_grid .

    Then implement the method in the implementation part of your local class.

    e.g. METHOD handle_print_top_of_list .

    WRITE:/ 'Flights Made on ', sy-datum .

    ENDMETHOD .

    And register this method as the handler.

    e.g. SET HANDLER gr_event_handler->handle_print_top_of_list FOR gr_alvgrid .

    Add comment
    10|10000 characters needed characters exceeded

  • May 21, 2009 at 10:10 AM

    Hi,

    Please refer to the following link,

    Hope it will provide you with some help

    http://www.sap-img.com/abap/sample-alv-heading-in-alv.htm

    Regards,

    Bhanu

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    May 21, 2009 at 10:11 AM

    Hi Shital,

    Please chk the code below :

    *&----------------------------------------------&
    *& ALV DATA DECLARATIONS
    *&----------------------------------------------&
    
    DATA : LT_FIELDCAT   TYPE SLIS_T_FIELDCAT_ALV,
           LW_FIELDCAT   LIKE LINE OF LT_FIELDCAT,
           WA_LAYOUT     TYPE SLIS_LAYOUT_ALV,
           IT_EVENTS     TYPE SLIS_T_EVENT,
           WA_EVENTS     TYPE SLIS_ALV_EVENT,
           IT_LISTHEADER TYPE SLIS_T_LISTHEADER,
           WA_LISTHEADER TYPE SLIS_LISTHEADER.
    
    
    
    INITIALIZATION.
      PERFORM getevents using it_events.
      PERFORM desinlayout.
    
    
    
    
    
    *&---------------------------------------------------------------------*
    *&      Form  DISPLAY
    *&---------------------------------------------------------------------*
    *       text
    *----------------------------------------------------------------------*
    *  -->  p1        text
    *  <--  p2        text
    *----------------------------------------------------------------------*
    FORM DISPLAY .
    
      CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
        EXPORTING
          I_CALLBACK_PROGRAM = sy-repid
    *      I_GRID_TITLE       = i_title_gts
          IS_LAYOUT          = wa_layout
          IT_FIELDCAT        = lt_fieldcat
          IT_EVENTS          = it_events
        TABLES
          T_OUTTAB           = <dyn_table>
        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.
    
    ENDFORM.                    " DISPLAY
    *&---------------------------------------------------------------------*
    *&      Form  DESINLAYOUT
    *&---------------------------------------------------------------------*
    *       text
    *----------------------------------------------------------------------*
    *  -->  p1        text
    *  <--  p2        text
    *----------------------------------------------------------------------*
    FORM DESINLAYOUT .
    
      WA_LAYOUT-ZEBRA = 'X'.
      WA_LAYOUT-COLWIDTH_OPTIMIZE = 'X'.
    
    
    ENDFORM.                    " DESINLAYOUT
    *&---------------------------------------------------------------------*
    *&      Form  GETEVENTS
    *&---------------------------------------------------------------------*
    *       text
    *----------------------------------------------------------------------*
    *      -->P_IT_EVENTS  text
    *----------------------------------------------------------------------*
    FORM GETEVENTS  USING  P_IT_EVENTS type slis_t_event.
    
      .
    
      CALL FUNCTION 'REUSE_ALV_EVENTS_GET'
        EXPORTING
          I_LIST_TYPE     = 0
        IMPORTING
          ET_EVENTS       = p_it_events
        EXCEPTIONS
          LIST_TYPE_WRONG = 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.
    
      READ TABLE P_IT_EVENTS INTO WA_EVENTS WITH KEY NAME = 'TOP_OF_PAGE'.
      WA_EVENTS-FORM = 'TOP_OF_PAGE'.
    
      MODIFY IT_EVENTS FROM WA_EVENTS TRANSPORTING FORM WHERE NAME = WA_EVENTS-NAME.
    
    ENDFORM.                    " GETEVENTS
    
    
    
    *&---------------------------------------------------------------------
    *& Form top-of-page
    *&---------------------------------------------------------------------
    FORM TOP_OF_PAGE.
    
      WA_LISTHEADER-TYP = 'S'.
      WA_LISTHEADER-KEY = 'DATE'.
    * WA_LISTHEADER-INFO = SY-DATUM. " - DG1K902198
      WRITE SY-DATUM TO WA_LISTHEADER-INFO." + DG1K902198
    _*(HERE INSTEAD OF SY-DATUM YOU CAN PASS THE SELECTION SCREEN PARAMETER(S_VBELN/ ANY parameter which is of selection screen) TO WRITE THEM ON THE TOP OF PAGE)*_  APPEND WA_LISTHEADER TO IT_LISTHEADER.
    
    
    
      WA_LISTHEADER-TYP = 'S'.
      WA_LISTHEADER-KEY = 'TIME'.
    * WA_LISTHEADER-INFO = SY-UZEIT." - DG1K902198
      WRITE SY-UZEIT TO WA_LISTHEADER-INFO. " +DG1K902198
      APPEND WA_LISTHEADER TO IT_LISTHEADER.
    
      WA_LISTHEADER-TYP = 'S'.
      WA_LISTHEADER-KEY = 'CLIENT'.
      WA_LISTHEADER-INFO = SY-MANDT.
      APPEND WA_LISTHEADER TO IT_LISTHEADER.
    *----------------------------------------------------------*
    *&TO DISPLAY THE TOTAL NO OF RECORDS IN THE OUTPUT SCREEN  &  "+ DG1K902352
    *----------------------------------------------------------*
      WA_LISTHEADER-TYP = 'S'.
      WA_LISTHEADER-KEY = 'Nbr of records'.
      WA_LISTHEADER-INFO = V_COUNT.
      APPEND WA_LISTHEADER TO IT_LISTHEADER.
    
      CLEAR WA_LISTHEADER.
    
      CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
        EXPORTING
          it_list_commentary = IT_LISTHEADER. "it_listheader.
    
    
      REFRESH IT_LISTHEADER.         "it_listheader.
    
    
    ENDFORM. "top-of-pa

    Hope this is helpful.....

    Regards,

    Kittu

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    May 21, 2009 at 10:31 AM

    Hi Shital ,

    I hope this code helps you. Also check your field catalog which you have created.

    • Writing select-option values on top-of-page .

    Code:

    REPORT ZALV_SAMPLE.

    • NO STANDARD PAGE HEADING

    • LINE-COUNT 58

    • LINE-SIZE 220.

    TYPE-POOLS: SLIS. "for 'REUSE_ALV...list&grids'

    ----


    • TABLES *

    ----


    TABLES: KNA1. "General Data in Customer Master

    .

    ----


    • Internal data *

    ----


    DATA: BEGIN OF LT_ALVTABLE OCCURS 0,

    KUNNR LIKE KNA1-KUNNR,

    NAME1 LIKE KNA1-NAME1,

    NAME2 LIKE KNA1-NAME2,

    STRAS LIKE KNA1-STRAS,

    PSTLZ LIKE KNA1-PSTLZ,

    ORT01 LIKE KNA1-ORT01,

    UMSA1 LIKE KNA1-UMSA1,

    KTOKD LIKE KNA1-KTOKD,

    END OF LT_ALVTABLE.

    • data-statements that are necessary for the use of the ALV-grid

    DATA: GT_XEVENTS TYPE SLIS_T_EVENT.

    DATA: XS_EVENT TYPE SLIS_ALV_EVENT.

    DATA: REPID TYPE SY-REPID.

    DATA: ZTA_PRINT TYPE SLIS_T_FIELDCAT_ALV WITH HEADER LINE.

    DATA: LO_LAYOUT TYPE SLIS_LAYOUT_ALV.

    DATA: LO_ITABNAME TYPE SLIS_TABNAME.

    DATA: LS_VARIANT TYPE DISVARIANT.

    ----


    • Initialization *

    ----


    INITIALIZATION.

    ----


    • Parameters and select-options *

    ----


    SELECT-OPTIONS SO_KUNNR FOR KNA1-KUNNR DEFAULT '2000' TO '2300'.

    SELECT-OPTIONS SO_NAME FOR KNA1-NAME1.

    PARAMETERS: PA_PSTCD AS CHECKBOX DEFAULT 'X'.

    PARAMETERS: PA_VAR AS CHECKBOX DEFAULT 'X'.

    ----


    • Start of main program *

    ----


    START-OF-SELECTION.

    PERFORM SELECT_RECORDS.

    PERFORM PRINT_ALVLIST.

    END-OF-SELECTION.

    &----


    *& Form select_records

    &----


    FORM SELECT_RECORDS.

    SELECT * FROM KNA1 INTO CORRESPONDING FIELDS OF LT_ALVTABLE

    WHERE KUNNR IN SO_KUNNR

    AND NAME1 IN SO_NAME.

    APPEND LT_ALVTABLE.

    ENDSELECT.

    ENDFORM. " select_records

    &----


    *& Form print_alvlist

    &----


    FORM PRINT_ALVLIST.

    REPID = SY-REPID.

    LO_ITABNAME = 'LT_ALVTABLE'. "NB: ONLY USE CAPITALS HERE!

    • Fill the variables of the ALV-grid.

    PERFORM SET_LAYOUT USING LO_LAYOUT. "Change layout-settings

    PERFORM SET_EVENTS USING GT_XEVENTS."Set the events (top-page etc)

    PERFORM FILL_STRUCTURE. "Read the structure of the itab

    PERFORM MODIFY_STRUCTURE. "Modify itab's field-properties

    • Sort the table

    SORT LT_ALVTABLE BY KUNNR.

    • Present the table using the ALV-grid.

    CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'

    EXPORTING

    I_CALLBACK_PROGRAM = REPID

    IT_FIELDCAT = ZTA_PRINT[]

    IS_LAYOUT = LO_LAYOUT

    IT_EVENTS = GT_XEVENTS

    I_SAVE = 'A'

    IS_VARIANT = LS_VARIANT

    TABLES

    T_OUTTAB = LT_ALVTABLE.

    ENDFORM. " print_alvlist

    &----


    *& Form SET_LAYOUT

    &----


    FORM SET_LAYOUT USING PA_LAYOUT TYPE SLIS_LAYOUT_ALV.

    • Minimize the columnwidth

    PA_LAYOUT-COLWIDTH_OPTIMIZE = 'X'.

    • Give the table a striped pattern

    PA_LAYOUT-ZEBRA = 'X'.

    • Set the text of the line with totals

    PA_LAYOUT-TOTALS_TEXT = 'Total:'.

    • Set the text of the line with subtotals

    PA_LAYOUT-SUBTOTALS_TEXT = 'Subtotal:'.

    • Set the variant, as requested via the checkbox

    IF PA_VAR = 'X'.

    LS_VARIANT-VARIANT = '/ZLAYOUT'.

    ELSE.

    CLEAR LS_VARIANT-VARIANT.

    ENDIF.

    ENDFORM. " SET_LAYOUT

    *&----


    *& Form Set_events

    *&----


    • Appends the values of the events to the events-variable that is

    • used by REUSE_ALV_LIST_DISPLAY

    *&----


    FORM SET_EVENTS USING PA_EVENTS TYPE SLIS_T_EVENT.

    XS_EVENT-NAME = SLIS_EV_TOP_OF_LIST.

    XS_EVENT-FORM = 'XTOP_OF_LIST'.

    APPEND XS_EVENT TO PA_EVENTS.

    XS_EVENT-NAME = SLIS_EV_END_OF_LIST.

    XS_EVENT-FORM = 'XEND_OF_LIST'.

    APPEND XS_EVENT TO PA_EVENTS.

    XS_EVENT-NAME = SLIS_EV_TOP_OF_PAGE.

    XS_EVENT-FORM = 'XTOP_OF_PAGE'.

    APPEND XS_EVENT TO PA_EVENTS.

    XS_EVENT-NAME = SLIS_EV_END_OF_PAGE.

    XS_EVENT-FORM = 'XEND_OF_PAGE'.

    APPEND XS_EVENT TO PA_EVENTS.

    ENDFORM.

    &----


    *& Form XTOP_OF_LIST

    &----


    FORM XTOP_OF_LIST.

    DATA LO_DATE(8).

    CONCATENATE SY-DATUM+6(2) '.'

    SY-DATUM+4(2) '.'

    SY-DATUM+2(2)

    INTO LO_DATE.

    WRITE: AT 1 'Report:'(T01), 20 'Reportname'(T02).

    WRITE: AT 50 'Date:'(T03), LO_DATE.

    NEW-LINE.

    WRITE: AT 1 'Abap-name report: '(T04), SY-REPID.

    WRITE: AT 50 'Page:'(T05), SY-CPAGE.

    ENDFORM. "xtop_of_list

    &----


    *& Form XEND_OF_LIST

    &----


    FORM XEND_OF_LIST.

    WRITE: 'Footer of the list'(002).

    ENDFORM. "xend_of_list

    &----


    *& Form XTOP_OF_PAGE

    &----


    FORM XTOP_OF_PAGE.

    WRITE:/ 'Top of the page.'(003).

    ()Here your selection-criteria can be printed

    ENDFORM. "xtop-of-page

    &----


    *& Form XEND_OF_PAGE

    &----


    FORM XEND_OF_PAGE.

    WRITE:/ 'End of the page.'(004).

    ENDFORM. "xtop-of-page

    &----


    *& Form FILL_STRUCTURE

    &----


    FORM FILL_STRUCTURE.

    CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'

    EXPORTING

    I_PROGRAM_NAME = REPID

    I_INTERNAL_TABNAME = LO_ITABNAME

    I_INCLNAME = 'ZALV_SAMPLE'

    CHANGING

    CT_FIELDCAT = ZTA_PRINT[].

    ENDFORM. " FILL_STRUCTURE

    &----


    *& Form MODIFY_STRUCTURE

    &----


    • Set the fieldproperties to your wishes

    &----


    FORM MODIFY_STRUCTURE.

    LOOP AT ZTA_PRINT.

    CLEAR ZTA_PRINT-KEY.

    CASE ZTA_PRINT-FIELDNAME.

    WHEN 'KUNNR'. "Klantnummer

    ZTA_PRINT-COL_POS = 0.

    ZTA_PRINT-SELTEXT_S = 'Cstm'(H01).

    ZTA_PRINT-SELTEXT_M = 'Customer'(H01).

    ZTA_PRINT-SELTEXT_L = 'Customer is king'(H01).

    WHEN 'NAME1'. "Name1

    ZTA_PRINT-COL_POS = 1.

    WHEN 'NAME2'. "Name 2 (now set to invisible)

    ZTA_PRINT-COL_POS = 2.

    ZTA_PRINT-NO_OUT = 'X'.

    WHEN 'STRAS'. "Month

    ZTA_PRINT-COL_POS = 3.

    WHEN 'PSTLZ'. "Postcode

    ZTA_PRINT-COL_POS = 4.

    IF PA_PSTCD = ''.

    ZTA_PRINT-NO_OUT = 'X'.

    ELSE.

    CLEAR ZTA_PRINT-NO_OUT.

    ENDIF.

    WHEN 'ORT01'. "Stad

    ZTA_PRINT-COL_POS = 5.

    WHEN 'UMSA1'. "Annual sales

    ZTA_PRINT-COL_POS = 6.

    WHEN 'KTOKD'. "

    ZTA_PRINT-COL_POS = 7.

    • when others. "set all other fields to invisible

    • zta_print-no_out = 'X'.

    ENDCASE.

    MODIFY ZTA_PRINT.

    ENDLOOP.

    ENDFORM. " modify_structure

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member

      hi

      Not printing

      This is my code.

      ======================================================================

      *C L A S S - A L V

      ======================================================================

      *class for event handling

      class lcl_event_receiver definition.

      public section.

      • § 2. Define a method for each print event you need.

      methods:

      handle_top_of_page

      for event print_top_of_page of cl_gui_alv_grid,

      handle_top_of_list

      for event print_top_of_list of cl_gui_alv_grid.

      private section.

      data: pagenum type i.

      endclass.

      ****************************************************************

      • LOCAL CLASSES: Implementation

      ****************************************************************

      • class c_event_receiver (Implementation)

      *

      class lcl_event_receiver implementation.

      *Implement your event handler methods.

      method handle_top_of_page.

      perform write_heading.

      endmethod. "handle_top_of_page

      *----

      -


      method handle_top_of_list.

      perform write_heading .

      endmethod. "handle_top_of_list

      endclass.

      ======================================================================

      *A L V G R I D

      ======================================================================

      *--- ALV Grid instance reference

      DATA cc_alvgrid TYPE REF TO cl_gui_alv_grid .

      *--- Name of the custom control added on the screen

      DATA ws_custom_control_name TYPE scrfname VALUE 'CC_ALV' .

      *--- Custom container instance reference

      DATA cc_ccontainer TYPE REF TO cl_gui_custom_container .

      *--- Field catalog table

      DATA int_fieldcat TYPE lvc_t_fcat.

      *--- Layout structure

      DATA: ws_layout TYPE lvc_s_layo ,

      it_sort type LVC_T_SORT.

      DATA: OK_CODE LIKE SY-UCOMM.

      Data:event_receiver type ref to lcl_event_receiver.

      form WRITE_HEADING .

      *--> Vendor Number

      SKIP 1.

      IF s_lifnr IS INITIAL.

      WRITE:/1 'Vendor : ALL'.

      ELSE.

      LOOP AT s_lifnr .

      WRITE:/1 'Vendor:',

      s_lifnr-SIGN,

      s_lifnr-OPTION,

      s_lifnr-LOW,

      '-',

      s_lifnr-HIGH.

      ENDLOOP.

      ENDIF.

      *--> Scheduling Agreement No

      SKIP 1.

      IF s_ebeln IS INITIAL.

      WRITE:/1 'Scheduling Agreement No : ALL'.

      ELSE.

      LOOP AT s_ebeln.

      WRITE:/1 'Scheduling Agreement No:',

      s_ebeln-SIGN,

      s_ebeln-OPTION,

      s_ebeln-LOW,

      '-',

      s_ebeln-HIGH.

      ENDLOOP.

      ENDIF.

      *--> Change Date From

      SKIP 1.

      IF s_kdatb IS INITIAL.

      WRITE:/1 'Change Date From : ALL'.

      ELSE.

      LOOP AT s_kdatb.

      WRITE:/1 'Change Date From:',

      s_kdatb-SIGN,

      s_kdatb-OPTION,

      s_kdatb-LOW,

      '-',

      s_kdatb-HIGH.

      ENDLOOP.

      ENDIF.

      *--> Change Date to

      SKIP 1.

      IF s_kdate IS INITIAL.

      WRITE:/1 ' Change Date to : ALL'.

      ELSE.

      LOOP AT s_ebeln.

      WRITE:/1 'Scheduling Agreement No:',

      s_kdate-SIGN,

      s_kdate-OPTION,

      s_kdate-LOW,

      '-',

      s_kdate-HIGH.

      ENDLOOP.

      ENDIF.

      endform. " WRITE_HEADING

      *&----


      *

      *& Form CREATE_ALV_OBJECT

      *&----


      *

      • text

      *----


      *

      • --> p1 text

      • <-- p2 text

      *----


      *

      FORM create_alv_object .

      IF cc_alvgrid IS INITIAL .

      • ----Creating custom container instance

      CREATE OBJECT cc_ccontainer

      EXPORTING

      container_name = ws_custom_control_name

      EXCEPTIONS

      cntl_error = 1

      cntl_system_error = 2

      create_error = 3

      lifetime_error = 4

      lifetime_dynpro_dynpro_link = 5

      OTHERS = 6 .

      IF sy-subrc <> 0.

      • --Exception handling

      ENDIF.

      • ----Creating ALV Grid instance

      CREATE OBJECT cc_alvgrid

      EXPORTING

      i_parent = cc_ccontainer

      EXCEPTIONS

      error_cntl_create = 1

      error_cntl_init = 2

      error_cntl_link = 3

      error_dp_create = 4

      OTHERS = 5 .

      IF sy-subrc <> 0.

      • --Exception handling

      ENDIF.

      ENDIF.

      ENDFORM. " CREATE_ALV_OBJECT

      *-Build field catalog

      PERFORM build_fieldcatalog.

      FORM build_layout .

      CLEAR ws_layout.

      • REFRESH I_SLIS_SORT.

      *-Set ALV Layout For List

      ws_layout-zebra = c_x.

      ws_layout-grid_title = 'Scheduling Agreement Changes'.

      ws_layout-CWIDTH_OPT = 'X'.

      **Setting The Sort Criteria

      • LS_SLIS_SORT-FIELDNAME = C_KUNR.

      • LS_SLIS_SORT-TABNAME = C_I_OUTAB_HDR.

      • LS_SLIS_SORT-SPOS = C_1.

      • LS_SLIS_SORT-UP = C_X.

      • APPEND LS_SLIS_SORT TO I_SLIS_SORT.

      *

      • LS_SLIS_SORT-FIELDNAME = C_WERKS.

      • LS_SLIS_SORT-TABNAME = C_I_OUTAB_HDR.

      • LS_SLIS_SORT-SPOS = 2.

      • LS_SLIS_SORT-UP = C_X.

      • APPEND LS_SLIS_SORT TO I_SLIS_SORT.

      *

      • LS_SLIS_SORT-FIELDNAME = C_VBELN.

      • LS_SLIS_SORT-TABNAME = C_I_OUTAB_HDR.

      • LS_SLIS_SORT-SPOS = 3.

      • LS_SLIS_SORT-SUBTOT = C_X.

      • LS_SLIS_SORT-UP = C_X.

      • APPEND LS_SLIS_SORT TO I_SLIS_SORT.

      • § 4. Link used print events and event handler methods.

      create object event_receiver.

      set handler event_receiver->handle_top_of_page for cc_alvgrid.

      create object event_receiver.

      set handler event_receiver->handle_top_of_list for cc_alvgrid.

      ENDFORM. " BUILD_LAYOUT

      *-Build Final Table

      PERFORM build_final_table.

      FORM display_data .

      CALL METHOD cc_alvgrid->set_table_for_first_display

      EXPORTING

      • I_BUFFER_ACTIVE =

      • I_CONSISTENCY_CHECK =

      • I_STRUCTURE_NAME =

      • IS_VARIANT =

      • I_SAVE =

      • I_DEFAULT = 'X'

      is_layout = ws_layout

      • IS_PRINT =

      • IT_SPECIAL_GROUPS =

      • IT_TOOLBAR_EXCLUDING =

      • IT_HYPERLINK =

      CHANGING

      it_outtab = it_final_list[]

      it_fieldcatalog = int_fieldcat

      • IT_SORT =

      • IT_FILTER =

      EXCEPTIONS

      invalid_parameter_combination = 1

      program_error = 2

      too_many_lines = 3

      OTHERS = 4 .

      ENDFORM. " DISP

  • avatar image
    Former Member
    May 21, 2009 at 10:56 AM

    Hi,

    To print the top-of page

    1. First define lass that contains to-of-page event.

    2.Then Divide contanier in two parts one for heading & other for ALV list.

    3.Then call methods to add ur text.

    For Example:

    CLASS lcl_event_handler DEFINITION .
      PUBLIC SECTION .
    
        METHODS:
           top_of_page FOR EVENT top_of_page OF cl_gui_alv_grid
                       IMPORTING e_dyndoc_id,
    
           double_click FOR EVENT double_click of cl_salv_events_table
                        IMPORTING row column.
    
    
    
    ENDCLASS. 
    
    DATA: dg_dyndoc_id  TYPE REF TO cl_dd_document, " Reference to document
          dg_splitter  TYPE REF TO cl_gui_splitter_container." Reference to split container
    
    *splitter that splits contanier in 2 parts
      CREATE OBJECT dg_splitter
        EXPORTING
          parent  = w_container
          rows    = 2
          columns = 1.
    
    *for header
      CALL METHOD dg_splitter->get_container
        EXPORTING
          row       = 1
          column    = 1
        RECEIVING
          container = w_cont_top.
    
    *list
      CALL METHOD dg_splitter->get_container
        EXPORTING
          row       = 2
          column    = 1
        RECEIVING
          container = w_cont_grid.
    
    * Set height for g_parent_html
      CALL METHOD dg_splitter->set_row_height
        EXPORTING
          id     = 1
          height = 20.
    
    
    *crate object for grid
      CREATE OBJECT w_grid
        EXPORTING
    *       i_shellstyle      = 0
    *       i_lifetime        =
           i_parent          = w_cont_grid
    *       i_appl_events     = space
    *       i_parentdbg       =
    *       i_applogparent    =
    *       i_graphicsparent  =
    *       i_name            =
    *       i_fcat_complete   = space
        EXCEPTIONS
          error_cntl_create = 1
          error_cntl_init   = 2
          error_cntl_link   = 3
          error_dp_create   = 4
          OTHERS            = 5
          .
      IF sy-subrc <> 0.
        MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
                   WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
      ENDIF.
    
      
    * setting focus for created grid control
      CALL METHOD cl_gui_control=>set_focus
        EXPORTING
          control = w_grid.
    
    
    **handler
      CREATE OBJECT w_handler.
    
      SET HANDLER w_handler->top_of_page FOR w_grid.
    
      w_grid->set_table_for_first_display(
     EXPORTING
    *    i_buffer_active               =
    *    i_bypassing_buffer            =
    *    i_consistency_check           =
    *     i_structure_name              =
         is_variant                    = w_variant
         i_save                        = 'A'
    *    i_default                     = 'X'
         is_layout                     = is_layout
    *    is_print                      =
    *    it_special_groups             =
    *    it_toolbar_excluding          =
    *    it_hyperlink                  =
    *    it_alv_graphics               =
    *    it_except_qinfo               =
    *    ir_salv_adapter               =
      CHANGING
        it_outtab                     =  it_output
        it_fieldcatalog               =  it_fieldcat
    *    it_sort                       =
    *    it_filter                     =
      EXCEPTIONS
        invalid_parameter_combination = 1
        program_error                 = 2
        too_many_lines                = 3
        OTHERS                        = 4
           ).
      IF sy-subrc <> 0.
        MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
                   WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
      ENDIF.
    
    * Initializing document
      CALL METHOD dg_dyndoc_id->initialize_document.
    
    * Processing events
      CALL METHOD w_grid->list_processing_events
        EXPORTING
          i_event_name = 'TOP_OF_PAGE'
          i_dyndoc_id  = dg_dyndoc_id.
    
    *&---------------------------------------------------------------------*
    *&      Form  EVENT_TOP_OF_PAGE
    *&---------------------------------------------------------------------*
    *       text
    *----------------------------------------------------------------------*
    *      -->P_DG_DYNDOC_ID  text
    *----------------------------------------------------------------------*
    FORM event_top_of_page USING dg_dyndoc_id TYPE REF TO cl_dd_document.
    
      DATA:w_length(255) TYPE c,
           w_leng TYPE i.
    
    *
    *  CALL METHOD dg_dyndoc_id->add_gap
    *    EXPORTING
    *      width = '116'.
    * Populating header to top-of-page
      CALL METHOD dg_dyndoc_id->add_text
        EXPORTING
          text      = 'ZLGC Details'
          sap_style = cl_dd_area=>heading.
    
    * Add new-line
      CALL METHOD dg_dyndoc_id->new_line.
    
    
      CLEAR w_length.
    
    *move plant name
      CONCATENATE 'Plant Name:' w_werks INTO w_length SEPARATED BY space.
    * Add new-line
      CALL METHOD dg_dyndoc_id->new_line.
    *
    *  CALL METHOD dg_dyndoc_id->add_gap
    *    EXPORTING
    *      width = '120'.
      PERFORM add_text USING w_length.
    
      CLEAR w_length.
    *move division name
      CONCATENATE 'Division Name:' w_spart INTO w_length SEPARATED BY space.
    * Add new-line
      CALL METHOD dg_dyndoc_id->new_line.
    *  CALL METHOD dg_dyndoc_id->add_gap
    *    EXPORTING
    *      width = '120'.
    
      PERFORM add_text USING w_length.
    
      CLEAR w_length.
    
    * Reuse_alv_grid_commentary_set
      CALL FUNCTION 'REUSE_ALV_GRID_COMMENTARY_SET'
        EXPORTING
          document = dg_dyndoc_id
          bottom   = space
        IMPORTING
          length   = w_leng.
    
    * Display TOP document
      CALL METHOD dg_dyndoc_id->display_document
        EXPORTING
          reuse_control      = 'X'
          parent             = w_cont_top
        EXCEPTIONS
          html_display_error = 1.
      IF sy-subrc NE 0.
    *    MESSAGE i999 WITH 'Error in displaying top-of-page'(036).
      ENDIF.
    
    ENDFORM.                    " EVENT_TOP_OF_PAGE
    
    *&---------------------------------------------------------------------*
    *&      Form  ADD_TEXT
    *&---------------------------------------------------------------------*
    *       text
    *----------------------------------------------------------------------*
    *      -->P_W_LENGTH  text
    *----------------------------------------------------------------------*
    FORM add_text  USING w_length TYPE sdydo_text_element.
    
    * Adding text
      CALL METHOD dg_dyndoc_id->add_text
        EXPORTING
          text         = w_length
          sap_emphasis = cl_dd_area=>heading.
    
    ENDFORM.                    " ADD_TEXT
    *&---------------------------------------------------------------------*
    
    
      CALL SCREEN 200.

    Also u can get this type of ode on Wiki & BLOG.

    Thanks & Regards,

    Anagha Deshmukh

    Add comment
    10|10000 characters needed characters exceeded