You will learn

In the preceding tutorial you created a custom business object, its simple data structure, persistence and application UI.Data could only be provided by the UI. Now you’ll implement logic to set some data from the backend only and to check all data of an instance.You will also learn how to ease development and test already while doing it.

Details

At the end your application will set some data automatically and reject a save with an error message for the causing inconsistencies.

ExampleA several tutorials spanning example will show extensibility along custom Bonus Management applications.

In the first parts a Manager wants to define business objects “Bonus Plan” for employees. A Bonus Plan is there to save employee specific rules for bonus entitlement.

Step 1: Make key field Read-Only

As there was no backend implementation to set the mandatory key field ID so far, we were forced to set it from the UI to be able to save instances.Now, as we will implement the logic to set the ID in backend and nowhere else, we will set that key field to Read-Only for the UI.

1. Open the business object Bonus Plan in Custom Business Objects application2. Start Edit Mode by executing the Edit Draft action.3. Go to Fields and Logic.4. Check the Read-Only box for key field ID.5. Go back via the application’s Back button.

1. Still editing the custom business object Bonus Plan’s definition, Check the box for Determination and Validation2. Publish the business object definition.

Now you are enabled to implement determination logic which is called after each modification to a Bonus Plan instance from the UI, as well as validation logic which is called before each save of an instance.

For published Custom Business Objects without a Draft version you can implement logic.

Go to Fields and Logic

Enter the After Modification Event Logic which is a Determination Logic.

In the logic view you initially see the not editable empty published version.Click the Create Draft action.An editable copy of the published version appears left to it. With the Draft Version and Published Version actions you can decide what coding to see.

Implement After Modification event with following fix value functionality:

Set the key field ID if still initial.

Hint: Changing Parameter bonusplan enables you to read current node data and change it.Hint: You can read existing Bonus Plan data via the CDS View that is named as the Business Object’s Identifier (here: YY1_BONUSPLAN).Hint: With the key combination CTRL + Space you can access the very helpful code completion.

On top of the coding you can maintain runtime data for the current node structure which represents the data before running the test functionality. This data can also be saved as variant for later usages.

Click the value help to add test data

Enter following data

Field Name

Field Value

validitystartdate

2017-01-01

validityenddate

2017-12-31

targetamount_v

1000

targetamount_c

EUR

lowbonusassignmentfactor

1

highbonusassignmentfactor

3

lowbonuspercentage

10

highbonuspercentage

20

employeeid

<any>

employeeid<any> shall be the one of a sales person that created sales orders with a Net Amount of more than 3000.00 EUR in 2016 and that are completed.

This will look as follows.

Execute the Test action and you can see the node data after your logic was executed.You can see that your logic works as id, *percentage_u fields and employename are filled and isconsistent is ‘X’.