Top Banner

of 16

Creating and Implementing Consistency Checks in Business Object Builder

Feb 13, 2018

Download

Documents

Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
  • 7/23/2019 Creating and Implementing Consistency Checks in Business Object Builder

    1/16

    Creating and Implementing Consistency Checksin Business Object Builder

    SummaryThis tutorial shows how to create a consistency check for anew field in a node of a BOPF Business Object. The tutorial

    uses the Business Object Builder (BOB).

    Author: Thea HillenbrandCompany: SAP AGCreated on: 15 January 2014

    Level of complexity: BeginnerTime required for completion: 15 minutes

  • 7/23/2019 Creating and Implementing Consistency Checks in Business Object Builder

    2/16

    Creating and Implementing Consistency Checks in Business Object Builder

    2

    TABLE OF CONTENTS

    BEFORE YOU START ...................................................................................................................................... 3Objectives ......................................................................................................................................................... 3Prerequisites .................................................................................................................................................... 3Systems, Releases, and Authorizations ............................................................................................................ 3

    Knowledge ......................................................................................................................................................... 4

    ENHANCING THE STRUCTURE OF A BUSINESS OBJECT NODE ............................................................. 4

    Procedure ......................................................................................................................................................... 4Launch the Business Object Builder (BOB)....................................................................................................... 4Launch the test tool ........................................................................................................................................... 6

    Result ................................................................................................................................................................ 7

    ADD A VALIDATION ........................................................................................................................................ 7

    Prerequisites .................................................................................................................................................... 7

    Procedure ......................................................................................................................................................... 7Start the Wizard to Create Consistency Validations .......................................................................................... 7

    Define Name and Description of the Validation ................................................................................................. 8Define the Implementing Class .......................................................................................................................... 9Define the Request nodes ............................................................................................................................... 10

    Define the Behavior ......................................................................................................................................... 11

    Finishing the wizard ......................................................................................................................................... 12Implement the Validation ................................................................................................................................. 12Result .............................................................................................................................................................. 14

    TESTING THE VALIDATION .......................................................................................................................... 14

    Procedure ....................................................................................................................................................... 14

    Start Business Object Test Environment ......................................................................................................... 14Create an instance of ZD_SALES_QUOTE .................................................................................................... 14

    Result .............................................................................................................................................................. 15

  • 7/23/2019 Creating and Implementing Consistency Checks in Business Object Builder

    3/16

    Creating and Implementing Consistency Checks in Business Object Builder

    3

    BEFORE YOU START

    Validating entered data is one of the core tasks of a back-end service. In BOPF these checks are registeredas validationsat 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 ProcessingFramework. It consists of the ROOT node with minimal header information, like QUOTE_ID and the ITEMnode with position data like PRODUCT_ID, quantity and price information. The goal is to allow entering adiscount between 0 and 100 percent for each item. Therefore we need an additional field (DISCOUNT) in theITEM 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.

    System s, Releases, and Au thorizations

    BOPF is part of the Business Suite Foundation Layer and, therefore, included in the following SAPBusiness Suite releases:

    SAP Business Suite EHP5, SP11

    SAP Business Suite EHP6, SP05

    SAP Business Suite EHP7, all SP

  • 7/23/2019 Creating and Implementing Consistency Checks in Business Object Builder

    4/16

    Creating and Implementing Consistency Checks in Business Object Builder

    4

    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 withBusiness 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 Bu siness Object Bui lder (BOB)

    Transaction BOB provides the design time for custom business objects as well as business objectenhancements.

    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 yoursystem:

    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.

  • 7/23/2019 Creating and Implementing Consistency Checks in Business Object Builder

    5/16

    Creating and Implementing Consistency Checks in Business Object Builder

    5

    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_Din the ABAPdata dictionary.

    Fig. 4: ITEM node

    In the ABAP Dictionary, switch to edit mode and add the new component DISCOUNT with the data typeDEClength6 decimals2. In an enhancement scenario, define the new component in an append structure.

  • 7/23/2019 Creating and Implementing Consistency Checks in Business Object Builder

    6/16

    Creating and Implementing Consistency Checks in Business Object Builder

    6

    Fig. 5: Define the additional componenteither 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 NodeInstance buttonon 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 Instancebutton. The newcomponent DISCOUNT is visible and can be maintained.

  • 7/23/2019 Creating and Implementing Consistency Checks in Business Object Builder

    7/16

    Creating and Implementing Consistency Checks in Business Object Builder

    7

    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 decimalvalues greater than 100 or even negative values. Introducing the consistency check will be the task of thenext step.

    Result

    You have now enhanced the original ITEM structure by the DISCOUNT field. You can enter data, and alsostore and retrieve it.

    ADD A VALIDATION

    In this step we will enhance the BO item node by adding a consistency validation. Consistency validationscheck whether a node instance is consistent with respect to the consistency criteria imposed by the businessrequirements. If inconsistencies exist, consistency validations can return messages that should be displayedto the user. In our case the business requirement is that the discount has to be between 0 and 100 percentand 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 Cons istency Validation s

    Open the context menu of the ITEM node in the node browser pane. Select the entry Create ConsistencyValidation. Press Continueto go to the first step.

  • 7/23/2019 Creating and Implementing Consistency Checks in Business Object Builder

    8/16

    Creating and Implementing Consistency Checks in Business Object Builder

    8

    Fig. 9: Create Consistency Validation

    Define Name and Descript ion o f the Validation

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

  • 7/23/2019 Creating and Implementing Consistency Checks in Business Object Builder

    9/16

    Creating and Implementing Consistency Checks in Business Object Builder

    9

    Fig. 10: Name of the validation

    The aim of this validation is to check the input in the field discountof the ITEM node of the sales quote. Wetherefore name the validation CHECK_DISCOUNT.

    Continue to the next step.

    Define the Imp lementing Class

    At runtime, a validation is represented by an ABAP class, implementing the validation interface. In this stepyou are able to define the name of that class.

  • 7/23/2019 Creating and Implementing Consistency Checks in Business Object Builder

    10/16

    Creating and Implementing Consistency Checks in Business Object Builder

    10

    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. Thereforewe have to define the condition for the validation to be triggered. In our example, DISCOUNT is an attributeof the ITEM node and the check has to be called when the node is updated.

    Mark the ITEM node and the checkbox for Createand Update. The validation should not be executed if the

    node instance is deletedthis is not necessary from a business point of view.

  • 7/23/2019 Creating and Implementing Consistency Checks in Business Object Builder

    11/16

    Creating and Implementing Consistency Checks in Business Object Builder

    11

    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. Themessage can be displayed on the UI to inform the user about the issue. If the error has a negative impact onsubsequent processes, you may want to prevent the user from saving the instance. In addition, there is athird option for setting a certain status attribute (status variable) to inconsistent if the validation process findsan error. Keep in mind that this option is only available in the context of enhancement BOs because thedefinition of status attributes is currently not supported for Custom Business Objects.

  • 7/23/2019 Creating and Implementing Consistency Checks in Business Object Builder

    12/16

    Creating and Implementing Consistency Checks in Business Object Builder

    12

    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 immediatelyafter having saved it, the data entered should be valid. So we set the radio button Return messages andprevent saving.

    Finishing the w izard

    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, thesettings of the selected validation are shown. Double-click the name of the implementing class to navigate tothe class builder. Open the empty implementation of method/BOBF/IF_FRW_VALIDATION~EXECUTEandprovide 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.

  • 7/23/2019 Creating and Implementing Consistency Checks in Business Object Builder

    13/16

    Creating and Implementing Consistency Checks in Business Object Builder

    13

    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 theother 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 thispurpose, the RETRIEVE method of the Internal Access Object IO_READ can be used; it is provided by theframework as an importing parameter. The keys of the node instances that need to be processed and thusneed to be read are handed over by another parameter called IT_KEY. To define the node from where wewant to read data, we use the appropriate constant from the Constants Interface of the BO. (Remember thatyou 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 objectEO_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.

  • 7/23/2019 Creating and Implementing Consistency Checks in Business Object Builder

    14/16

    Creating and Implementing Consistency Checks in Business Object Builder

    14

    When instantiating the message we provide not only a text and severity level, but also further informationabout the actual error location. This data can be used by the UI to indicate the actual position of theinconsistency 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 theuser changes the items. It checks if the discount entered is between 0 and 100. The user cannot save theitem if the check fails.

    TESTING THE VALIDATION

    We are now going to test the validation.

    Procedure

    Star t Bus iness Object Test Environm ent

    In the configuration view of BOB, choose the Testbutton in the toolbar.

    Create an instan ce of ZD_SALES_QUOTE

    In the Node Instance Table pane, select Add Node Instancefrom 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 getan error message.

    Fig. 14: Invalid discount

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

  • 7/23/2019 Creating and Implementing Consistency Checks in Business Object Builder

    15/16

    Creating and Implementing Consistency Checks in Business Object Builder

    15

    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 anytest code. Of course, this does not replace an automated test, but with the help of the Business Object TestEnvironment 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 totry out more things with BOPF, as there is much more that can be discovered. Stay tuned for further articlesabout our framework.

  • 7/23/2019 Creating and Implementing Consistency Checks in Business Object Builder

    16/16

    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 Germanyand 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 materialsare provided by SAP AG and i ts 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.

    www sap com