Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

convert ALV spool output into excel file

siongchao_ng
Contributor
0 Kudos

Hi all,

I am supposed to run a few programs in background and download it to shared folder.

The output is ALV. So I get the spool number. How do I convert the spool output into excel?

I tried with both RSPO_RETURN_ABAP_SPOOLJOB and RSPO_RETURN_ABAP_SPOOLJOB_RAW but it is returning in text format.

Any method for this?

3 REPLIES 3

Former Member
0 Kudos

Greetings siongchao.ng,

Have you checked this post?

https://blogs.sap.com/2018/06/16/using-abap2xlsx-to-send-alv-table-output-as-excel-spreadsheet-via-i...

The following has an extensive code example for reference

https://answers.sap.com/questions/11478354/convert-alv-output-to-excel.html

Let us know if it helped to address you topic.

Cheers,

Luis

Sandra_Rossi
Active Contributor

If you generate a spool, it will be very difficult to transform it into a nice Excel file. Why not creating a custom program which calls the programs and intercepts their ALV output directly as several internal tables? You can transform them into Excel files too. Search the forum for class CL_SALV_BS_RUNTIME_INFO, CL_SALV_EXPORT_DB_STORAGE, etc.

former_member818464
Discoverer
0 Kudos

Hi

Try to export the spool to DB memory - whatever report it is + the selection screen parameters

EXPORT l_mode = 'M' TO MEMORY ID 'ALV_EXTRACT_MODE'.
EXPORT l_guid = gv_guid TO MEMORY ID 'ALV_EXTRACT_GUID'.

SUBMIT (lv_prog) EXPORTING LIST TO MEMORY
USING SELECTION-SET s_var-low
AND RETURN.

Now get the xml data into Xstring variable

gv_xxml_data = cl_salv_export_db_storage=>import_xmlstring( guid = gv_guid ).

transfer the data to Application server ( use your path - and save as xlsx / xml )

CONCATENATE p_files '\' p_name lv_count '.xml' INTO lv_path.
OPEN DATASET lv_path FOR OUTPUT IN BINARY MODE.
TRANSFER gv_xxml_data TO lv_path.
CLOSE DATASET lv_path.

OR create an attachment using following method and send email :

lv_size = XSTRLEN( gv_xxml_data ).
WHILE lv_int < lv_size.
lv_offset = lv_size - lv_int.
IF lv_offset >= 255.
ls_data-line = gv_xxml_data+lv_int(255).
ELSE.
ls_data-line = gv_xxml_data+lv_int(lv_offset).
ENDIF.
APPEND ls_data TO lt_data.
CLEAR ls_data.
lv_int = lv_int + 255.
ENDWHILE.
CONCATENATE p_name '.xlsx' INTO lv_filename.
REPLACE '"' IN lv_filename WITH space.
SPLIT lv_filename AT '.' INTO lv_filename lv_exten.
TRY.
lr_document = cl_document_bcs=>create_document(
i_type = 'RAW'
i_text = lt_main_text
i_subject = lv_subj ).

lr_document->add_attachment(
i_attachment_type = lv_exten
i_attachment_subject = lv_filename
i_attachment_size = lv_size
i_att_content_hex = lt_data ).

lr_send_request = cl_bcs=>create_persistent( ).
lr_send_request->set_document( lr_document ).

LOOP AT so_adr INTO so_adr.
lr_recipient = cl_cam_address_bcs=>create_internet_address( so_adr-low ).
lr_send_request->add_recipient( lr_recipient ).
ENDLOOP.

lr_send_request->send( i_with_error_screen = 'X' ).

COMMIT WORK.
CATCH cx_root.
EXIT.
ENDTRY.

--- this program is also a good example for external export in different formats:

pass xml_type = 10 for .xls

SALV_TEST_XML_TRANSFER_EXTERN