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

to quote Steerpike from the novel Gormen ghast, “What are problems for, if not

for solving?”). The next problem is that in two countries a standard monster is

handled the same way, in the United Stat es it’s handled a different way, and in

Australia nothing needs to be done at that point in the program. One way (not a

good way) of addressing this problem is demonstrated in Listing 6.2.

IF ( ld_land = 'DE' OR ld_land = 'GB' ) AND

ld_monster_type IN gr_standard_monster.

PERFORM something.

ELSEIF ld_land = 'US' AND ld_monster_type IN gr_standard_monster.

PERFORM something_else.

ELSEIF ld_land = 'AU' AND ld_monster_type IN gr_standard_monster.

* Don't do anything

ENDIF.

Listing 6.2 A Suboptimal Way of Coding Logic that Varies by Country

This code has conditional logic based on the country, so you keep having to

change the code for each new country adde d. To fix this problem, this is where

you need to take a leaf out of SAP’s book and define a BAdI. In such a situation,

SAP uses a BAdI, and if it is good enough for SAP, then it’s good enough for me.

Defining a BAdI is quite a complicated process, to put it mildly. One of the goals

of OO programming is abstraction (to sepa rate the things that change from the

things that stay the same), and sometimes to achieve a good level of abstraction

things have to be more complicated (have more layers) than you would find in

the procedural world. Creating a BAdI is rather like a Russian nesting doll: Each

time you create a doll, you then create a bigger one to put the last one into. The

outside world (the calling program) only sees the outermost doll; all the complexity

is hidden inside.

There are three main steps in defining a BAdI: creating an enhancement spot, creating

the BAdI definition, and creating th e BAdI interface. Each of these steps is

discussed next.

236

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

Saved successfully!

Ooh no, something went wrong!