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)

Using a Custom Query

Next, you’ll add a method to your ZCL_MONSTER_MODEL that will input a monster

number and get the header structure and item table back. A model class should

never query the database directly; it should delegate that job to some sort of persistence

layer. However, don’t panic; that’s exactly what you’re going to do. Any

task that retrieves or updates the database will be outsourced to a specialist class,

which can then be mocked for the purposes of unit testing.

To reiterate, when the model class is created it either takes in a persistency layer

mock object as a parameter for unit testing or creates one itself that will do all the

BOPF-related stuff for real . The model will not know that the BOPF is handling

the database retrieval and updates.

There is a huge amount of debate about what to call the method that returns

something like a header record an d item table. You could call it QUERY, GET,

LOOKUP, or any of the wide variety of name s used by assorted BAPIs. You could

also go with the acronym CRUD (despi te the unfortunate connotations of the

word CRUD in some countries of the world), which stands for create, read,

update, and delete. Sometimes CRUD is expanded with the word retrieve instead

of read; indeed, the word retrieve is featured heavily in SAP documentation. Thus,

in this example, the method is called RETRIEVE (Figure 8.10).

Figure 8.10 Model Class: Retrieval Method Signature

Note

The monster model class passes on this method to an identical method in the ZCL_MON-

STER_MODEL_PERS_LAYER class, because model classes should never read the database

directly. This top-level method should give you an idea of what sort of thing is going on

and will call several lower-level methods that deal with the question of how.

296

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

Saved successfully!

Ooh no, something went wrong!