Académique Documents
Professionnel Documents
Culture Documents
Welcome, Guest
Login
Register
ABAP Development
In my previous two blog posts, we explored the BOPF API from a client point-of-view. Here, we learned how to perform basic CRUD operations, execute actions, and so on. Now that you have a feel for how the API operates, we're ready to take a peek behind the curtain and see these services are implemented within the business objects themselves. For now, our emphasis will be on enhancing these services since SAP does not yet support the creation of new business objects. However, whether we're enhancing existing business objects or creating new ones from scratch, the concepts remain the same.
What to Enhance?
postpost
Before we dive into the exploration of specific enhancement techniques, let's first take a look at the kinds of entities we're allowed to enhance in a business object. Aside from implicit enhancements applied to implementation classes using the Enhancement Framework, the types of entities that we can enhance within a business object are as follows: Custom Attributes For a given node, we might want to define a handful of additional custom attributes.These attributes could be persistent (i.e., they get appended to the target database table which contains the node data) or transient in nature. New Sub-Nodes In some cases, we may need to do more than simply define a few new attributes on an existing node. Using the relational data model as our guide, we may determine that a new sub-node is needed to properly model some new dimension of data (e.g. 1-to-many relations, etc.). Depending on the requirement, the sub-node(s) might be persistent or transient in nature. Determinations If we add new custom attributes to a given node, it stands to reason that we might also want to create a custom determination to manage these attributes. Or, we might have a standalone requirement which calls for some sort of "trigger" to be fired whenever a specific event occurs (e.g. fire an event to spawn a workflow, etc.). Consistency Validations If we are enhancing the data model of a business object, we might want to define a consistency validation to ensure that the new data points remain consistent. A custom validation might also be used to graft in a new set of business rules or a custom security model. Actions If we have certain operations which need to be performed on a business object, we would prefer to encapsulate those operations as an action on the business object as opposed to some standalone function module or class. Queries In some cases, the set of defined queries for a business object might not be sufficient for our needs. In these situations, we might want to define custom queries to encapsulate the selection logic so that we can use the generic query services of the BOPF API as opposed to some custom selection method.
scn.sap.com/community/abap/blog/2013/02/22/navigating-the-bopf-part-5--enhancement-techniques
1/7
12/3/13
You can find a detailed treatment of supported enhancement options in the BOPF Enhancement Workb ench Help documentation which is provided as a separate download in SAP Note #1457235. This document provides a wealth of information concerning the use of the BOPF Enhancement Workbench, enhancement strategies, and even the BOPF framework in general. Given the amount of detail provided there, I won't attempt to re-invent the wheel in this blog post. Instead, I'll simply hit on the high points and leave the nitty-gritty details to the help documentation.
All of the BOs which are eligible for enhancement will show up in the Enhancement Browser perspective of the BOPF Enhancement Workbench shown below. To create an enhancement, simply right-click on the BO that you wish to enhance and select the Create Enhancement menu option (see below). From here, the BOPF Enhancement Workbench will guide you through a wizard process which allows you to select the name of the enhancement object, the constants interface for the enhancement object, and so on.
scn.sap.com/community/abap/blog/2013/02/22/navigating-the-bopf-part-5--enhancement-techniques
2/7
12/3/13
Once the enhancement is created, you will be able to edit your enhancement object in the workbench perspective of the BOPF Enhancement Workbench shown below. As you can see, it has a similar look-and-feel to that of the normal BO browser tool (Transaction /BOBF/CONF_UI). From here, we can begin adding custom entities by right-clicking on the target node and selecting from the available menu options. We'll see how this works in the upcoming sections.
One final item I would draw your attention to with enhancement objects is the assigned constants interface (highlighted above). This constants interface can be used to access the enhancement object entities in the same way that the super BO's constants interface is used for BOPF API calls, etc.
For more complex data requirements, we typically need to define sub-nodes. This can be achieved by right-clicking on the parent node and selecting the Create Subnode menu option. This kicks off a wizard process in which you can select the sub-node's name, its persistent and/or transient structures, and the rest of the auto-generated dictionary
scn.sap.com/community/abap/blog/2013/02/22/navigating-the-bopf-part-5--enhancement-techniques
3/7
12/3/13
types which go along with a node definition (e.g. combined structure/table type, database table, etc.). Most of this is pretty standard stuff, but I would draw your attention to the step which creates the persistent and/or transient structures. Note that these structures must exist in the database b efore you move on from the Attributes step in the wizard process. And, in the case of the persistent structure, you must include the / B O B F / S _ A D M I Nstructure as the first component.
After the custom sub-node is created, you can fill out its attributes by adding components to the persistent/transient structures defined by the sub-node. If the sub-node is a persistent node, then we can create, modify, and retrieve node instances using the BOPF API as per usual. However, in the case of transient nodes, we need determinations to pre-fetch the data for us. We'll see how to define such determinations next.
Defining Determinations
According to the help documentation, determinations encapsulate internal changing business logic on a business object. Unlike the logic encapsulated in actions which can be triggered at any time, the business logic contained within determinations is triggered as specific times within the BO life cycle (e.g. right before a node is saved, etc.). So, in a way, it is appropriate to think of determinations as being a little bit like user exits/BAdIs/enhancement spots in that they provide a place to hang custom logic at particular points within the process flow. Once we determine (no pun intended) that we want to create a determination for a given node, we can do so by simply right-clicking on that node and selecting the Create Determination menu option. This will spawn a wizard which guides us through the process. Here, there are two main properties that we must account for: 1. Implementing Class: We must create or assign an ABAP Objects class that implements the / B O B F / I F _ F R W _ D E T E R M I N A T I O N interface. 2. Determination Pattern: This property defines the event which triggers the determination. As you can see below, the set of available patterns will vary depending on the type of node you're enhancing, its location in the node hierarchy, and so on. Once a pattern is selected, you may be presented with additional options for refining when an event is triggered. For example, if we select the pattern "Derive dependent data immediately after modification", we will have the opportunity to specify if the dependent data should be created/modified after any modification, only when the node is created the first time, etc.
scn.sap.com/community/abap/blog/2013/02/22/navigating-the-bopf-part-5--enhancement-techniques
4/7
12/3/13
Because determinations can be used for a lot of different things, they can be implemented in a lot of different ways. Here, it is very important that you pay close attention to selecting the right pattern for the right job. The aforementioned help documentation provides a good set of guidelines to assist here. Other valuable resources include the interface documentation for the / B O B F / I F _ F R W _ D E T E R M I N A T I O Ninterface in the Class Builder tool and SAP standarddelivered determinations implementations available in the system you're working on.
scn.sap.com/community/abap/blog/2013/02/22/navigating-the-bopf-part-5--enhancement-techniques
5/7
12/3/13
Once the action is created, we simply need to plug in the relevant logic in the defined implementation class. You can find implementation details for this in the interface documentation and/or sample action classes in the system. In order to create a pre/post action enhancement, the target action definition in the super BO must have its "Action Can Be Enhanced" flag set (see below). Assuming that the flag is set, then we can proceed through the corresponding wizard process in much the same way we would if we were creating a custom action from scratch. Indeed, as is the case with regular actions, the implementation class(es) for pre/post action enhancements must implement the / B O B F / I F _ F R W _ A C T I O Ninterface.
Before you go to implement a pre/post action enhancement, I would definitely recommend that you read through the help documentation so that you understand what you can and cannot do within an action enhancement. Most of the rules are intuitive, but you can definitely get into trouble if you abuse these enhancements by using them for things they weren't designed for.
scn.sap.com/community/abap/blog/2013/02/22/navigating-the-bopf-part-5--enhancement-techniques
6/7
12/3/13
From an implementation perspective, all of the query logic for a custom query gets encapsulated in the implementation class (which must implement the / B O B F / I F _ F R W _ Q U E R Yinterface). For the most part, you'll find that the framework doesn't really get in the way with regards to how we go about implementing the query. Basically, it passes in the query parameters up front and it's up to us to figure out how to find all of the node instances which match the given parameters. Here, we must pay careful attention to the SQL statements that we use since the query may be used extensively by a number of different clients.
Next Steps
Hopefully by now you have a general feel for how BOs are enhanced and the basic steps required to achieve these enhancements. As is the case with most programming-related subjects, the best way to really drive these concepts home is to look at live examples and experiment for yourself. I would also highly recommend that you read through the aforementioned help documentation as it devotes quite a bit of time to understanding when and where to apply specific enhancement techniques. In my next and final blog post in this series, I'll demonstrate another useful tool within the BOPF toolset: the BO test tool. This tool can be used to experiment with BOs and perform ad hoc unit tests, etc.
2011 View s
Share
Tw eet
0 Comments
There are no comments on this post
Copyright
Follow SCN
scn.sap.com/community/abap/blog/2013/02/22/navigating-the-bopf-part-5--enhancement-techniques
7/7