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.

5

Debugger Scripting

DATA: ld_current_number TYPE sy-tabix,

ld_laugh_count TYPE sy-tabix,

ld_lightning_count TYPE sy-tabix.

DO 10 TIMES.

ADD 1 TO ld_current_number.

WRITE:/ 'Monster has counted to',ld_current_number.

IF ld_current_number DIV 3 = 0.

WRITE:/ 'Ha ha ha!'.

ADD 1 TO ld_laugh_count.

ENDIF.

IF ld_current_number MOD 5 = 0.

WRITE:/ 'Lightning Flashes!'.

ADD 1 TO ld_lightning_count.

ENDIF.

ENDDO.

Listing 5.6 Laughing Program with Error

Even though you already know what the error is, pretend that you’re at your

wit’s end; you just cannot spot what’s wrong. Instead of stepping through the

program one line at a time looking for where things go wrong, write a debugger

script to show you an application log thatanalyzes the program flow and tells you

what’s wrong.

Set a user-specific breakpoint right at th e start of the program, and execute it in

your development system. Once you’re in the debugger, navigate to the Script

tab, and move to the INIT method, where you’ll use the Script Wizard to insert a

template for creating an application log (Listing 5.7).

* Local Variables

DATA: ls_log_header TYPE bal_s_log.

ls_log_header-object = 'MONSTER'.

ls_log_header-extnumber = '12345'.

TRY.

CALL METHOD cl_tpda_script_messages=>create_appl_log

EXPORTING

p_log = ls_log_header

RECEIVING

p_ref_log = appl_log.

CATCH cx_tpda_application_log .

216

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

Saved successfully!

Ooh no, something went wrong!