So far, we have created two applications. One to maintain employee specific Bonus Plans and a second to entitle bonuses for an employee. Until now the Bonus Entitlement is only dependent on the net amount of completed sales orders, but at the Bonus Plan one can already maintain relevant products.
Task: Make use of custom fields.
Example: Custom Fields for Bonus Data at Product are used to calculate an additional product based bonus.
I) Having completed all preceding parts of SAP S/4HANA Extensibility Tutorial.
II) Having Sales Orders in the system for the employee of the bonus plan as creator. The sales Orders where created within the validity period of the bonus plan. Their sum of Net Amount is higher than 3000,- Euros (multiplication product of bonus plan’s Target Amount and High Bonus Assignment Factor) and consist of at least one product that is bonus relevant for the employee.
To be able to create Sales Order a user needs Business Catalog SAP_SD_BC_SO_PROC_MC.
To be able to complete Sales Orders a user needs Business Catalog SAP_LE_BC_ODLV_PROC_MC
Step 1: Enabling Custom Fields readability
The enablement of the Bonus fields in the Product UI, doesn’t offer a possibility to read their data in Custom Business objects yet. To achieve that, do the following
1. Start the Custom Fields and Logic application by clicking its tile
2. Search for the Bonus Fields and do the following points 3.-8. of Step 3 for each of them
3. Open the details by clicking the field’s list item
4. Go to “UIs and Reports”
6. “Enable Usage” for “Product active core entity”
7. Save the change.
8. Publish the field.
This has enhanced a CDS View with the field.
Hint: To see the CDS View name, open table Personalization via the action in the upper right corner
Check the “Data Source” Column and press OK to make that column visible in the table.
Now you can see the CDS View’s name “i_product” that you have to use to get the custom field data in logic implementations
Step 2: Enhancing Bonus Entitlement’s structure
All relevant products maintained at a bonus plan shall be considered at bonus calculation.
1. Start the Custom Business Object’s application by clicking its tile
2. Search for the Bonus Entitlement object and open its details by clicking its list item
3. Create a draft version to be able to do changes by executing “Edit Draft” action.
4. Go to Fields and Logic of the its one node.
5. Create following field
|field name||field properties||Tooltip|
|Product Bonus Amount||Amount|
8. Go back and publish.
Step 3: Enhancing Bonus Entitlement’s logic
1. “Go to Fields and Logic”
2. Enter the After Modification Event Logic
3. Implement following additional functionality:
- Get the relevant products from the bonus plan
Hint: The CDS view name for that sub node is yy1_relevantproduct_bonusplan and can be seen in Custom Business Object’s structure table by making the Data Source column visible.
Hint: The association between parental bonus plan and sub node data for relevant products is ensured by technical key fields. Every node has a field named sap_uuid, every sub node additionally has a sap_parental_uuid.
- For each product, check if it has a bonus percentage, if yes get the employee’s actual revenue from the completed Sales Orders that fulfill following conditions:
- created by the bonus plan’s employee
- in overall status “Completed”
- created in the validity period of the bonus plan
- created in the bonus validity period of the product
- with the current product (precondition is, that a sales order has only items of one and the same product)
Hint: You can read custom field data at the product via CDS View “i_product”
Hint: There is the CDS view I_SalesOrderItemCube with the parameters Exchange Rate (take ‘M’) and Display Currency (should be the one from bonus plan’s target amount). This view offers the netamountindisplaycurrency which does already currency conversion
Hint: You need following view field to restrict the results correctly:
- “overallsdprocessstatus” (value “C” stands for completed)
- If the net amount is greater than 0, calculate the product specific bonus
- Sum the product specific bonus to the bonuses of other products
- Add the product bonus amount to the total bonus amount
- Write a listing of products into the bonus entitlement’s description
" calculate product bonus DATA: relevantproducts TYPE TABLE OF yy1_relevantproduct_bonusplan. DATA: products_s TYPE string. DATA: productbonus TYPE i. DATA: products TYPE TABLE OF i_product. DATA: product LIKE LINE OF products. SELECT * FROM yy1_relevantproduct_bonusplan INTO TABLE @relevantproducts WHERE sap_parent_uuid EQ @bonusplan-sap_uuid. LOOP AT relevantproducts INTO DATA(relevant_product). " get net amount for product SELECT * FROM i_product INTO @product WHERE i_product~product = @relevant_product-productid. ENDSELECT. CONCATENATE products_s product-product INTO products_s SEPARATED BY ','. IF product-yy1_bonuspercentage1_prd GT 0. 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 AND creationdate BETWEEN @product-yy1_bonusvalid1tystart_prd AND @product-yy1_bonusvalidityend1_prd AND material = @relevant_product-productid INTO @bonusentitlement-productbonusamount_v. " if net amount for product greater 0, calculate its bonus IF bonusentitlement-productbonusamount_v GT 0. bonusentitlement-productbonusamount_v = bonusentitlement-productbonusamount_v * product-yy1_bonuspercentage1_prd / 100. productbonus = productbonus + bonusentitlement-productbonusamount_v. ENDIF. ENDIF. ENDLOOP. bonusentitlement-productbonusamount_v = productbonus. bonusentitlement-productbonusamount_c = bonusplan-targetamount_c. " calculate total bonus bonusentitlement-totalbonusamount_v = bonusentitlement-lowbonusamount_v + bonusentitlement-highbonusamount_v + bonusentitlement-productbonusamount_v. bonusentitlement-totalbonusamount_c = bonusplan-targetamount_c. " write bonus plan information into description DATA(employee_s) = CONV string( bonusplan-employeename ). 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 ' of Employee: ' employee_s ' with Target Amount: ' target_s ', Low Factor: ' lowf_s ', Low Percentage: ' lowp_s ', High Factor: ' highf_s ', High Percentage: ' highp_s ', Products: ' products_s INTO bonusentitlement-description SEPARATED BY space.
4. Publish the logic.
Step 4: Testing/ Creating Bonus Entitlement
1. Open the Bonus Entitlement application.
2. Create an object.
3. Enter following data
4. Save the Bonus Entitlement. All Data of the Entitlement will get filled, including the product based bonus.