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.

Types of Exception Classes 7.1

declared in the routine signature. In essence, you can throw the exception object

up in the air, and it will travel up the call stack looking for an appropriate handler.

It will stop at the first one it finds, and if it can’t find any, then a short dump will

occur.

In most documentation, this type of exception class is described as being useful

for problems that can occur anywhere (such as the system running out of memory),

and it would clearly be impractical to declare a long list of such exception

classes in every single method signatur e throughout the system. However, this

also has a much wider application. As an example, say that you have an interactive

ALV list program that calls a Mon ster Monitor. The Monster Monitor displays

a list of active monsters, and you can select a monster by clicking the checkbox

next to the monster. Then, you can choose one of 15 icons along the top of

the screen to issue various commands to that monster. The code for this is shown

in Listing 7.2.

FORM user_command USING id_ucomm TYPE sy-ucomm

is_selfield TYPE slis_selfield.

TRY.

PERFORM get_chosen_monster USING is_selfield

CHANGING mo_chosen_monster.

PERFORM lock_monster USING mo_chosen_monster.

CASE id_ucomm.

WHEN 'HOWL'.

mo_chosen_monster->howl_at_moon( ).

WHEN 'TERROR'.

mo_chosen_monster->terrorise_village( ).

WHEN 'SUBPRIME'.

"Most monstrous activity possible

mo_chosen_monster->sell_mortgages( ).

"Etc...

WHEN OTHERS.

MESSAGE 'Function is not available' TYPE 'I'.

ENDCASE.

CATCH zcx_bc_user_cancelled.

MESSAGE 'Processing Cancelled'(349) TYPE 'S'.

PERFORM unlock_monster USING mo_chosen_monster.

RETURN.

ENDTRY.

261

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

Saved successfully!

Ooh no, something went wrong!