abap alv multiple header using write
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.
1. Execute TCODE SE38, and name the program Zmultipleheader
2. Copy and paste this code below.
*&---------------------------------------------------------------------*
*& Report
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT
TYPE-POOLS: slis, icon.
DATA: ld_fieldcat
DATA: t_alv_fieldcat
Alv_Layout TYPE SLIS_LAYOUT_ALV .
DATA : it_fld TYPE slis_t_fieldcat_alv ,
data:
START-OF-SELECTION.
"We are using table sflight to populate the internal
"table
SELECT carrid connid planetype seatsmax
CALL FUNCTION 'REUSE_ALV_EVENTS_GET'
"This is where we exclude the standard ALV columns
ALV_LAYOUT-no_colhead = 'X' .
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*
"Uline for creating a horizontal line
ULINE AT 1(45) .
"Format color for header background
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.
WRITE: / sy-vline , 02 'CARRID AND CONNID',
23 SY-VLINE, 25 'PLANE & SEATS MAX', 45 SY-VLINE.
WRITE: / sy-vline , 02 'CARRID' ,12 sy-vline, 14 'CONNID',
23 SY-VLINE, 25 'PLANE ', 34 SY-VLINE, 36 'SEATS MAX', 45 SY-VLINE.
ENDFORM.
3. Here’s the multiple header result.