Function module to export local table to excel
Solution 1
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.
Solution 2
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.
Jared
Updated on June 04, 2022Comments
-
Jared almost 2 years
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( ).
-
Jared almost 11 yearswhen i search for this function module in se37 it is not found.
-
Jared almost 11 yearsSAP_CONVERT_TO_CSV_FORMAT cannot be found
-
tomdemuyt almost 11 yearsOdd, you can also try working with
SAP_CONVERT_TO_TEX_FORMAT
or try to create an internal table with strings yourself. -
Jared almost 11 yearsi'm interested in trying that, hopefully it is available in my system.
-
Jared almost 11 yearsI just checked in SE37 and there are lots of ALV and SALV function modules available for use. Looks like this will be the right direction to go.
-
vwegert almost 11 years@Salmonerd It's not a function module, you'll have to use classes, but don't worry. You might search for a report named SALVXML, but I'll check tomorrow.
-
Bryan Cain almost 11 yearsThis FM may not be in BW. Not everything that can be found in ECC is.
-
Jared almost 11 yearsyep got it, i was able to do a little research on the SALV classes and have changed the code to now display the report using the SALV table class.