14.01.2020 Views

ABAP_to_the_Future

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

11

ABAP2XLSX

to the application server (which is pain ful, because IT doesn’t really want your

average person to have access to the ap plication server) or the user had to open

up the spool request and download it (which gives you random blank columns at

the front and top, with the headers repe ating throughout the sheet; it involves

tons of manual formatting of the downloaded spreadsheet).

With ABAP2XLSX, there’s a miracle soluti on to this problem. Run the report in

the background and then email the resulting spreadsheet; you can send it to yourself

or to a distribution list. The sp readsheet generated from the SAP report

appears as an attachment in the email.

There is nothing extraordinary about the code that follows (Listing 11.31). You

can see it on the Internet in a million places, almost line for line in every case. The

only thing happening differently here is that the XML string has been generated

from an Excel object.

* Local Variables

DATA: lo_send_request TYPE REF TO cl_bcs,

lo_document TYPE REF TO cl_document_bcs,

lo_recipient TYPE REF TO if_recipient_bcs,

lo_bcs_exception TYPE REF TO cx_bcs,

lt_main_text TYPE bcsy_text,

lf_sent_to_all TYPE os_boolean,

ld_bytecount TYPE i,

ld_filelen TYPE so_obj_len,

lt_file_tab TYPE solix_tab,

ld_email

TYPE ad_smtpadr.

"Start off with the XSTRING derived from the EXCEL object

"Convert this to a format that the standard SAP emailing

"class understands

lt_file_tab = cl_bcs_convert=>xstring_to_solix(

iv_xstring = id_file ).

ld_bytecount = xstrlen( id_file ).

TRY.

“Off you go with the standard emailing code

lo_send_request = cl_bcs=>create_persistent( ).

*The email body is a table with lines of element SOLI

lt_main_text = lt_email_body.

lo_document = cl_document_bcs=>create_document(

i_type = 'RAW'

i_text = lt_main_text

i_subject = id_email_subject ).

494

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!