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)

Following the CRUD naming convention, the monster model class has CREATE and

UPDATE methods (Figure 8.29). The signature is exactly the same in both cases. The

method lives in the monster model class, which then instantly delegates it to an

identical method in the model persistency layer class.

Figure 8.29 Create and Update Methods Signature

Next you’ll learn how to code a method that uses BOPF to create a new record in

the database, and then how to code the method that updates existing records with

changed data. Typically, a business object is changed many times after it’s created.

Creating a New Record

Without further ado, it’s time for you to meet the code for creating a new monster

in the database. In Listing 8.19, the purpose of the method as a whole is to fill

an internal table with a list of the chan ges that you want to make. This is a very

generic structure, so you never pass in an actual structure or internal table;

instead, you pass in data references in several stages.

First, in the section starting with the comment Create Header Record, you add an

entry to the table of required “changes” (creating something is a change) for the

header record, the most important bit being to generate a new GUID. Then, you

do the exact same thing for the item tabl e. Every line needs a new key as well;

remember, the item lines are child nodes of the header record. Finally, in the section

that starts with the comment Here we go! , you pass all this data into two

helper methods: first, to update the data in memory (you can think of this as running

a BAPI in test mode if you want; I won’t tell anyone) and then, if all is well,

to update the actual database.

METHOD create_monster_record.

* Local Variables

DATA : lt_changes_to_be_made TYPE /bobf/t_frw_modification,

336

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

Saved successfully!

Ooh no, something went wrong!