Find your way to the BOPF

Last year I set a learning path to catch up with SAP development tools and techniques that in spite of being around for a while now, the comfort zone was just too comfortable to step out, until the breakthrough came in and I realized I didn’t want to be left behind. After one year things are starting to pay off now :), which is great.

In this opportunity, I want to talk about the Business Object Processing Framework (BOPF), which is yet another way of maintaining database records in an Object-Oriented way. Although this is a rather simplistic view, as it turns out that the framework is capable of doing many more things, such as dealing with authorizations, or even orchestrate the application business logic flow. It can be integrated with several UI technologies, say UI5 or Web Dynpro/FPM.

Following my last examples of modeling a Music Store inside SAP, I wanted to see how could I model this into a Business Object. So I ran my VM instance with the Developer Edition of SAP AS ABAP 751, opened Eclipse and created a new business object

Eclipse has this wizard ready to create BOs

I select the package and gave it a name. I’m taking a manual creation here, but we will see later on that is also possible to create BOs from ABAP CDS using some annotations, I’m curious on what is the end result, so I named this “MANUAL” and later on will compare this BO with one created from CDS to see the difference.

In the next screen, you are asked to define a persistent structure and a transient structure. The Persistent structure will be the definition of the database table, the transient structure are just fields that can be calculated at runtime, like master data details that you don’t wanna have duplicated in your database tables. For the sake of simplicity, I choose to create only a Persistent structure.

One very nice thing about ABAP 7.50 is that now we can define structures, data elements and domains from within Eclipse itself, bye bye SE11!

You don’t need to remember all of these annotations, there is code completion for each one of them.

The last step is to create a so-called Constants Interface. This is an auto-generated ABAP interface created by the framework, since as we will see shortly, the framework generates 32 characters (256 bits) hexadecimal identifiers, rather than plain number ranges or incremented integers. This interface makes easy to identify the BO

By clicking on the link Go to the ROOT node, an overview window displays what we can achieve with this BO

Here we can see the persistent structure defined in the wizard, also a combined structure, which is autogenerated by combining the persistent and transient structure. We also see a table type for this structure, and finally the database table that will be generated upon the activation of the BO. So by clicking the activate button, the database table will look like this:

Note that we didn’t define any DB_KEY field in the structure, it was inserted by the framework, every database table created via the BOPF will have this field marked as part of the key.

Now, going back to the BO overview -not the rote node overview, we can navigate to the nodes.

Business objects are organized in a hierarchical fashion through these nodes. At design time, we can think of a parent node and a child node as a relationship between Header and Item tables, for example. At runtime, nodes behave like internal tables grouping these instances together, and for which we can perform operations. In this case, I created a second BO, with a separate database table for managing the descriptions of my main instruments table.

OK, now that we have modeled our BOs, it’s time to play around with them through some ABAP code. We can manipulate the business objects through the BOPF API, that is composed of mainly 3 interfaces: The Service manager, that allow us to communicate with node elements, so we can execute queries, navigate through the hierarchy, perform actions, etc. There’s also the Transaction Manager, we use this interface to commit changes to the database, or even rollback changes. Then there is the configuration interface, which at this point I’m not entirely sure how to use it, but it seems that it is used to get the metadata from a BO -If anyone knows how to use it, I’m all ears.

So I start by getting some instances from the BOPF API factory class, note that for the Service Manager and object configuration, I pass the bo key that the framework generated for me in the constants interface, it feels nicer to refer to it as ZIF_BO=>SC_BO_KEY rather than 0800279DF3981ED7B18B0BBFE6C68691.

Then I create my root node structure, get a new key from the API factory, and populate my fields.

This next step is to append the child node to the modifications table, and create an association between them. So when I save, I will have a record in the Instrument table and another one in the texts table.

Now it’s time to save these changes in the memory, prior to commit the changes in the database.

Assigned tags

Related Blog Posts

Related Questions

Thank you so much for sharing, the new capabilities with 7.5 it seems ABAP is on fire now. I recently got chance to write a small application on BOPF in Solman and I really enjoyed it. May be because of lack of quality documentation people are scred to use it but it’s the easiest framework.

Well I’m far for being an expert in the matter. These posts respond to the fact that I’m just learning the technologies, and this process of doing and explaining what I’m trying to achieve really helps in the overall understanding on the subject. I also read a lot in this community, so there’s also a retribution aspect involved. Thank you for taking the time to read, stay tuned!

One thing I would note is that this technology is evolving very quickly i.e. with every new release of SAP there are somewhat radical changes to the BOPF.

Some people have a right go at me for having a “model class” where I have all my business logic, and then the actions / validations and so on in the BOPF business object outsource the function to my re-usable class. I also use that self same class in SEGW Gateway functions (DPC Class). Did you know thus very day I was told by someone within SAP to stop using the term “Gateway” as it was old fashioned? I should say rather “Frontend UI5 server” or some such, and then the name iwll change again next week.

The point is that these frameworks change so fast I feel I need another layer of abstraction as – amazingly – the underlying technology changes faster than the business requirements! That is backwards to what you might expect.

Moreover from what I saw at Teched the other day SAP has some sort of plan to use a “business definition language” to define BOPF behavior in the same way a CDS view can define database access behavior in an abstract way.