Application Development 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: 

ABAP Multi heading in ALV GRID DISPLAY

0 Kudos

I am trying to display 2 row multi heading in an alv grid display where each main heading should occupy 2 sub-headings as follows:

REPORT  ZSAM8 message-id zz.
TYPE-POOLS: slis.  " SLIS contains all the ALV data
types: BEGIN OF ty_report,
          jan_deb TYPE UMXXS,
          jan_cred TYPE UMXXH,
          feb_deb TYPE UMXXS,
          feb_cred TYPE UMXXH,
        END OF ty_report,
        tt_report TYPE TABLE OF ty_report.
DATA: lt_report TYPE tt_report with header line,
      WA Type ty_report,
      LFC1_table TYPE standard table of LFC1,
      repid TYPE sy-repid,
      wa_deb Type SALDV,
      wa_cred TYPE SALDV,
      it_fieldcat TYPE slis_t_fieldcat_alv,
      wa_fieldcat TYPE slis_fieldcat_alv,
      x_events type slis_alv_event,
      it_events type SLIS_T_EVENT,
      L_LAYOUT type slis_layout_alv.
FIELD-SYMBOLS: <fs_rep> LIKE LINE OF lt_report,
               <fs_rep1> LIKE LINE OF LFC1_table.
select * from LFC1 into corresponding fields of table LFC1_table where bukrs = '1000' AND GJAHR  = 2003.
loop at LFC1_table assigning <fs_rep1>.
APPEND INITIAL LINE to lt_report ASSIGNING <fs_rep>.
if <fs_rep1>-UM01S > <fs_rep1>-UM01H.
<fs_rep>-jan_deb = <fs_rep1>-UM01S - <fs_rep1>-UM01H.
else.
<fs_rep>-jan_cred = <fs_rep1>-UM01H - <fs_rep1>-UM01S.
endif.
if <fs_rep1>-UM02S > <fs_rep1>-UM02H.
<fs_rep>-feb_deb = <fs_rep1>-UM02S - <fs_rep1>-UM02H.
else.
<fs_rep>-feb_cred = <fs_rep1>-UM02H - <fs_rep1>-UM02S.
endif.
endLOOP.
repid = sy-repid.
*Build field catalog
  wa_fieldcat-fieldname  = 'JAN_DEB'.    " Fieldname in the data table
  wa_fieldcat-seltext_l  = 'deb'.   " ColuAN_DEBmn description in the output
  wa_fieldcat-col_pos = 1.
  APPEND wa_fieldcat TO it_fieldcat.
  wa_fieldcat-fieldname  = 'JAN_CRED'.
  wa_fieldcat-seltext_l  = 'cred'.
  wa_fieldcat-col_pos = 1.
  APPEND wa_fieldcat TO it_fieldcat.
  wa_fieldcat-fieldname  = 'FEB_DEB'.    " Fieldname in the data table
  wa_fieldcat-seltext_l  = 'deb'.   " Column description in the output
  wa_fieldcat-col_pos = 2.
  APPEND wa_fieldcat TO it_fieldcat.
  wa_fieldcat-fieldname  = 'FEB_CRED'.
  wa_fieldcat-seltext_l  = 'cred'.
  wa_fieldcat-col_pos = 2.
  APPEND wa_fieldcat TO it_fieldcat.
call function 'REUSE_ALV_GRID_DISPLAY'
   exporting
      i_callback_program      = repid
      i_callback_user_command = 'HANDLE_USER_COMMAND'
      i_callback_html_top_of_page = 'HTML_TOP_OF_PAGE'
      it_fieldcat             = it_fieldcat
  tables
      t_outtab                = lt_report
  EXCEPTIONS
      program_error = 1
      OTHERS        = 2.
FORM HTML_TOP_OF_PAGE USING LW_DOCUMENT TYPE REF TO CL_DD_DOCUMENT .
DATA : DOCTABLE TYPE REF TO CL_DD_TABLE_ELEMENT,
COL1_T1 TYPE REF TO CL_DD_AREA,
COL2_T1 TYPE REF TO CL_DD_AREA.
* add quick table with five columns
CALL METHOD LW_DOCUMENT->ADD_TABLE
EXPORTING
NO_OF_COLUMNS = 12
BORDER = '1'
WITH_HEADING = 'X'
WIDTH = '150%'
IMPORTING
TABLE = DOCTABLE.
* Filling columns in row
CALL METHOD DOCTABLE->ADD_COLUMN
EXPORTING
WIDTH = '8%'
IMPORTING
COLUMN = COL1_T1.
* Filling columns in row
CALL METHOD DOCTABLE->ADD_COLUMN
EXPORTING
WIDTH =  '8%'
IMPORTING
COLUMN = COL2_T1.
CALL METHOD DOCTABLE->NEW_ROW.
CALL METHOD COL1_T1->ADD_TEXT
EXPORTING
TEXT = 'JAN'.
CALL METHOD COL2_T1->ADD_TEXT
EXPORTING
TEXT = 'FEB'.
ENDFORM. "html_top_of_page

As you can see I am trying to use html_top_of_page but the main headings are at the top and not inline with the subheadings. I know you can also use alv_list_display but I need grid display in-order to use filtering and sorting on the subheadings. The main headings does not need to use filtering or sorting or any other but they need to be on top of the subheadings and be inline with them where each heading should occupy two sub headings. It is possible to use one row scroll for the whole report? Also it is better if the main headings are self centered. How to achieve this?

2 REPLIES 2

Jelena
Active Contributor

There is only one column header in ALV, it's not feasible to do multi-row headers like in Excel, for example. This question has been asked many times on SCN. Google -> "alv header multiple lines"

"Top of page" is a separate header for the whole ALV, it is not aligned with the columns at all.

raymond_giuseppi
Active Contributor
0 Kudos

Look at ALV Grid With Multiple Header Lines (basically 2 internal tables)