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

ENDIF.

WHEN 33. "Lightning Count Changed

ld_info_text = |Lightning trigger { ld_current_

number } is supposed to be exactly divisible by 5|.

IF ld_current_number MOD 5 <> 0.

CONCATENATE ld_info_text 'and it is not'

INTO ld_info_text SEPARATED BY space.

ld_message_type = 'E'.

ELSE.

CONCATENATE ld_info_text 'and it is'

INTO ld_info_text SEPARATED BY space.

ld_message_type = 'S'.

ENDIF.

WHEN OTHERS.

RETURN.

ENDCASE.

* Write the information into the application log

TRY.

CALL METHOD appl_log->add_message_free_text

EXPORTING

p_mess_type = ld_message_type

p_text = ld_info_text.

CATCH cx_tpda_application_log .

RETURN.

ENDTRY.

"When done, return control to the real debugger

IF ld_current_number = 10.

me->break( ).

ENDIF.

ENDMETHOD.

Listing 5.8 SCRIPT Method for Laughing Example

"script

After the script finishes, the END method is called, and that is where you’ll display

the application log. You will notice in Listing 5.8 that at the end of the script

method there is some conditional logic such that after the last expected watchpoint

has been reached you force a breakp oint and return control to the normal

debugger. This is needed so that the End Script button pops up in the developers

face. The programmer needs to click that button; otherwise, the END method will

never be executed (Listing 5.9). (That fact seems really odd; you would expect the

END method to run at the end of a script, the way the INIT method runs automatically

at the start of a script, but in real life you have to press a button, and so a

button shall be pressed.)

219

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

Saved successfully!

Ooh no, something went wrong!