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.

Features 1.2

ld_description1 = 'BONKERS'.

ELSE.

ld_description1 = 'AVERAGE SANITY'.

ENDIF.

IF ld_monster_madness2 LT 30.

ld_description2 = 'FAIRLY SANE'.

ELSEIF ld_monster_madness2 GT 90.

ld_description2 = 'BONKERS'.

ELSE.

ld_description2 = 'AVERAGE SANITY'.

ENDIF.

IF ld_monster_madness3 LT 30.

ld_description3 = 'FAIRLY SANE'.

ELSEIF ld_monster_madness3 GT 90.

ld_description3 = 'BONKERS'.

ELSE.

ld_description3 = 'AVERAGE SANITY'.

ENDIF.

ENDMETHOD.

ENDCLASS.

Listing 1.6 Sample Code with Changing Variables

How many times have you seen code li ke that—the same construct again and

again, with only the variables changing? This is in fact criminal behavior—and the

victim is the programmer who wrote the code—when there are so many ways to

make your life easier (e.g., macros).

To fix this problem, highlight the first IF/THEN/ELSE block—be sure to start with

the comment line—and press (ALT) + (SHIFT) + (M), or choose the menu option

Source 폷 Extract method. Up pops the box shown in Figure 1.15. You may wonder

where the proposed name came from; it is in fa ct the comment line, which

was why it was important to include the comment in the highlighted block. You

may have no comment or a bizarre comment, so of course you can change the

proposed name.

You will notice that Eclipse has looked at the variables in the highlighted section

and turned them into parameters. It so metimes gets confused, but generally the

result is fairly good. You can change th e name of the proposed parameters and

the direction. In this case, you do not want to change the monster madness level,

so turn the proposal into an IMPORTING parameter.

55

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

Saved successfully!

Ooh no, something went wrong!