Skip to Content
author's profile photo Former Member
Former Member

Multi-line repeating header in ALV based on internal table data

I'm updating an ancient report that retrieves data from RESB and related tables. The old output method used basic WRITE statements to create a table header, the main data set and a footer. I've converted this output to an OO-based ALV table which now works well.

However, the end users will still expect to see the same header rows repeated in the new output instead of seeing this data as grouped columns in the ALV table. A such I want to recreate this header, either with standard ALV OO or in some manner that matches the layout of the ALV.

To make this more concrete, suppose I currently have the following data in my internal table and therefore in my ALV output:

Project Order Number Date Material Description

<PROJ-PSPID~1> <RESB-AUFNR~1> <RESB-BDTER~1> <RESB-MATNR~24> <MAKT-MAKTX~24>

<PROJ-PSPID~1> <RESB-AUFNR~1> <RESB-BDTER~2> <RESB-MATNR~53> <MAKT-MAKTX~53>

<PROJ-PSPID~1> <RESB-AUFNR~2> <RESB-BDTER~3> <RESB-MATNR~12> <MAKT-MAKTX~12>

<PROJ-PSPID~2> <RESB-AUFNR~5> <RESB-BDTER~4> <RESB-MATNR~45> <MAKT-MAKTX~45>

<PROJ-PSPID~2> <RESB-AUFNR~6> <RESB-BDTER~5> <RESB-MATNR~81> <MAKT-MAKTX~81>

<PROJ-PSPID~3> <RESB-AUFNR~9> <RESB-BDTER~8> <RESB-MATNR~22> <MAKT-MAKTX~22>

Now I'd like to move the first two columns to a header:

Project: <PROJ-PSPID~1>
Order Number: <RESB-AUFNR~1>
Date Material Description
<RESB-BDTER~1> <RESB-MATNR~24> <MAKT-MAKTX~24>
<RESB-BDTER~2> <RESB-MATNR~53> <MAKT-MAKTX~53>
Order Number: <RESB-AUFNR~2>
Date Material Description
<RESB-BDTER~3> <RESB-MATNR~12> <MAKT-MAKTX~12>

Project: <PROJ-PSPID~2>
Order Number: <RESB-AUFNR~5>
Date Material Description
<RESB-BDTER~4> <RESB-MATNR~45> <MAKT-MAKTX~45>
Order Number: <RESB-AUFNR~6>
Date Material Description
<RESB-BDTER~5> <RESB-MATNR~45> <MAKT-MAKTX~45>

Project: <PROJ-PSPID~3>
Order Number: <RESB-AUFNR~9>
Date Material Description
<RESB-BDTER~8> <RESB-MATNR~22> <MAKT-MAKTX~22>

Is it possible to implement this in OO ALV?

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

4 Answers

  • Best Answer
    Posted on Dec 31, 2013 at 04:12 PM

    Hi,

    You can do this with the 'REUSE_ALV_LIST_DISPLAY' function and the TOP-OF-PAGE event. This

    Here is a sample code of this functionality. I would recommend you to excecute and debug it.

    *--------------------------------------------------------------------------------------------------------------------*

    REPORT zexample NO STANDARD PAGE HEADING LINE-COUNT 10(2).

    TYPE-POOLS: slis.

    CONSTANTS: gc_tabname TYPE slis_tabname VALUE 'GT_REPORT',
    gc_1 TYPE i VALUE 1,
    gc_x TYPE char01 VALUE 'X'.

    TYPES: BEGIN OF gty_report,
    header1 TYPE c LENGTH 2,
    header2 TYPE c LENGTH 2,
    descri TYPE c LENGTH 10,
    detail TYPE c LENGTH 50,
    END OF gty_report,
    gty_t_report TYPE STANDARD TABLE OF gty_report,

    BEGIN OF gty_header,
    header1 TYPE c LENGTH 2,
    header2 TYPE c LENGTH 2,
    END OF gty_header,
    gty_t_header TYPE STANDARD TABLE OF gty_header.

    DATA: gt_report TYPE gty_t_report, "#EC NEEDED
    ga_report TYPE gty_report, "#EC NEEDED
    gt_header TYPE gty_t_header, "#EC NEEDED
    ga_header TYPE gty_header, "#EC NEEDED
    gv_mod TYPE i, "#EC NEEDED
    gv_header1 TYPE i VALUE 1, "#EC NEEDED
    gv_header2 TYPE i VALUE 1. "#EC NEEDED

    START-OF-SELECTION.

    * Filling internal table with any data based on the example you gave
    DO 20 TIMES.
    gv_mod = sy-index MOD 4.
    IF gv_mod EQ 0.
    ADD 1 TO gv_header1.
    gv_header2 = 1.
    ENDIF.
    MOVE: gv_header1 TO ga_report-header1,
    gv_header2 TO ga_report-header2,
    gv_header1 TO ga_header-header1,
    gv_header2 TO ga_header-header2,
    'Anything' TO ga_report-detail,
    gv_mod TO ga_report-descri.
    APPEND: ga_report TO gt_report,
    ga_header TO gt_header.
    ADD 1 TO gv_mod.
    MOVE gv_mod TO ga_report-descri.
    APPEND ga_report TO gt_report.
    ADD 1 TO gv_header2.
    ENDDO.

    CLEAR: gv_header1, gv_header2.
    PERFORM f_show_report.

    *&---------------------------------------------------------------------*
    *& Form f_show_report
    *&---------------------------------------------------------------------*
    * text
    *----------------------------------------------------------------------*
    FORM f_show_report.
    DATA: lt_fieldcat TYPE slis_t_fieldcat_alv, "#EC NEEDED
    lt_events TYPE slis_t_event, "#EC NEEDED
    lt_sort TYPE slis_t_sortinfo_alv, "#EC NEEDED
    ls_print TYPE slis_print_alv, "#EC NEEDED
    ls_layout TYPE slis_layout_alv. "#EC NEEDED

    * Catalogo ALV
    * ALV Fieldcat
    PERFORM f_build_fieldcat CHANGING lt_fieldcat.
    PERFORM f_set_alv CHANGING lt_events
    lt_sort
    ls_layout
    ls_print.

    * Display ALV
    * Show ALV
    CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
    EXPORTING
    i_callback_program = sy-repid
    it_fieldcat = lt_fieldcat[]
    it_events = lt_events[]
    it_sort = lt_sort[]
    is_layout = ls_layout
    is_print = ls_print
    i_callback_pf_status_set = slis_ev_pf_status_set
    i_callback_user_command = slis_ev_user_command
    TABLES
    t_outtab = gt_report[]
    EXCEPTIONS
    program_error = 1
    OTHERS = 2.

    IF sy-subrc NE 0.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
    WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
    ENDIF.
    ENDFORM. "f_show_report
    *&---------------------------------------------------------------------*
    *& Form F_BUILD_FIELDCAT
    *&---------------------------------------------------------------------*
    * text
    *----------------------------------------------------------------------*
    * --> p1 text
    * <-- p2 text
    *----------------------------------------------------------------------*
    FORM f_build_fieldcat CHANGING p_t_fieldcat TYPE slis_t_fieldcat_alv.
    REFRESH p_t_fieldcat.

    * Header1
    PERFORM f_add_column USING gc_tabname 'HEADER1' 'Header 1'
    10 space space space
    CHANGING p_t_fieldcat.
    * Header2
    PERFORM f_add_column USING gc_tabname 'HEADER2' 'Header 2'
    10 space space space
    CHANGING p_t_fieldcat.
    * Description
    PERFORM f_add_column USING gc_tabname 'DESCRI' 'Description'
    15 space space space
    CHANGING p_t_fieldcat.
    * Detail
    PERFORM f_add_column USING gc_tabname 'DETAIL' 'Detail'
    50 space space space
    CHANGING p_t_fieldcat.
    ENDFORM. " F_BUILD_FIELDCAT
    *&---------------------------------------------------------------------*
    *& Form F_SET_ALV
    *&---------------------------------------------------------------------*
    * text
    *----------------------------------------------------------------------*
    * --> p1 text
    * <-- p2 text
    *----------------------------------------------------------------------*
    FORM f_set_alv CHANGING p_t_events TYPE slis_t_event
    p_t_sort TYPE slis_t_sortinfo_alv
    p_s_layout TYPE slis_layout_alv
    p_s_print TYPE slis_print_alv.

    DATA: ls_event TYPE slis_alv_event,
    ls_sort TYPE slis_sortinfo_alv.

    ls_sort-fieldname = 'HEADER1'.
    ls_sort-tabname = gc_tabname.
    ls_sort-spos = 1.
    ls_sort-up = 'X'.
    APPEND ls_sort TO p_t_sort.

    ls_sort-fieldname = 'HEADER2'.
    ls_sort-tabname = gc_tabname.
    ls_sort-spos = 1.
    ls_sort-up = 'X'.
    ls_sort-group = '*'.
    APPEND ls_sort TO p_t_sort.

    MOVE: gc_x TO p_s_print-no_new_page,
    gc_x TO p_s_layout-zebra.

    * EVENTOS DEL ALV
    * ALV EVENTS
    CALL FUNCTION 'REUSE_ALV_EVENTS_GET'
    EXPORTING
    i_list_type = 0
    IMPORTING
    et_events = p_t_events.

    CLEAR ls_event.
    READ TABLE p_t_events WITH KEY name = slis_ev_top_of_page
    INTO ls_event.
    IF sy-subrc IS INITIAL.
    MOVE slis_ev_top_of_page TO ls_event-form.
    APPEND ls_event TO p_t_events.
    ENDIF.
    ENDFORM. " F_SET_ALV

    *&---------------------------------------------------------------------*
    *& Form f_add_column
    *&---------------------------------------------------------------------*
    * text
    *----------------------------------------------------------------------*
    * -->P_TABNAME text
    * -->P_FIELDNAME text
    * -->P_SELTEXT text
    * -->P_OUTPUTLEN text
    * -->P_COL_POS text
    * -->P_DO_SUM text
    * -->P_JUST text
    * -->P_HOTSPOT text
    *----------------------------------------------------------------------*
    FORM f_add_column USING p_tabname TYPE slis_tabname
    p_fieldname TYPE string
    p_seltext TYPE string
    p_outputlen TYPE outputlen
    p_do_sum TYPE c
    p_just TYPE c
    p_hotspot TYPE c
    CHANGING p_t_fieldcat TYPE slis_t_fieldcat_alv.

    DATA: la_fieldcat TYPE slis_fieldcat_alv,
    lv_col_pos TYPE sycucol,
    lv_lines TYPE i.

    DESCRIBE TABLE p_t_fieldcat LINES lv_lines.
    ADD 1 TO lv_lines.
    MOVE lv_lines TO lv_col_pos.

    MOVE: lv_col_pos TO la_fieldcat-col_pos,
    p_tabname TO la_fieldcat-tabname,
    p_fieldname TO la_fieldcat-fieldname,
    p_seltext TO la_fieldcat-seltext_s,
    p_seltext TO la_fieldcat-seltext_m,
    p_seltext TO la_fieldcat-seltext_l,
    p_outputlen TO la_fieldcat-outputlen,
    p_do_sum TO la_fieldcat-do_sum,
    p_just TO la_fieldcat-just,
    p_hotspot TO la_fieldcat-hotspot.
    APPEND la_fieldcat TO p_t_fieldcat.
    ENDFORM. "f_add_column


    *&---------------------------------------------------------------------*
    *& Form TOP_OF_PAGE
    *&---------------------------------------------------------------------*
    * Evento TOP OF PAGE del ALV
    * ALV TOP OF PAGE Event
    *----------------------------------------------------------------------*
    FORM top_of_page. "#EC CALLED
    READ TABLE gt_header INDEX sy-pagno INTO ga_header.
    IF gv_header1 NE ga_header-header1.
    FORMAT INTENSIFIED ON COLOR = 3.
    WRITE: /5 'HEADER 1:', AT 20 ga_header-header1.
    FORMAT COLOR OFF.
    MOVE ga_header-header1 TO gv_header1.
    ENDIF.
    WRITE: /5 'HEADER 2:', AT 20 ga_header-header2 .
    ENDFORM. "top_of_page

    *--------------------------------------------------------------------------------------------------------------------------------------------*


    This is the result of this report's excecution.


    I hope this may help you.

    Best regards,

    Rubén Mircin


    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Dec 30, 2013 at 02:17 PM

    Some more reading seems to point me in the direction of the ALV Tree instead of a Table or Grid. Would this be my only option for preserving this header structure? If so, can its layout be modified to look less like a directory tree and more like a classic header along with full auto-expansion of all nodes?

    Or is there an alternative solution using the classic ALV controls? Repeated ALVs inside dynamically created custom containers, subcontainers and splitters?

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jan 01, 2014 at 06:47 AM

    Hi Tom Dhooghe,

    Try to use REUSE_ALV_BLOCK_LIST for multiple ALV list display.

    Regards,

    Aditya Tanguturi.

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Jan 02, 2014 at 04:43 PM

    use Blocked REUSE_ALV_BLOCK_LIST and REUSE_ALV_HIERSEQ_LIST_DISPLAY.

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.