SAP

Manage my Account SAP Devs YouTube ↗ Learnings ↗ Community ↗ Provide Feedback ↗
Logout
⤢ Open full site

Execute an Outbound Service from Custom Business Object Logic

Call an external service of SAP Business Accelerator Hub from inside the logic implementation of a custom business object.

Overview

You will learn

  • How to get needed service data from SAP Business Accelerator Hub Sandbox
  • How to configure outbound service connection in SAP S/4HANA Cloud system
  • How to call and process an outbound service in custom business object logic

More from Peter Persiel

See all 9 tutorials by Peter Persiel →

Prerequisites

Prerequisites

  • Authorizations: Your user needs business role(s) with business catalogs Extensibility - Custom Business Objects (ID: SAP_CORE_BC_EXT_CBO), Communication Management (ID: SAP_CORE_BC_COM) and Extensibility - Custom Communication Scenarios (ID: SAP_CORE_BC_EXT_CCS) in your SAP S/4HANA Cloud system
  • Your user needs access to SAP Business Accelerator Hub.
  • Example Objects: Existence of custom business object Bonus Entitlement, refer to instructions below for Bonus Entitlement CBO.

Steps

Additional Info

  • The example application of Bonus Entitlement will be enhanced by a feedback functionality. The manager’s feedback will be translated automatically into English by calling the externally available service SAP Translation Hub of SAP.
  • Be aware that the example is done with the SAP Business Accelerator Hub Sandbox system only. This shall only give an idea on how it works and cannot be used productively.
  • Tutorial feasibility last checked with SAP S/4HANA Cloud Release 2608

Step 1 Prerequsite: Bonus Entitlement CBO

As a prerequisite, create another Custom Business Object Bonus Entitlement. Also refer to Part IV: Associated Business Objects (Bonus Entitlement with - Plan & Sales Order).

  • Business Object ID: YY1_BONUSENTITLEMENT
  • Enabled Features: Determination and Validation, User Interface, System Administrative Data
  • Nodes: BONUSENTITLEMENT
  • Fields:
    • Description, Type = Text with Length = 255
    • Calculation Start Date, Type = Date
    • Calculation End Date, Type = Date
    • Actual Revenue Amount, Type = Amount with Currency
    • Low Bonus Amount, Type = Amount with Currency
    • High Bonus Amount, Type = Amount with Currency
    • Total Bonus Amount, Type = Amount with Currency
    • Bonus Plan ID, Type = Numeric Identifier with Length = 10
  • Determination Logic (After Modification):
ABAP
DATA: bonusplan TYPE yy1_bonusplan.
DATA: bonusplan_id TYPE yy1_bonusplan-id.

IF bonusentitlement-bonusplanid IS INITIAL.
    RETURN.
ELSE.
    " get Bonus Plan
    SELECT *
    FROM yy1_bonusplan
    INTO @bonusplan
    WHERE id EQ @bonusentitlement-bonusplanid.
    ENDSELECT.

    " fill calculation period (should actually be done by plan when creating entitlement)
    bonusentitlement-calculationstartdate = bonusplan-validitystartdate.
    bonusentitlement-calculationenddate = bonusplan-validityenddate.

    " get completed Sales Orders for bonus plan's employee

    SELECT FROM i_salesorderitemcube( p_exchangeratetype = 'M', p_displaycurrency = @bonusplan-targetamount_c )
    FIELDS SUM( netamountindisplaycurrency )
    WHERE createdbyuser = @bonusplan-employeeid
        AND overallsdprocessstatus = 'C'
        AND creationdate BETWEEN @bonusplan-validitystartdate AND @bonusplan-validityenddate
    INTO @bonusentitlement-actualrevenueamount_v.

    bonusentitlement-actualrevenueamount_c = bonusplan-targetamount_c.

    " calculate minimum bonus
    IF ( bonusentitlement-actualrevenueamount_v / bonusplan-targetamount_v ) GT bonusplan-lowbonusassignmentfactor.
        bonusentitlement-lowbonusamount_v = bonusentitlement-actualrevenueamount_v * bonusplan-lowbonuspercentage_v / 100.
        bonusentitlement-lowbonusamount_c = bonusplan-targetamount_c.
    ELSE.
        CLEAR bonusentitlement-lowbonusamount_v.
        CLEAR bonusentitlement-lowbonusamount_c.
    ENDIF.

    " calculate maximum bonus
    IF ( bonusentitlement-actualrevenueamount_v / bonusplan-targetamount_v ) GT bonusplan-highbonusassignmentfactor.
        bonusentitlement-highbonusamount_v = ( bonusentitlement-actualrevenueamount_v - ( bonusplan-targetamount_v * bonusplan-highbonusassignmentfactor ) ) *  bonusplan-highbonuspercentage_v / 100.
        bonusentitlement-highbonusamount_c = bonusplan-targetamount_c.
    ELSE.
        CLEAR bonusentitlement-highbonusamount_v.
        CLEAR bonusentitlement-highbonusamount_c.
    ENDIF.

    " calculate total bonus
    bonusentitlement-totalbonusamount_v = bonusentitlement-lowbonusamount_v + bonusentitlement-highbonusamount_v.
    bonusentitlement-totalbonusamount_c = bonusplan-targetamount_c.

    DATA(actrevenue_s) = CONV string( bonusentitlement-actualrevenueamount_v ).
    DATA(target_s) = CONV string( bonusplan-targetamount_v ).
    DATA(lowf_s) = CONV string( bonusplan-lowbonusassignmentfactor ).
    DATA(lowp_s) = CONV string( bonusplan-lowbonuspercentage_v ).
    DATA(highf_s) = CONV string( bonusplan-highbonusassignmentfactor ).
    DATA(highp_s) = CONV string( bonusplan-highbonuspercentage_v ).

    CONCATENATE 'Bonus Run for Plan: ' bonusentitlement-bonusplanid
                ' with Target Amount: ' target_s
                ', Low Factor: ' lowf_s
                ', Low Percentage: ' lowp_s
                ', High Factor: ' highf_s
                ', High Percentage: ' highp_s INTO bonusentitlement-description SEPARATED BY space.
ENDIF.
  • Validation Logic (Before Save):
ABAP
valid = abap_false.

* check for consistency
DATA: bonusplan TYPE yy1_bonusplan.
DATA: bonusplan_id TYPE yy1_bonusplan-id.

IF bonusentitlement-bonusplanid IS INITIAL.
    message = 'No Bonus Plan set. Bonus calculation impossible.'.
    RETURN.
    ELSE.

    * check for uniqueness
    SELECT SINGLE @abap_true FROM yy1_bonusentitlement INTO @DATA(rv_exists) WHERE bonusplanid EQ @bonusentitlement-bonusplanid
    AND sap_createddatetime NE @bonusentitlement-sap_createddatetime.

    IF rv_exists EQ abap_true.
        CONCATENATE 'Bonus Entitlement for Bonus Plan ' bonusentitlement-bonusplanid 'already exists' INTO message SEPARATED BY space.
        RETURN.
    ELSE.

        " get Bonus Plan
        SELECT *
        FROM yy1_bonusplan
        INTO @bonusplan
        WHERE id EQ @bonusentitlement-bonusplanid.
        ENDSELECT.

        IF bonusplan IS INITIAL.
        CONCATENATE 'Bonus Plan ' bonusentitlement-bonusplanid 'does not exist. Bonus calculation impossible.' INTO message SEPARATED BY space.
        RETURN.
        ENDIF.

        message = 'Bonus calculated' .
        valid = abap_true.
    ENDIF.
ENDIF.
Step 2 Excursus - Try out the service in SAP Business Accelerator Hub
+
Step 3 Get service end point and API Key
+
Step 4 Create Communication System for Sandbox
+
Step 5 Create custom communication scenario for outbound service
+
Step 6 Create communication arrangement for outbound service
+
Step 7 Extend custom business object data structure
+
Step 8 Enhance custom business object logic
+
Step 9 Test the application
+
Step 10 Test yourself
+

Resources

Discussion

Share feedback on this tutorial or join the conversation in SAP Community.

Submit detailed feedback Discuss in Community
Steps
Step 1 of 10
1. Prerequsite: Bonus Entitlement CBO 2. Excursus - Try out the service in SAP Business Accelerator Hub 3. Get service end point and API Key 4. Create Communication System for Sandbox 5. Create custom communication scenario for outbound service 6. Create communication arrangement for outbound service 7. Extend custom business object data structure 8. Enhance custom business object logic 9. Test the application 10. Test yourself