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.

11

ABAP2XLSX

EXPORTING

io_worksheet = core_object " Worksheet

ip_column = ip_column " Cell Column

ip_row = ip_row " Cell Row

ip_current_max = ip_current_max " Current maximum Width

RECEIVING

ep_width = ep_width ). " New Width

ENDMETHOD.

Listing 11.34 Coding an Overwrite Method

You will notice that in Listing 11.34 you cannot refer to the class you are enhancing

by using the me keyword to refer to the class instance; instead, you have to use

the term CORE_OBJECT. This is because when the ov erwrite method is called you

aren’t inside the main ZCL_EXCEL_WORKSHEET class; you’re inside a generated class

called LCL_ZEI_EXCEL_EXTENSIONS. which has an instance of the real class called

CORE_OBJECT passed into it upon creation.

11.3.2 Creating a Reusable Custom Framework

When looking at the code samples throughout this chapter, you may have noticed

that often it takes a large amount of code to achieve each function; the conditional

formatting code is a case inpoint. Despite this, every time you find yourself wanting

to cut and paste a large chunk of co de out of one program and into another

one and then change one or two input valu es, you should take a leaf out of the

Spice Girls’ book and stop right now. Obviously, this applies to programming as

a whole: not just ABAP2XLSX, not just SAP, but all code everywhere. However,

I’m talking about ABAP2XLSX specifically here, and although it’s good to work

out how to do each task, once you have that worked out it’s time to hide the complexity

in your own custom method of some sort of generic ABAP2XLSX Z custom

class.

For this example, assume there is such a class in the system, and (for example) the

code in Listing 11.33 is encapsulated in a method in that reusable Z class. It is the

same for emailing or downloading a spreadsheet: In each case, you have about 20

lines of code with just one value varying for each report, so it’s best to have a

reusable Z method with all the code that never changes in it, taking the variable

data as input parameters.

504

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

Saved successfully!

Ooh no, something went wrong!