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.

Mass Checks 4.2

CASE statement, like the one in Listing 4.1. The rule in the syntax check for CASE

statements is that there should always be an OTHERS branch to handle all situations

not catered for in the branches where you have given specific values.

The code in Listing 4.1 represents the following business rule: If a monster scares

one or two villagers during the course of the day, then his happiness changes to

a specific percentage. If the monster has sc ared no villagers, or more than two,

then his happiness remains unchanged.

DATA: ld_monster_happiness TYPE i,

ld_villagers_scared_today TYPE i.

ld_monster_happiness = lo_monster->get_current_happiness( ).

CASE ld_villagers_scared_today.

WHEN 1.

ld_monster_happiness = 25.

WHEN 2.

ld_monster_happiness = 50.

ENDCASE.

Listing 4.1 CASE Statement that Only Changes a Variable Sometimes

This code is exactly what you want, but nonetheless the extended syntax check is

going to give you a false positive warning because there is no OTHERS branch. You

have two choices:

1. You can leave the code as it is, in wh ich case you will get a warning that you

haven’t dealt with the OTHERS possibility in the CASE statement.

2. You can add an OTHERS clause that says “do nothing” as a comment, and then

you’ll get a warning that there ar e no executable statements between OTHERS

and ENDCASE.

In the case of mass checks, false positive s occur when the static code checks fail

but there is a good reason why the “rule” set by the system is not being obeyed.

A good example is when you create a function module to be called by a dependency

in Variant Configuration (which chan ges the value of one or more fields

depending upon the value of other fields). In such cases, the interface/signature

of the function module is set in stone; you have to have one import structure, two

tables parameters, and two defined exceptio ns. However, when you create the

function module, the system starts warning you that tables parameters are obsolete.

In this case, you have no choice; the function will no t work without tables

parameters, so you have to ignore the warning. (Maybe one day SAP will allow

189

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

Saved successfully!

Ooh no, something went wrong!