I want to add multiple column headers for the same field. I am using Factory model alv to display the output. Please refer the attached screen shot to get a better understanding of the requirement.
I am getting the following output
the code i've used is as follows:-
FORM display_data .
DATA : lt_salv_table TYPE REF TO cl_salv_table,
lt_salv_functions_list TYPE REF TO cl_salv_functions_list,
lt_salv_form_layout_grid TYPE REF TO cl_salv_form_layout_grid,
lt_grid_obj TYPE REF TO cl_salv_form_layout_grid,
lt_salv_column TYPE REF TO cl_salv_column,
lt_salv_columns TYPE REF TO cl_salv_columns,
lt_salv_columns_table TYPE REF TO cl_salv_columns_table,
lt_salv_column_table TYPE REF TO cl_salv_column_table,
lt_salv_aggregations TYPE REF TO cl_salv_aggregations,
lt_salv_aggregation TYPE REF TO cl_salv_aggregation,
lt_grid_fobj TYPE REF TO cl_salv_form_layout_grid,
lt_text TYPE REF TO cl_salv_form_text,
lt_salv_wd_column_header TYPE REF TO cl_salv_wd_column_header.
DATA : lt_footer_obj TYPE REF TO cl_salv_form_layout_grid,
lt_grid TYPE REF TO cl_salv_form_layout_grid.
DATA : lv_month TYPE t247-ltx,
lv_mon_h TYPE string.
***Setting Report Heading
DEFINE header.
call method lt_grid_obj->create_label
exporting
row = &1
column = &2
text = &3.
END-OF-DEFINITION.
***Macro to change column heading
DEFINE set_cl_hd.
try.
lt_salv_column = lt_salv_columns->get_column( &1 ).
lt_salv_column->set_short_text( &2 ).
lt_salv_column->set_medium_text( &3 ).
lt_salv_column->set_long_text( &4 ).
lt_salv_column->set_optimized( ).
catch cx_salv_not_found.
message i158 with text-026. "'Output Failed'.
endtry.
END-OF-DEFINITION.
***Calling Factory method
TRY.
CALL METHOD cl_salv_table=>factory
IMPORTING
r_salv_table = lt_salv_table
CHANGING
t_table = gt_final_d.
CATCH cx_salv_msg .
MESSAGE i158 WITH text-003. "Output Failed.
ENDTRY.
***Standard Toolbar
CALL METHOD lt_salv_table->get_functions
RECEIVING
value = lt_salv_functions_list.
CALL METHOD lt_salv_functions_list->set_all
EXPORTING
value = if_salv_c_bool_sap=>true.
***Setting Report Heading
CREATE OBJECT lt_salv_form_layout_grid.
lt_grid_obj = lt_salv_form_layout_grid->create_grid( row = 4
column = 5
colspan = 8 ).
header 1 40 text-004.
header 2 05 text-005.
header 3 1 text-006.
CALL METHOD lt_salv_table->set_top_of_list
EXPORTING
value = lt_grid_obj.
***Getting column values
CALL METHOD lt_salv_table->get_columns
RECEIVING
value = lt_salv_columns.
***Calling Macro to change Column headers
set_cl_hd 'DATE' text-008 text-008 text-009 .
set_cl_hd 'LFIMG_500' text-010 text-010 text-011 .
set_cl_hd 'LFIMG_1' text-012 text-012 text-013 .
set_cl_hd 'LFIMG_2' text-014 text-014 text-015 .
set_cl_hd 'LFIMG_3' text-016 text-016 text-017 .
set_cl_hd 'LFIMG_5' text-018 text-018 text-019 .
set_cl_hd 'LFIMG_T' text-020 text-020 text-021 .
set_cl_hd 'QUOTA_AL' text-022 text-022 text-023 .
set_cl_hd 'QUOTA_P' text-024 text-024 text-025 .
***Create an instance of Footer objects
CREATE OBJECT lt_footer_obj
EXPORTING
columns = 1.
***Create a Grid with 5 rows and 3 columns
CALL METHOD lt_footer_obj->create_grid
EXPORTING
row = 5
column = 3
RECEIVING
r_value = lt_grid.
***Footer Macro
DEFINE footer.
lt_text = lt_grid->create_text(
row = &1
column = &2
text = &3 ).
END-OF-DEFINITION.
DATA : lv_total TYPE char10,
lv_tot TYPE char12,
lv_sub TYPE i,
lv_f_mon TYPE string,
lv_mon_number TYPE sy-datum.
lv_tot = gs_final-lfimg_t.
SHIFT lv_tot LEFT DELETING LEADING space.
CONCATENATE '(' lv_tot ')' INTO lv_total.
SHIFT lv_total LEFT DELETING LEADING space.
lv_sub = pa_quota - gs_final-lfimg_t.
footer 1 85 lv_f_mon.
footer 1 87 pa_quota .
footer 2 85 'Total Delivery'.
footer 2 87 lv_total.
footer 3 87 '___________'.
footer 4 87 lv_sub.
footer 5 87 '___________'.
CALL METHOD lt_salv_table->set_end_of_list
EXPORTING
value = lt_footer_obj.
***Display
CALL METHOD lt_salv_table->display.
ENDFORM. "DISPLAY_DATA