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.

Making Programs Flexible

B

This approach can also be used for the “magic numbers”—for example, you have

a variable that is typed as the st andard SAP data element for dates DATUM. You

would firstly want to give that variable a meaningful name, like Maximum

Annual Holidays. Then at runtime you would programmatically fill the value of

that variable, which would be 30 in Germany and 21 in Australia.

Magic Numbers

A magic number is a number that appears in a program seemingly for no logical reason.

For example, you may see code that says th at, “If variable XYZ is greater than 65. do

something; otherwise, do something else.” Naturally, you would think to yourself,

“What is so wonderful about 65?”

If, instead, the code said, “I f variable XYZ is greater than RETIREMENT_AGE, do something;

otherwise, do something else” then suddenly things make a lot more sense.

Moreover if the retirement age ever changes, it is easier to search code for an English

phrase than the number 65, as the numeric value could pop up for all sorts of other reasons.

Now, you need to ascertain the correct value. In some programs, you can set the

organizational elements based on what th e user enters on an initial screen—for

example, the select options for a report program or the sales organization for a

dialog transaction, like VA01. Sometimes, this option isn’t available, but at a minimum

you can usually get the country from the user’s master record: The default

time zone is usually a dead giveaway as to what country the user is in.

As soon as you know the organizational element (or straight away if that isn’t relevant),

your program will call a routine called something like READ_GLOBAL_CUS-

TOMIZING, which will set all such values needed by the logic in the program. This

could be in a constructor for an object —for example, the code below could be

inserted into a constructor method:

PERFORM get_customizing_range :

USING 'YDE_VC_MONSTER_TYPE' 'STANDARD_MONSTER'

CHANGING gr_standard_monster[],

USING 'YDE_VC_MONSTER_TYPE' 'EXTRA_SCARY_MONSTER'

CHANGING gr_extra_scary_monster[].

The vast majority of the time, you’ll want the values in a range, even if you only

have one value at the moment, because you never know when more values are

going to be added further down the trac k. In the example below, you see what

would be code in the GET_CUSTOMIZING_RANGE; namely, a call to a method that will

fill up the values in the range based on organizational-element–specific rules.

715

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

Saved successfully!

Ooh no, something went wrong!