Create Multiple Lines Header in ALV List Report
Create Multiple Lines Header in ALV List Report
A standard SAP ALV list report will show only one line header, but there will be a
requirement someday for you to create a multiple lines header in your ALV list report and in
order to do this, you must first set the no_colhead property to “X” in the ALV Layout, this
code is to exclude the standard ALV columns and after that we replace the columns text by
using WRITE command at the top of page event.
Okay now let’s create a small ALV report that will display multiple lines header.
*&---------------------------------------------------------------------*
*& Report ZMULTIPLEHEADER
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT ZMULTIPLEHEADER.
TYPE-POOLS: slis, icon.
data:
BEGIN OF itab OCCURS 0,
carrid like sflight-carrid,
connid like sflight-connid,
planetype like sflight-planetype,
seatsmax like sflight-seatsmax,
END OF itab.
START-OF-SELECTION.
CLEAR: ld_fieldcat.
ld_fieldcat-tabname = 'ITAB'.
ld_fieldcat-fieldname = 'CARRID'.
ld_fieldcat-ref_tabname = 'SFLIGHT'.
ld_fieldcat-outputlen = '10'.
APPEND ld_fieldcat TO t_alv_fieldcat.
CLEAR ld_fieldcat.
CLEAR: ld_fieldcat.
ld_fieldcat-tabname = 'ITAB'.
ld_fieldcat-fieldname = 'CONNID'.
ld_fieldcat-ref_tabname = 'SFLIGHT'.
ld_fieldcat-outputlen = '10'.
APPEND ld_fieldcat TO t_alv_fieldcat.
CLEAR ld_fieldcat.
CLEAR: ld_fieldcat.
ld_fieldcat-tabname = 'ITAB'.
ld_fieldcat-fieldname = 'PLANETYPE'.
ld_fieldcat-ref_tabname = 'SFLIGHT'.
ld_fieldcat-outputlen = '10'.
APPEND ld_fieldcat TO t_alv_fieldcat.
CLEAR ld_fieldcat.
CLEAR: ld_fieldcat.
ld_fieldcat-tabname = 'ITAB'.
ld_fieldcat-fieldname = 'SEATSMAX'.
ld_fieldcat-ref_tabname = 'SFLIGHT'.
ld_fieldcat-outputlen = '10'.
APPEND ld_fieldcat TO t_alv_fieldcat.
CLEAR ld_fieldcat.
ALV_LAYOUT-no_colhead = 'X' .
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 .
ULINE AT 1(45) .
FORMAT COLOR 7 .
"This is where we manually create the header text,
"in this example I'm using 2 lines header, if you
"want to have 3 lines header or more, you can just
"add new write command.
ENDFORM.