Sie sind auf Seite 1von 16

Creating and Implementing Consistency Checks

in Business Object Builder


Summary
This tutorial shows how to create a consistency check for a
new field in a node of a BOPF Business Object. The tutorial
uses the Business Object Builder (BOB).

Level of complexity:
Time required for completion:

Author:
Company:
Created on:

Beginner
15 minutes

Thea Hillenbrand
SAP AG
15 January 2014

Creating and Implementing Consistency Checks in Business Object Builder

TABLE OF CONTENTS
BEFORE YOU START ...................................................................................................................................... 3
Objectives ......................................................................................................................................................... 3
Prerequisites .................................................................................................................................................... 3
Systems, Releases, and Authorizations ............................................................................................................ 3
Knowledge ......................................................................................................................................................... 4
ENHANCING THE STRUCTURE OF A BUSINESS OBJECT NODE ............................................................. 4
Procedure ......................................................................................................................................................... 4
Launch the Business Object Builder (BOB)....................................................................................................... 4
Launch the test tool ........................................................................................................................................... 6
Result ................................................................................................................................................................ 7
ADD A VALIDATION ........................................................................................................................................ 7
Prerequisites .................................................................................................................................................... 7
Procedure ......................................................................................................................................................... 7
Start the Wizard to Create Consistency Validations .......................................................................................... 7
Define Name and Description of the Validation ................................................................................................. 8
Define the Implementing Class .......................................................................................................................... 9
Define the Request nodes ............................................................................................................................... 10
Define the Behavior ......................................................................................................................................... 11
Finishing the wizard ......................................................................................................................................... 12
Implement the Validation ................................................................................................................................. 12
Result .............................................................................................................................................................. 14
TESTING THE VALIDATION .......................................................................................................................... 14
Procedure ....................................................................................................................................................... 14
Start Business Object Test Environment ......................................................................................................... 14
Create an instance of ZD_SALES_QUOTE .................................................................................................... 14
Result .............................................................................................................................................................. 15

Creating and Implementing Consistency Checks in Business Object Builder

BEFORE YOU START


Validating entered data is one of the core tasks of a back-end service. In BOPF these checks are registered
as validations at business object node level and implemented in an ABAP class.
Objectives
By the end of this tutorial, you will be able to
Enhance the structure of a business object node
Create a consistency validation
Implement a simple consistency validation based on the BOPF API
Test the new features of the business object.

Fig. 1: Structure of the Business Object to be enhanced

The tutorial starts with the business object created in the Getting Started with Business Object Processing
Framework. It consists of the ROOT node with minimal header information, like QUOTE_ID and the ITEM
node with position data like PRODUCT_ID, quantity and price information. The goal is to allow entering a
discount between 0 and 100 percent for each item. Therefore we need an additional field (DISCOUNT) in the
ITEM database table and a validation check for the item node (CHECK_DISCOUNT).
Prerequisites
To be able to perform the tutorial, make sure the following prerequisites are fulfilled.
Systems, Releases, and Authorizations
BOPF is part of the Business Suite Foundation Layer and, therefore, included in the following SAP
Business Suite releases:
SAP Business Suite EHP5, SP11
SAP Business Suite EHP6, SP05
SAP Business Suite EHP7, all SP

Creating and Implementing Consistency Checks in Business Object Builder

To create a consistency validation, your SAP user requires the developer authorization profile
(S_DEVELOP authorization object)
To implement this example, you need the business object created in the tutorial Getting started with
Business Object Processing Framework.
Knowledge
Basic knowledge in ABAP OO
Experience with DDIC tools
ENHANCING THE STRUCTURE OF A BUSINESS OBJECT NODE
In this step, you will enhance the ITEM node of the Business Object (BO) SALES_QUOTE. This Business
Object follows the semantics of the sales quote based on the NetWeaver Enterprise Procurement Model
(EPM).
Procedure
Launch the Business Object Builder (BOB)
Transaction BOB provides the design time for custom business objects as well as business object
enhancements.

Fig. 2: Welcome page of the BOB transaction in an SAP customer system

On the left side of the initial screen you see three categories of BOs that are currently available in your
system:
Custom Business Objects: BOs created by the customer in their system
SAP Business Objects: Extensible BOs that are delivered by SAP
Business Object Enhancement: BOs that are enhancements to an existing business object.
Select the Business Object ZD_SALES_QUOTE.

Creating and Implementing Consistency Checks in Business Object Builder

Fig. 3: SALES_QUOTE resulting from Getting started with Business Object Processing Framework

Select the node ITEM and navigate to the definition of the persistent structure ZDS_ITEM_D in the ABAP
data dictionary.

Fig. 4: ITEM node

In the ABAP Dictionary, switch to edit mode and add the new component DISCOUNT with the data type DEC
length 6 decimals 2. In an enhancement scenario, define the new component in an append structure.

Creating and Implementing Consistency Checks in Business Object Builder

Fig. 5: Define the additional component either directly in the DDIC structure or as Append Structure

Save and activate the definition. Then go back to the Business Object Builder.
Launch the test tool
Back in transaction BOB, choose the
Test button and start the BOPF test tool. Create a new sales quote instance by choosing the Add Node
Instance button on the ROOT node.

Fig. 6: Create the root node instance

Enter at least a QUOTE_ID and navigate to the ITEM node by choosing the navigation menu button.

Fig. 7: navigate to the item instance

You can now create an instance of the ITEM node by choosing the Add Node Instance button. The new
component DISCOUNT is visible and can be maintained.

Creating and Implementing Consistency Checks in Business Object Builder

Fig. 8: The ITEM node contains the component DISCOUNT

Enter the data for the item node. If you play with the data in the DISCOUNT field, you can enter decimal
values greater than 100 or even negative values. Introducing the consistency check will be the task of the
next step.
Result
You have now enhanced the original ITEM structure by the DISCOUNT field. You can enter data, and also
store and retrieve it.
ADD A VALIDATION
In this step we will enhance the BO item node by adding a consistency validation. Consistency validations
check whether a node instance is consistent with respect to the consistency criteria imposed by the business
requirements. If inconsistencies exist, consistency validations can return messages that should be displayed
to the user. In our case the business requirement is that the discount has to be between 0 and 100 percent
and that the BO instances accept only values in this interval.
Prerequisites
The ITEM node of the BO is opened in the configuration view of the Business Object Builder.
Procedure
Start the Wizard to Create Consistency Validations
Open the context menu of the ITEM node in the node browser pane. Select the entry Create Consistency
Validation. Press Continue to go to the first step.

Creating and Implementing Consistency Checks in Business Object Builder

Fig. 9: Create Consistency Validation

Define Name and Description of the Validation


In this step, you have to provide the validation name and you can define a short description.

Creating and Implementing Consistency Checks in Business Object Builder

Fig. 10: Name of the validation

The aim of this validation is to check the input in the field discount of the ITEM node of the sales quote. We
therefore name the validation CHECK_DISCOUNT.
Continue to the next step.
Define the Implementing Class
At runtime, a validation is represented by an ABAP class, implementing the validation interface. In this step
you are able to define the name of that class.

Creating and Implementing Consistency Checks in Business Object Builder

Fig. 11: Implementing the validation class

For this demo we wont change the proposed name, but instead continue with the next step.
Define the Request nodes
At runtime, we want the validation to be executed only when the user has changed the discount. Therefore
we have to define the condition for the validation to be triggered. In our example, DISCOUNT is an attribute
of the ITEM node and the check has to be called when the node is updated.
Mark the ITEM node and the checkbox for Create and Update. The validation should not be executed if the
node instance is deleted this is not necessary from a business point of view.

10

Creating and Implementing Consistency Checks in Business Object Builder

Fig. 12: Set the Trigger Conditions

Continue with the next step.


Define the Behavior
The standard behavior of a consistency validation is to send a message in the case of an error. The
message can be displayed on the UI to inform the user about the issue. If the error has a negative impact on
subsequent processes, you may want to prevent the user from saving the instance. In addition, there is a
third option for setting a certain status attribute (status variable) to inconsistent if the validation process finds
an error. Keep in mind that this option is only available in the context of enhancement BOs because the
definition of status attributes is currently not supported for Custom Business Objects.

11

Creating and Implementing Consistency Checks in Business Object Builder

Fig. 13: Define the Behavior of the Consistency Validation

As we have to assume in our scenario that the user will send the sales quote to the customer immediately
after having saved it, the data entered should be valid. So we set the radio button Return messages and
prevent saving.
Finishing the wizard
Finish the validation creation by choosing Complete. In the background, the system updates the BO
configuration and generates the implementing class of the validation.
Implement the Validation
The new validation is now visible in the Entity Browser pane of the BO configuration view. On the right, the
settings of the selected validation are shown. Double-click the name of the implementing class to navigate to
the class builder. Open the empty implementation of method /BOBF/IF_FRW_VALIDATION~EXECUTE and
provide the following source code.

method /BOBF/IF_FRW_VALIDATION~EXECUTE.
DATA lt_item
TYPE
zdt_item. " Combined table type
DATA lr_item
TYPE REF TO zds_item. " Combined structure type
DATA ls_incons_item_key LIKE LINE OF it_key.
DATA ls_error_location
TYPE /bobf/s_frw_location.
DATA lo_message
TYPE REF TO /bobf/cm_sepm_soq_messages.

12

Creating and Implementing Consistency Checks in Business Object Builder

io_read->retrieve(
EXPORTING
iv_node = zif_d_sales_quote_c=>sc_node-item
it_key = it_key
IMPORTING
et_data = lt_item ).
LOOP AT lt_item REFERENCE INTO lr_item
WHERE discount > 100 OR discount < 0.
" Collect the keys of the indonsistent item
ls_incons_item_key-key = lr_item->key.
APPEND ls_incons_item_key TO et_failed_key.
" Raise message
" 1.) Prepare error location info
ls_error_location-bo_key = zif_d_sales_quote_c=>sc_bo_key.
ls_error_location-node_key = zif_d_sales_quote_c=>sc_node-item.
ls_error_location-key = lr_item->key.
INSERT zif_d_sales_quote_c=>sc_node_attribute-item-discount
INTO TABLE ls_error_location-attributes.
" 2.) Create message
CREATE OBJECT lo_message
EXPORTING
textid
= /bobf/cm_sepm_soq_messages=>gc_invalid_discount_rate
severity = /bobf/cm_sepm_soq_messages=>co_severity_error
symptom = /bobf/if_frw_message_symptoms=>co_bo_inconsistency
ms_origin_location = ls_error_location.
" 3.) Add message to message object
if eo_message is NOT BOUND.
eo_message = /bobf/cl_frw_factory=>get_message( ).
ENDIF.
eo_message->add_cm( lo_message ).
ENDLOOP.
endmethod.
Hint: if you copy the source code directly into the ABAP editor, the formatting will be lost. Copying it into WordPad, on the
other hand, preserves at least the line breaks. This format can then be copied into the ABAP editor.

In most cases, the first step is to read the data of those node instances that need to be checked. For this
purpose, the RETRIEVE method of the Internal Access Object IO_READ can be used; it is provided by the
framework as an importing parameter. The keys of the node instances that need to be processed and thus
need to be read are handed over by another parameter called IT_KEY. To define the node from where we
want to read data, we use the appropriate constant from the Constants Interface of the BO. (Remember that
you have to use the specific Constance Interface of your business object that you created in the first task).
The result of the call is stored in a variable, typed with the Combined Table Type of the read node.
We execute the check for each item. If an item fails, we create a message and add it to the message object
EO_MESSAGE. As message class you can use the sample class of EPM
/BOBF/CM_SEPM_SOQ_MESSAGES. If the class does not exist in your system, create a new one, with
/BOBF/CM_FRW as the superclass.

13

Creating and Implementing Consistency Checks in Business Object Builder

When instantiating the message we provide not only a text and severity level, but also further information
about the actual error location. This data can be used by the UI to indicate the actual position of the
inconsistency to the user.
Activate your code and navigate back to the configuration view of the Business Object Builder.
Result
You are now finished with the implementation of the validation. The validation is always executed when the
user changes the items. It checks if the discount entered is between 0 and 100. The user cannot save the
item if the check fails.
TESTING THE VALIDATION
We are now going to test the validation.
Procedure
Start Business Object Test Environment
In the configuration view of BOB, choose the Test button in the toolbar.
Create an instance of ZD_SALES_QUOTE
In the Node Instance Table pane, select Add Node Instance from the toolbar and enter the header data.
Then navigate to the item node as described in the previous chapter. If you now enter invalid data, you get
an error message.

Fig. 14: Invalid discount

If you want to save the data, the framework prevents the save and sends an error message.

14

Creating and Implementing Consistency Checks in Business Object Builder

Fig. 15: Incorrect data cannot be saved

If you correct the data, the application message disappears and the framework saves the data.

Fig. 16: Correct data can be saved

Result
Within a few minutes we have verified that we have implemented the validation correctly, without writing any
test code. Of course, this does not replace an automated test, but with the help of the Business Object Test
Environment you get direct feedback as to whether your Business Object works correctly or not.
We have now gone through the fundamentals of creating and testing validations. I hope you are motivated to
try out more things with BOPF, as there is much more that can be discovered. Stay tuned for further articles
about our framework.

15

www.sap.com

2014 SAP AG. All rights reserved.


SAP, R/3, SAP NetWeaver, Duet, PartnerEdge, ByDesign, SAP
BusinessObjects Explorer, StreamWork, SAP HANA, and other SAP
products and services mentioned herein as well as their respective
logos are trademarks or registered trademarks of SAP AG in Germany
and other countries.
Business Objects and the Business Objects logo, BusinessObjects,
Crystal Reports, Crystal Decisions, Web Intelligence, Xcelsius, and
other Business Objects products and services mentioned herein as
well as their respective logos are trademarks or registered trademarks
of Business Objects Software Ltd. Business Objects is an SAP
company.
Sybase and Adaptive Server, iAnywhere, Sybase 365, SQL
Anywhere, and other Sybase products and services mentioned herein
as well as their respective logos are trademarks or registered
trademarks of Sybase Inc. Sybase is an SAP company.
Crossgate, m@gic EDDY, B2B 360, and B2B 360 Services are
registered trademarks of Crossgate AG in Germany and other
countries. Crossgate is an SAP company.
All other product and service names mentioned are the trademarks of
their respective companies. Data contained in this document serves
informational purposes only. National product specifications may vary.
These materials are subject to change without notice. These materials
are provided by SAP AG and its affiliated companies ("SAP Group")
for informational purposes only, without representation or warranty of
any kind, and SAP Group shall not be liable for errors or omissions
with respect to the materials. The only warranties for SAP Group
products and services are those that are set forth in the express
warranty statements accompanying such products and services, if
any. Nothing herein should be construed as constituting an additional
warranty.

Das könnte Ihnen auch gefallen