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

CREATE OBJECT lo_excel_writer TYPE zcl_excel_writer_xlsm.

"Where did I say the file lived?

ld_full_path = p_path.

"Load the empty template with the macros

lo_excel = lo_excel_reader->load_file( ld_full_path ).

"Transform the resulting EXCEL object into a whacking

"great XSTRING

ld_object_as_xstring = lo_excel_writer->write_file( lo_excel ).

Listing 11.26 Turning a Blank Spreadsheet into an XSTRING

Saving the Template in the SAP Database

Create a transparent table to store your templates inside SAP. You could get all

fancy and store them in the MIME repository, but a quick and dirty solution is to

go into Transaction SE11 and create a table like the one shown in Figure 11.13.

Figure 11.13 Excel Template Storage Table

Then, you need to store the XSTRING version of the Excel object in the database

(Listing 11.27). There’s nothing fancy here; set the primary key of the table entry

to be the template name, add the XSTRING data, and then use the MODIFY statement

to store the data.

DATA: ls_template TYPE ztexcel_template.

"What did we say the template name was?

ls_template-template_name = p_temp.

ls_template-raw_data = ld_object_as_xstring.

MODIFY ztexcel_template FROM ls_template.

Listing 11.27 Storing the Spreadsheet Template in the Database

490

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

Saved successfully!

Ooh no, something went wrong!