0

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  zsam7.

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?

Sandra Rossi
  • 11,934
  • 5
  • 22
  • 48
mj1261829
  • 1,200
  • 3
  • 26
  • 53
  • Thank you for providing the code, but please could you make it [minimal](https://stackoverflow.com/help/minimal-reproducible-example) so that it's more readable/understandable by visitors? Note that it works only in SAP ERP systems and you may easily make it work in all ABAP systems by using a table like T000 ("clients"). – Sandra Rossi Aug 08 '19 at 07:42
  • What do you mean by subheadings? Those deb cred columns? – Jagger Aug 08 '19 at 17:44
  • YES, thats what I meant. – mj1261829 Aug 09 '19 at 07:20
  • The header area is completely independent of the table area and so of the columns there. There is no chance you can align it with column widths. – Jagger Aug 09 '19 at 08:22
  • I see but is there another way to do it? – mj1261829 Aug 09 '19 at 08:34
  • `CL_SALV_HIERSEQ_TABLE` gives a possibility to define something like main header and subheaders. Maybe it will suit you. Example program `SALV_DEMO_HIERSEQ_SIMPLE`. – Jagger Aug 09 '19 at 10:25
  • 1
    Also didn't get what is implied by two headings/subheadings. Try to paint a screenshot of what you want – Suncatcher Aug 09 '19 at 16:40

0 Answers0