Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Alv grid header

Former Member
0 Likes
570

Hi,

I want to display my alv grid output as follows.

¦ Name ¦

Field1 ¦ Firstname ¦ Last name ¦ Field5 ¦

Please let me know how to display the grid header like this.

Thanks a lot.

Regards,

Priti

3 REPLIES 3
Read only

Former Member
0 Likes
535

Hi,

Thread: how to add the double headings in Alv Report.

Regards

Debarshi

Read only

Former Member
0 Likes
535

hi,

if you are using the approach of calling FM, check the code below:


TYPE-POOLS: slis.
TABLES trdir.

* Display data
DATA: BEGIN OF it_data OCCURS 0,
        name    LIKE trdir-name,
        clas    LIKE trdir-clas,
        subc    LIKE trdir-subc,
        cnam    LIKE trdir-cnam,
        cdat    LIKE trdir-cdat,
        myfield(1) TYPE c,
      END OF it_data.

DATA wa_data LIKE LINE OF it_data.

DATA: it_fieldcat_alv TYPE slis_t_fieldcat_alv,
      wa_fieldcat_alv TYPE LINE OF slis_t_fieldcat_alv.

DATA: g_repid LIKE sy-repid VALUE sy-repid.


DATA s_name TYPE RANGE OF trdir-name WITH HEADER LINE.

INITIALIZATION.
  s_name-sign = 'I'.
  s_name-option = 'CP'.
  s_name-low = 'Z*'.
  APPEND s_name.


START-OF-SELECTION.

  PERFORM f_get_data.

END-OF-SELECTION.

  PERFORM f_alv_fields.

  PERFORM f_display_alv.

*&---------------------------------------------------------------------*
*&      Form  F_GET_DATA
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM f_get_data .

*  DATA wa_data TYPE ty_data.

  SELECT name
         clas
         subc
         cnam
         cdat
    UP TO 15 ROWS
    INTO TABLE it_data
    FROM trdir
   WHERE name IN s_name.

ENDFORM.                    " F_GET_DATA
*&---------------------------------------------------------------------*
*&      Form  f_display_alv
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM f_display_alv .
  DATA gd_repid       LIKE sy-repid.
  gd_repid = sy-repid.

  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
     EXPORTING
*   I_INTERFACE_CHECK                 = ' '
*   I_BYPASSING_BUFFER                = ' '
*   I_BUFFER_ACTIVE                   = ' '
    i_callback_program                = gd_repid
*   I_CALLBACK_PF_STATUS_SET          = ' '
    i_callback_user_command           = 'F_USER_COMMAND'
    i_callback_top_of_page            = 'F_TOP_OF_PAGE'
*   I_CALLBACK_HTML_TOP_OF_PAGE       = ' '
*   I_CALLBACK_HTML_END_OF_LIST       = ' '
*   I_STRUCTURE_NAME                  = ' '
*   I_BACKGROUND_ID                   = ' '
*   I_GRID_TITLE                      =
*   I_GRID_SETTINGS                   =
*   IS_LAYOUT                         =
    it_fieldcat                       = it_fieldcat_alv
*   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        =
* IMPORTING
*   E_EXIT_CAUSED_BY_CALLER           =
*   ES_EXIT_CAUSED_BY_USER            =
     TABLES
       t_outtab                          = it_data
     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.                    " f_display_alv
*&---------------------------------------------------------------------*
*&      Form  f_alv_fields
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM f_alv_fields .


* First Column
  wa_fieldcat_alv-col_pos = '1'.
  wa_fieldcat_alv-fieldname = 'NAME'.
  wa_fieldcat_alv-key = 'X'.
  wa_fieldcat_alv-ref_fieldname  = 'NAME'.
  wa_fieldcat_alv-ref_tabname = 'TRDIR'.
  APPEND wa_fieldcat_alv TO it_fieldcat_alv.

* Second Column
  CLEAR wa_fieldcat_alv.
  wa_fieldcat_alv-col_pos = '2'.
  wa_fieldcat_alv-fieldname = 'SUBC'.
  wa_fieldcat_alv-just = 'R'.
  wa_fieldcat_alv-key = 'X'.
  wa_fieldcat_alv-ref_fieldname  = 'SUBC'.
  wa_fieldcat_alv-ref_tabname = 'TRDIR'.
  APPEND wa_fieldcat_alv TO it_fieldcat_alv.

* Third Column
  CLEAR wa_fieldcat_alv.
  wa_fieldcat_alv-col_pos = '3'.
  wa_fieldcat_alv-fieldname = 'CLAS'.
  wa_fieldcat_alv-fix_column = 'X'.
  wa_fieldcat_alv-ref_fieldname  = 'CLAS'.
  wa_fieldcat_alv-ref_tabname = 'TRDIR'.
  APPEND wa_fieldcat_alv TO it_fieldcat_alv.

* Fourth Column
  CLEAR wa_fieldcat_alv.
  wa_fieldcat_alv-col_pos = '4'.
  wa_fieldcat_alv-fieldname = 'CNAM'.
  wa_fieldcat_alv-ref_fieldname  = 'CNAM'.
  wa_fieldcat_alv-ref_tabname = 'TRDIR'.
  APPEND wa_fieldcat_alv TO it_fieldcat_alv.

* Fifth Column
  CLEAR wa_fieldcat_alv.
  wa_fieldcat_alv-col_pos = '5'.
  wa_fieldcat_alv-fieldname = 'CDAT'.
  wa_fieldcat_alv-emphasize = 'C101'.
  wa_fieldcat_alv-ref_fieldname  = 'CDAT'.
  wa_fieldcat_alv-ref_tabname = 'TRDIR'.
  APPEND wa_fieldcat_alv TO it_fieldcat_alv.

** Sixth Column
*  CLEAR wa_fieldcat_alv.
*  wa_fieldcat_alv-col_pos = '6'.
*  wa_fieldcat_alv-fieldname = 'MYFIELD'.
*  wa_fieldcat_alv-reptext_ddic = 'Self-defined Name'.
*  APPEND wa_fieldcat_alv TO it_fieldcat_alv.
*
ENDFORM.                    " f_alv_fields

*&---------------------------------------------------------------------*
*&      Form  f_user_command
*&---------------------------------------------------------------------*
*       ALV¿Ø¼þµÄGUI
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM f_user_command  USING r_ucomm LIKE sy-ucomm
                           rs_selfield TYPE slis_selfield.

  CASE r_ucomm.
    WHEN '&IC1'.
      MESSAGE i001(zalv_demo) WITH rs_selfield-value.
    WHEN OTHERS.
  ENDCASE.

ENDFORM.                    "callback_ucomm

*&---------------------------------------------------------------------*
*&      Form  F_TOP_OF_PAGE
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM f_top_of_page.

  DATA: it_list_commentary TYPE slis_t_listheader,
        wa_list_commentary TYPE slis_listheader.

  wa_list_commentary-typ = 'H'.
  wa_list_commentary-info = 'Program name list'.
  APPEND wa_list_commentary TO it_list_commentary.
  CLEAR wa_list_commentary.

  wa_list_commentary-typ = 'S'.
  wa_list_commentary-key = ''.
  wa_list_commentary-info = 'Double clik will show a message'.
  APPEND wa_list_commentary TO it_list_commentary.
  CLEAR wa_list_commentary.

  CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
    EXPORTING
      it_list_commentary = it_list_commentary.

ENDFORM.                    "F_TOP_OF_PAGE


Read only

Former Member
0 Likes
535

hi,

if your using the approach of OO

check the link:

after you finish it , your will get an idea.