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.

Coding the INIT and END Methods 5.3

P_TEXT =

* p_problem_class =

.

* CATCH cx_tpda_application_log .

*ENDTRY.

Listing 5.5 Free Text

An application log object has to be created in order to have messages added to it

and to output the results. In the example in Section 5.3, you will see how to create

your application log in the INIT method and display it to yourself in the END

method.

Using Z Classes in the SCRIPT Method

The Script Wizard contains a large number of useful classes that can do almost anything

you can think of when it comes to controlling the debugger. However, you are bound to

reach a situation in which you need to do something that is not covered. When that day

comes, it’s no problem—because you’re in a normal ABAP method, so you can use your

own classes.

Say you want to save the application log to the database. The standard CL_TPDA_

SCRIPT_MESSAGES does not give you that option, so instead of using the wizard you just

use methods of a class that does have th at option, perhaps one that implements IF_

RECA_MESSAGE_LIST. You usually cannot create a subclass of standard SAP classes, like

CL_TPDA_SCRIPT_MESSAGES, because 99.99% of the time standard SAP classes are set

to final. Therefore, creating your own Z classes with the same method interfaces is the

way to go most of the time.

5.3 Coding the INIT and END Methods

To further illustrate the process of writing a debugger script, look at another

example, this time on e that involves the INIT and END methods as well as the

SCRIPT method. You have a program in which a monster counts to 10, and every

time the monster gets to a number that is divisible by three he has to say “Ha ha

ha.” Every time he gets to a number that is divisible by five, lightning flashes. The

end users are complaining that there is not enough laughing and lightning.

Sounds familiar, right? You probably get almost the exact same situation in your

day-to-day work all the time.

The example program can be seen in List ing 5.6. Right away, you will spot the

error, which is that the program uses the command DIV instead of MOD: tut, tut, tut.

215

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

Saved successfully!

Ooh no, something went wrong!