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.

8

Business Object Processing Framework (BOPF)

ASSIGN lrt_monster_items->* TO <lt_monster_items>.

et_monster_items = <lt_monster_items>.

ENDMETHOD.

"Retrieve Monster Record

Listing 8.2 Model Class Retrieval Method

You will note that due to the fully generic nature of the BOPF classes and methods,

you have to devote a lot of effort to converting generic data objects into

actual structures and tables you can work with directly.

You will also see that Listing 8.2 includes a call to an instance of a helper class.

Section 8.3.2 explains how best to wrap the generic BOPF classes and methods in

a more developer-friendly API, but for now anything monster-specific goes in the

monster model class (or its persistency-layer friend) and anything fully generic

goes into a reusable BOPF helper class; this helper class is named MO_BOPF_PL_

HELPER in the example code. This all means that how the data is retrieved is several

levels down from the monster model class. You now have a nice level of

abstraction, because it’s not the model’s concern how data is obtained; this helps

with unit testing.

Next, Listing 8.3 delves into the method that turns the monster number into a

key. You’re going to be using the quer y you defined earlier (Figure 8.9), which

enables you to do a search on the databasefor attributes other than the GUID key.

METHOD get_bopf_key_4_monster_number.

*---------------------------------------------------------------*

* IMPORTING id_monster_number TYPE ZDE_MONSTER_NUMBER

* RETURN rd_bopf_key TYPE /BOBF/CONF_KEY

*---------------------------------------------------------------*

* Local Variables

DATA : lt_parameters TYPE /bobf/t_frw_query_selparam,

lt_monster_keys TYPE /bobf/t_frw_key.

FIELD-SYMBOLS : <ls_parameter> LIKE LINE OF lt_parameters,

<ls_monster_keys> LIKE LINE OF lt_monster_keys.

* This builds the dynamic WHERE clause for the database read

APPEND INITIAL LINE TO lt_parameters ASSIGNING <ls_parameter>.

<ls_parameter>-attribute_name =

zif_monster_c=>sc_query_attribute-monster_header- select_monster_by_

attribute-monster_number.

<ls_parameter>-sign = 'I'.

<ls_parameter>-option = 'EQ'.

298

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

Saved successfully!

Ooh no, something went wrong!