Skip to Content
avatar image
Former Member

Adding header to alv(factory) in container

Hi frends!

How can I add a header to alv in container using factory method?

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

5 Answers

  • Best Answer
    avatar image
    Former Member
    Jun 16, 2010 at 09:58 AM

    Calling the top of page method CALL METHOD me->set_top_of_page CHANGING co_alv = o_alv.

    METHOD set_top_of_page.*

    DATA: lo_header TYPE REF TO cl_salv_form_layout_grid,

    lo_h_label TYPE REF TO cl_salv_form_label

    , lo_h_flow TYPE REF TO cl_salv_form_layout_flow.

    • header object CREATE OBJECT lo_header.

    lo_h_label = lo_header->create_label( row = 1 column = 1 ).

    lo_h_label->set_text( 'Header in Bold' ).

    ENDMETHOD. "set_top_of_page

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Jun 16, 2010 at 07:40 AM

    No any suggestions?

    😔

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member Former Member

      You can use splitter. For example :

      REPORT ZCE_TEST2.

      DATA: IT_FLIGHT TYPE TABLE OF SFLIGHT.

      DATA: OK_CODE LIKE SY-UCOMM,

      SAVE_OK LIKE SY-UCOMM.

      DATA: G_CONTAINER TYPE SCRFNAME VALUE 'CONTROL',

      O_DYNDOC_ID TYPE REF TO CL_DD_DOCUMENT,

      O_SPLITTER TYPE REF TO CL_GUI_SPLITTER_CONTAINER,

      O_PARENT_GRID TYPE REF TO CL_GUI_CONTAINER,

      O_PARENT_TOP TYPE REF TO CL_GUI_CONTAINER,

      O_HTML_CNTRL TYPE REF TO CL_GUI_HTML_VIEWER.

      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.

      ENDCLASS. "lcl_event_handler DEFINITION

      CLASS LCL_EVENT_HANDLER IMPLEMENTATION.

      METHOD TOP_OF_PAGE.

      PERFORM EVENT_TOP_OF_PAGE USING O_DYNDOC_ID.

      ENDMETHOD. "top_of_page

      ENDCLASS. "LCL_EVENT_HANDLER IMPLEMENTATION

      DATA: G_CUSTOM_CONTAINER TYPE REF TO CL_GUI_CUSTOM_CONTAINER,

      G_HANDLER TYPE REF TO LCL_EVENT_HANDLER. "handler

      START-OF-SELECTION.

      SELECT *

      FROM SFLIGHT

      UP TO 20 ROWS

      INTO TABLE IT_FLIGHT.

      END-OF-SELECTION.

      IF NOT IT_FLIGHT[] IS INITIAL.

      CALL SCREEN 100.

      ELSE.

      MESSAGE 'NO DATA FOR THE SELECTION' TYPE 'I'.

      ENDIF.

      MODULE STATUS_0100 OUTPUT.

      SET PF-STATUS 'STATUS'.

      SET TITLEBAR 'TITLE'.

      IF G_CUSTOM_CONTAINER IS INITIAL.

      PERFORM CREATE_AND_INIT_ALV.

      ENDIF.

      ENDMODULE. " STATUS_0100 OUTPUT

      MODULE USER_COMMAND_0100 INPUT.

      CASE SY-UCOMM.

      WHEN 'BACK'.

      LEAVE TO SCREEN 0.

      ENDCASE.

      ENDMODULE. " USER_COMMAND_0100 INPUT

      FORM CREATE_AND_INIT_ALV .

      DATA: G_GRID TYPE REF TO CL_GUI_ALV_GRID.

      CREATE OBJECT G_CUSTOM_CONTAINER

      EXPORTING CONTAINER_NAME = G_CONTAINER.

      • Create TOP-Document

      CREATE OBJECT O_DYNDOC_ID

      EXPORTING STYLE = 'ALV_GRID'.

      • Create Splitter for custom_container

      CREATE OBJECT O_SPLITTER

      EXPORTING PARENT = G_CUSTOM_CONTAINER

      ROWS = 2

      COLUMNS = 1.

      CALL METHOD O_SPLITTER->GET_CONTAINER

      EXPORTING

      ROW = 1

      COLUMN = 1

      RECEIVING

      CONTAINER = O_PARENT_TOP.

      CALL METHOD O_SPLITTER->GET_CONTAINER

      EXPORTING

      ROW = 2

      COLUMN = 1

      RECEIVING

      CONTAINER = O_PARENT_GRID.

      • Set height for g_parent_html

      CALL METHOD O_SPLITTER->SET_ROW_HEIGHT

      EXPORTING

      ID = 1

      HEIGHT = 5.

      CREATE OBJECT G_GRID

      EXPORTING I_PARENT = O_PARENT_GRID.

      CREATE OBJECT G_HANDLER.

      SET HANDLER G_HANDLER->TOP_OF_PAGE FOR G_GRID.

      *Calling the Method for ALV output

      CALL METHOD G_GRID->SET_TABLE_FOR_FIRST_DISPLAY

      EXPORTING

      I_STRUCTURE_NAME = 'SFLIGHT'

      CHANGING

      IT_OUTTAB = IT_FLIGHT[].

      CALL METHOD O_DYNDOC_ID->INITIALIZE_DOCUMENT

      EXPORTING

      BACKGROUND_COLOR = CL_DD_AREA=>COL_TEXTAREA.

      • Processing events

      CALL METHOD G_GRID->LIST_PROCESSING_EVENTS

      EXPORTING

      I_EVENT_NAME = 'TOP_OF_PAGE'

      I_DYNDOC_ID = O_DYNDOC_ID.

      ENDFORM. "CREATE_AND_INIT_ALV

      FORM EVENT_TOP_OF_PAGE USING DG_DYNDOC_ID TYPE REF TO CL_DD_DOCUMENT.

      DATA : DL_TEXT(255) TYPE C. "Text

      CALL METHOD DG_DYNDOC_ID->ADD_TEXT

      EXPORTING

      TEXT = 'Flight Details'

      SAP_STYLE = CL_DD_AREA=>HEADING

      SAP_FONTSIZE = CL_DD_AREA=>LARGE

      SAP_COLOR = CL_DD_AREA=>LIST_HEADING_INT.

      CALL METHOD DG_DYNDOC_ID->ADD_GAP

      EXPORTING

      WIDTH = 200.

      CALL METHOD O_DYNDOC_ID->ADD_PICTURE

      EXPORTING

      PICTURE_ID = 'ENJOYSAP_LOGO'.

      • Add new-line

      CALL METHOD DG_DYNDOC_ID->NEW_LINE.

      CALL METHOD DG_DYNDOC_ID->NEW_LINE.

      CLEAR : DL_TEXT.

      • program ID

      DL_TEXT = 'Program Name :'.

      CALL METHOD DG_DYNDOC_ID->ADD_GAP.

      CALL METHOD O_DYNDOC_ID->ADD_TEXT

      EXPORTING

      TEXT = DL_TEXT

      SAP_EMPHASIS = CL_DD_AREA=>HEADING

      SAP_COLOR = CL_DD_AREA=>LIST_HEADING_INT.

      CLEAR DL_TEXT.

      DL_TEXT = SY-REPID.

      CALL METHOD O_DYNDOC_ID->ADD_TEXT

      EXPORTING

      TEXT = DL_TEXT

      SAP_EMPHASIS = CL_DD_AREA=>HEADING

      SAP_COLOR = CL_DD_AREA=>LIST_NEGATIVE_INV.

      • Add new-line

      CALL METHOD DG_DYNDOC_ID->NEW_LINE.

      CLEAR : DL_TEXT.

      CLEAR : DL_TEXT.

      • program ID

      DL_TEXT = 'User Name :'.

      CALL METHOD DG_DYNDOC_ID->ADD_GAP.

      CALL METHOD O_DYNDOC_ID->ADD_TEXT

      EXPORTING

      TEXT = DL_TEXT

      SAP_EMPHASIS = CL_DD_AREA=>HEADING

      SAP_COLOR = CL_DD_AREA=>LIST_HEADING_INT.

      CLEAR DL_TEXT.

      DL_TEXT = SY-UNAME.

      CALL METHOD O_DYNDOC_ID->ADD_TEXT

      EXPORTING

      TEXT = DL_TEXT

      SAP_EMPHASIS = CL_DD_AREA=>HEADING

      SAP_COLOR = CL_DD_AREA=>LIST_NEGATIVE_INV.

      • Add new-line

      CALL METHOD DG_DYNDOC_ID->NEW_LINE.

      CLEAR : DL_TEXT.

      • Run Date

      DL_TEXT = 'Run Date :'.

      CALL METHOD DG_DYNDOC_ID->ADD_GAP.

      CALL METHOD O_DYNDOC_ID->ADD_TEXT

      EXPORTING

      TEXT = DL_TEXT

      SAP_EMPHASIS = CL_DD_AREA=>HEADING

      SAP_COLOR = CL_DD_AREA=>LIST_HEADING_INT.

      CLEAR DL_TEXT.

      • Move date

      WRITE SY-DATUM TO DL_TEXT.

      CALL METHOD O_DYNDOC_ID->ADD_TEXT

      EXPORTING

      TEXT = DL_TEXT

      SAP_EMPHASIS = CL_DD_AREA=>HEADING

      SAP_COLOR = CL_DD_AREA=>LIST_NEGATIVE_INV.

      • Add new-line

      CALL METHOD DG_DYNDOC_ID->NEW_LINE.

      CLEAR : DL_TEXT.

      *Time

      DL_TEXT = 'Time :'.

      CALL METHOD DG_DYNDOC_ID->ADD_GAP.

      CALL METHOD O_DYNDOC_ID->ADD_TEXT

      EXPORTING

      TEXT = DL_TEXT

      SAP_EMPHASIS = CL_DD_AREA=>HEADING

      SAP_COLOR = CL_DD_AREA=>LIST_HEADING_INT.

      CLEAR DL_TEXT.

      • Move time

      WRITE SY-UZEIT TO DL_TEXT.

      CALL METHOD O_DYNDOC_ID->ADD_TEXT

      EXPORTING

      TEXT = DL_TEXT

      SAP_EMPHASIS = CL_DD_AREA=>HEADING

      SAP_COLOR = CL_DD_AREA=>LIST_NEGATIVE_INV.

      • Add new-line

      CALL METHOD DG_DYNDOC_ID->NEW_LINE.

      PERFORM DISPLAY.

      ENDFORM. " EVENT_TOP_OF_PAGE

      FORM DISPLAY.

      • Creating html control

      IF O_HTML_CNTRL IS INITIAL.

      CREATE OBJECT O_HTML_CNTRL

      EXPORTING

      PARENT = O_PARENT_TOP.

      ENDIF.

      CALL METHOD O_DYNDOC_ID->MERGE_DOCUMENT.

      O_DYNDOC_ID->HTML_CONTROL = O_HTML_CNTRL.

      • Display document

      CALL METHOD O_DYNDOC_ID->DISPLAY_DOCUMENT

      EXPORTING

      REUSE_CONTROL = 'X'

      PARENT = O_PARENT_TOP

      EXCEPTIONS

      HTML_DISPLAY_ERROR = 1.

      IF SY-SUBRC NE 0.

      MESSAGE 'Error in displaying top-of-page' TYPE 'I'.

      ENDIF.

      ENDFORM. " display

  • avatar image
    Former Member
    Jun 16, 2010 at 11:03 AM

    Hi,

    Try the follwoing code

    data: gr_salv_table TYPE REF TO cl_salv_table,

    lv_header TYPE REF TO cl_salv_form_layout_grid,

    lv_h_label TYPE REF TO cl_salv_form_label.

    TRY.

    CALL METHOD cl_salv_table=>factory

    IMPORTING

    r_salv_table = gr_salv_table

    CHANGING

    t_table = it_output " o/p alv table

    CATCH cx_salv_msg INTO lr_msg .

    ENDTRY.

      • Set top of page

      CREATE OBJECT lv_header.

      lv_h_label = lv_header->create_label( row = 1 column = 1 ).

      lv_h_label->set_text( 'Flow Contacts SAP_SIEBEL' ).

      • set the top of list using the header for Online.

      gr_salv_table->set_top_of_list( lv_header ).

      • set the top of list using the header for Print.

      gr_salv_table->set_top_of_list_print( lv_header ).

      Add comment
      10|10000 characters needed characters exceeded

    • avatar image
      Former Member
      Jun 16, 2010 at 11:44 AM

      See SALV_DEMO_TABLE_LAYOUT program....that might be helpful to you...

      Add comment
      10|10000 characters needed characters exceeded

    • May 21, 2015 at 02:56 PM

      A correct example for Simple ALV can be found in report SALV_DEMO_TABLE_EVENTS.

      DATA: lo_display_settings TYPE REF TO cl_salv_display_settings

               , l_title TYPE lvc_title

               .

      l_title = 'some ALV header...'.

      lo_display_settings = gr_table->get_display_settings( ).

      lo_display_settings->set_list_header( l_title ).

      Add comment
      10|10000 characters needed characters exceeded