14.01.2020 Views

ABAP_to_the_Future

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Enhancing Custom Reports with ABAP2XLSX 11.2

spreadsheet. Perhaps you want the same datato be displayed in different ways on

different sheets: a detail view, a summar y view, and a list of records requiring

attention, for example. This requires a lot of manual work, usually the exact same

work each month or week oreven day. Often, people get friendly Excel experts to

write macros to help them do this. Next, you will get to go one stage further and

have ABAP2XLSX do this work inside of SAP.

In this example, you will download a spreadsheet with two worksheets, both containing

the same report. (In real life, of course, you could have as many different

reports as you wanted.) Listing 11.22 sh ows the code to create a second worksheet

and fill it with data from a report. In Listing 11.22, you start from the position

of already having one worksheet that is full of data. You then give that original

worksheet a name so that you can te ll it apart from any others you create.

Then, create a second worksheet, and call the CONVERTER again to fill the new

worksheet with an SAP report, this time passing in the exact worksheet you want

to populate. (You didn’t need to perform that last step of passing in the worksheet

object back when there was only one worksheet.)

lo_worksheet->set_title( 'First Worksheet' ).

lo_worksheet = lo_excel->add_new_worksheet( ).

lo_worksheet->set_title( 'Second Worksheet' ).

lo_converter->convert(

EXPORTING

io_alv = go_view->mo_alv_grid

it_table = gt_monsters[]

i_table = abap_true

i_style_table = zcl_excel_table=>builtinstyle_medium2

"Specify newly created worksheet

io_worksheet = lo_worksheet

CHANGING

co_excel = lo_excel ).

Listing 11.22 Creating a Second Worksheet

Note

In fact, you do not need a report object at all; you can pass an internal table in via the

BIND_TABLE method of the worksheet object, and then you do not need a CONVERTER at

all. The worksheet object also has a BIND_ALV method that wraps the CONVERTER. However,

this chapter explains the long way of doing things so that you can see what’s really

happening.

483

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

Saved successfully!

Ooh no, something went wrong!