14.01.2020 Views

ABAP_to_the_Future

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

6

The Enhancement Framework and New BAdIs

company code or plant being processed). Inthe current example, this enables you

to avoid hard-coding the country value th at gets passed into the BAdI filter. As

you can see, there is also some conditio nal logic to see what sort of monster

you’re dealing with, and then code that tasks a BAdI with dealing with the chosen

monster type.

This code is yet another example of a separation of concerns, and every time you

achieve a separation of concerns, you get to pass GO and collect a million dollars.

The part of the program that determines the monster type doesn’t need to know

what you’re going to do with that information, and the part that deals with a specific

monster type doesn’t need to know how you worked out what monster type

you’re dealing with.

DATA: lo_monster_badi TYPE REF TO ybd_vc_monster_handler.

ld_land = ls_company_code-land.”GB

IF ld_monster_type IN gr_standard_monster.

ld_monster_type_name = 'STANDARD_MONSTER'.

ELSEIF ld_monster_type IN gr_extra_scary_monster.

ld_monster_type_name = 'EXTRA_SCARY_MONSTER'.

ELSE.

"Unexpected situation, do some error handling

ENDIF.

TRY.

GET BADI lo_monster_badi

FILTERS

country = ld_land

monster_type = ld_monster_type_name.

CALL BADI lo_monster_badi->handle_monster

CHANGING

co_monster = lo_monster.

CATCH ycx_monster_exception.

"Do some error handling

CATCH cx_badi_not_implemented.

"This exception only happens for single-use BAdIs

ENDTRY.

Listing 6.4 Calling a BAdI

250

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

Saved successfully!

Ooh no, something went wrong!