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.

B

Making Programs Flexible

TRY.

CALL METHOD zcl_bc_gpc=>get_multi_vals_by_soe

EXPORTING

iv_parameter = pud_paramater

iv_char = pud_char

iv_vkorg = p_vkorg

CHANGING

et_values = pt_values[].

* Error Handling

CATCH zcx_ai_application_fault INTO lo_fault.

CALL METHOD lo_fault->error_log->show_error_log.

ENDTRY.

In the preceding example, the user has entered the sales organization on the initial

screen, and a class is created to read from the table. This code will try several strategies

to get the value (starting with the sales organization entered, then trying the

company code based on the sales organiza tion, then the country based on clues

from the organizational elements, and then the user master record if all else fails).

Finally, it will look for a default entry (i.e., one for which no organizational elements

at all are specified). (If everything fails, then this is an exception situation.)

The range of values is put into a global range in a procedural program or a private

range in an OO program. What benefit do you get from this? Say that you wanted

to keep a program the same across vari ous different SAP systems so that you

could easily move updates from the ma ster system to subsidiary systems. Normally,

you would have to write something like the following:

IF ( ld_land = 'DE' AND ld_monster_type = '4321' ) OR

( ld_land = 'AU' AND ld_monster_type = 'MSTR' ) OR

( ld_land = 'GB' AND ld_monster_type = 'P45X' ) OR

( ld_land = 'US' AND ld_monster_type = 'ZZT5' ).

PERFORM something.

ENDIF.

The normal way to avoid the situation in the preceding exampl e is to have four

different versions of the program, each one changing the routine to something

like this:

IF ld_monster_type = 'ZZT5'.

PERFORM something.

ENDIF.

716

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

Saved successfully!

Ooh no, something went wrong!