‎2014 Feb 21 8:36 AM
Hi ABAP gurus,
I am in need of help, I have create my ALV using SALV classes which works fine.
But when i want to export to Excel by clicking Microsoft Excel button(Ctrl+Shift+F7) on the PF-Status, it will call Excel in SAP, The header title doesnt appear unlike traditional REUSE_ALV_GRID_DISPLAY. Am I missing any steps? I do not want to change all my code back to using the FM style.
My header already appeared in top of page, but it is missing in excel. Appreciate your help here.
My example code for top of page:
lo_h_label = lo_header->create_label( row = 1 column = 1 text = gv_title ).
lo_header->create_header_information( row = 1 column = 1 text = gv_title ).
lo_h_label->set_text( gv_title ).
lo_alv->set_top_of_list( lo_header ).
lo_alv->set_top_of_list_print( lo_header ).
Many thanks!
.
‎2014 Feb 22 4:56 AM
OK solved it by using the FM
REUSE_ALV_COMMENTARY_WRITE. The header appears in the excel in place even I use SALV class. Ha ha.
‎2014 Feb 21 9:09 AM
which function are you using? Direct export to excel or Local file... / Spreadsheet?
‎2014 Feb 21 9:45 AM
Hi Jozef,
I'm using the direct export. It will prompt for macro enable. I think this sample code is having the same problem:
REPORT ztest_wrap.
*----------------------------------------------------------------------*
* CLASS lcl_report DEFINITION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS lcl_report DEFINITION.
PUBLIC SECTION.
*----------------------------------------------------------------------*
* Final Output Table
*----------------------------------------------------------------------*
TYPES: BEGIN OF ty_mara,
matnr TYPE matnr,
ersda TYPE ersda,
matkl TYPE matkl,
mtart TYPE mtart,
lvorm TYPE lvorm,
END OF ty_mara.
DATA: o_alv TYPE REF TO cl_salv_table, " ALV Reference
t_mara TYPE STANDARD TABLE OF ty_mara.
*----------------------------------------------------------------------*
* Methods to Fetch Data and Generate Output
*----------------------------------------------------------------------*
METHODS: get_data, "Data Selection
generate_output. "Generating Output PRIVATE SECTION.
*----------------------------------------------------------------------*
* Methods to Set PF-Status, Header and Footer
*----------------------------------------------------------------------*
METHODS: set_pf_status
CHANGING
co_alv TYPE REF TO cl_salv_table, " Default Pf Status
set_top_of_page
CHANGING
co_alv TYPE REF TO cl_salv_table, " Set Top of page
set_end_of_page
CHANGING
co_alv TYPE REF TO cl_salv_table. " Set End of page
ENDCLASS. "lcl_report DEFINITION
*----------------------------------------------------------------------*
* CLASS lcl_report IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS lcl_report IMPLEMENTATION.
*----------------------------------------------------------------------*
* Data selection
*----------------------------------------------------------------------*
METHOD get_data.
SELECT matnr ersda matkl mtart lvorm INTO TABLE t_mara
FROM mara UP TO 20 ROWS.
ENDMETHOD. "get_data
*----------------------------------------------------------------------*
* Generating Output
*----------------------------------------------------------------------*
METHOD generate_output.
*Exception Class
DATA: lc_msg TYPE REF TO cx_salv_msg.
DATA: lo_alv_functions TYPE REF TO cl_salv_functions_list.
*----------------------------------------------------------------------*
* We are calling the static Factory method which will give back
* the ALV object reference.
*----------------------------------------------------------------------*
TRY.
CALL METHOD cl_salv_table=>factory
IMPORTING
r_salv_table = o_alv
CHANGING
t_table = t_mara.
CATCH cx_salv_msg INTO lc_msg .
ENDTRY.
************************************************************************
* In this area we will call the methods which will set the
* different properties to the ALV
************************************************************************
* Calling Set PF status method
CALL METHOD set_pf_status
CHANGING
co_alv = o_alv. "set_end_of_page
* Calling the top of page method
CALL METHOD set_top_of_page
CHANGING
co_alv = o_alv.
*Set functions
lo_alv_functions = o_alv->get_functions( ).
lo_alv_functions->set_default( 'X' ).
lo_alv_functions->set_all( 'X' ).
lo_alv_functions->set_layout_save( 'X' ).
lo_alv_functions->set_layout_load( 'X' ).
lo_alv_functions->set_layout_maintain( 'X' ).
lo_alv_functions->set_layout_save( 'X' ).
* Calling the End of page method
CALL METHOD set_end_of_page
CHANGING
co_alv = o_alv.
************************************************************************
* Displaying the ALV
* Here we will call the DISPLAY method to get the output on the screen
************************************************************************
o_alv->display( ).
ENDMETHOD. "generate_output ************************************************************************
* In this area we will implement the methods which are defined in
* the class definition
************************************************************************
* Setting Default PF-Status
METHOD set_pf_status.
DATA: lo_functions TYPE REF TO cl_salv_functions_list.
* Default functions
lo_functions = co_alv->get_functions( ).
lo_functions->set_default( abap_true ).
ENDMETHOD. "set_pf_status
* Setting Top_of_page
METHOD set_top_of_page.
DATA: lo_header TYPE REF TO cl_salv_form_layout_grid,
lo_h_label TYPE REF TO cl_salv_form_label,
lo_h_flow TYPE REF TO cl_salv_form_layout_flow.
* Header object
CREATE OBJECT lo_header.
*----------------------------------------------------------------------*
* To create a Label or Flow we have to specify the target
* row and column number where we need to set up the output
* text.
*----------------------------------------------------------------------*
* Information in Bold
lo_h_label = lo_header->create_label( row = 1 column = 1 text = 'Header of the ALV Output in Bold' ).
lo_header->create_header_information( row = 1
column = 1
text = 'Header of the ALV Output in Bold' ).
lo_h_label->set_text('Header of the ALV Output in Bold').
* Information in tabular format
lo_h_flow = lo_header->create_flow( row = 2 column = 1 ).
lo_h_flow->create_text( text = 'This is text of flow in Header' ).
lo_h_flow = lo_header->create_flow( row = 3 column = 1 ).
lo_h_flow->create_text( text = 'Date of List Generation' ).
lo_h_flow = lo_header->create_flow( row = 3 column = 2 ).
lo_h_flow->create_text( text = sy-datum ).
* Set the top of list using the header for Online
co_alv->set_top_of_list( lo_header ).
* Set the top of list using the header for Print
co_alv->set_top_of_list_print( lo_header ).
ENDMETHOD. "set_top_of_page
* Setting End_Of_page
METHOD set_end_of_page.
DATA: lo_footer TYPE REF TO cl_salv_form_layout_grid,
lo_f_label TYPE REF TO cl_salv_form_label,
lo_f_flow TYPE REF TO cl_salv_form_layout_flow.
* Footer Object
CREATE OBJECT lo_footer.
* Information in Bold
lo_f_label = lo_footer->create_label( row = 1 column = 1 ).
lo_f_label->set_text('Footer of the ALV in Bold').
* Tabular Information
lo_f_flow = lo_footer->create_flow( row = 2 column = 1 ).
lo_f_flow->create_text( text = 'This is text of flow in footer' ).
* Set the end of list using the header for Online
co_alv->set_end_of_list( lo_footer ).
* Set the End of list using the header for Print
co_alv->set_end_of_list_print( lo_footer ).
ENDMETHOD. "set_end_of_page
ENDCLASS. "lcl_report IMPLEMENTATION
"lcl_report IMPLEMENTATION
*----------------------------------------------------------------------*
START-OF-SELECTION.
*----------------------------------------------------------------------*
DATA: lo_report TYPE REF TO lcl_report.
CREATE OBJECT lo_report.
lo_report->get_data( ).
lo_report->generate_output( ).
Try clicking the excel button and the macro enabled excel will populate the excel, but with no title header. It is possible to do it using the FM way.
Thanks!
‎2014 Feb 21 4:05 PM
Oh the excel function i think it is call excel in place.
thanks. anybody can help?
‎2014 Feb 22 4:56 AM
OK solved it by using the FM
REUSE_ALV_COMMENTARY_WRITE. The header appears in the excel in place even I use SALV class. Ha ha.
‎2015 Jul 09 2:47 PM
Good afternoon.
You can ask for an example of how you have organized code in Excel Inplace? I use CL_GUI_ALV_GRID, and deduce the TOP-OF-PAGE and ALV. When push Excel Inplace do not see HEADER, it is not filled to Excel, visible only the data