Question

I am working on a program in Business Warehouse that allows you to map out all of your process chains by following the hierarchy of parent to sub-chains by using the rspcchain table. As of right now I have it printing the output to the screen, but would like to export this output to excel instead. I have been unable to find a function module that serves this purpose, so any help would be greatly appreciated

note - after learning about the SALV classes available I changed the code to display the table differently.

REPORT  Z_PC_VARIANT_MAPPING.

*Declaring types and variables
TYPES: BEGIN OF t_chains,
  chain_id LIKE  rspcchain-chain_id,
  variant LIKE rspcchain-variante,
END OF t_chains.

DATA: lt_rspcchain TYPE STANDARD TABLE OF t_chains,
      lwa_rspcchain TYPE t_chains,
      o_alv TYPE REF TO cl_salv_table,
      lx_msg TYPE REF TO cx_salv_msg.

TABLES: rspcchain.

*selection screen setup
SELECT-OPTIONS chain_id FOR rspcchain-chain_id.
SELECT-OPTIONS type FOR rspcchain-type.

*filling local table
SELECT chain_id variante
  FROM rspcchain  INTO TABLE lt_rspcchain
  WHERE chain_id IN chain_id AND
  type IN  type AND
  objvers = 'A'.

*original code to test printing output on screen
*LOOP AT lt_rspcchain INTO lwa_rspcchain.
*  skip.
*  WRITE lwa_rspcchain-chain_id.
*  WRITE lwa_rspcchain-variant.
*ENDLOOP.

IF sy-subrc NE 0. "sy-subrc = return code
  WRITE 'Data not found'.
ENDIF.


*loading data from local table into alv object table
TRY.
  cl_salv_table=>factory(
    IMPORTING
      r_salv_table = o_alv
    CHANGING
      t_table      = lt_rspcchain ).
  CATCH cx_salv_msg INTO lx_msg.
ENDTRY.

*calling display method to display table
o_alv->display( ).
Was it helpful?

Solution

You can use the SALV framework for this, it comes with a class to export whatever would be displayed to various formats, including .MHTML and .XML formats that are understood by Excel. The class CL_SALV_TABLE has a method TO_XML to support this; additionally, you might need the CL_SALV_BS_XML_UTILS to handle the transformations. See the report SALV_TEST_TABLE_DISPLAY_OR_XML for example coding.

OTHER TIPS

You should look at the ABAP2XLSX project.

http://wiki.sdn.sap.com/wiki/display/ABAP/abap2xlsx

Not sure if all the necessary components exist in BW, but this is really the best solution for creating spreadsheets out of ABAP code that I have found.

You can try the following which will download a CSV file, which with the .xls extension opens flawlessly in Excel:

Convert lt_rspcchain to a csv internal table by calling SAP_CONVERT_TO_CSV_FORMAT

Figure out where the user wants to store the file by calling cl_gui_frontend_services=>file_save_dialog( )

Store the file by calling cl_gui_frontend_services=>gui_download( )

I assume you will be able to find how these work by experience or through Google.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top