Enterprise Resource Planning Blogs by SAP
Get insights and updates about cloud ERP and RISE with SAP, SAP S/4HANA and SAP S/4HANA Cloud, and more enterprise management capabilities with SAP blog posts.
cancel
Showing results for 
Search instead for 
Did you mean: 
ulrike_liebherr
Advisor
Advisor
So far, we created a custom business object “Bonus Plan” with simple data structure, initialization and check logic and application UI. This business object is there to save employee specific rules for bonus entitlement.

Task: Create your Custom Code List to be used in your custom Business Object

Example: A code list for release status shall be used in Bonus Plan to reflect if a Bonus Plan is still under work or ready for use.




Prerequisites


Having completed all preceding parts of SAP S/4HANA Extensibility Tutorial.




Step 1: Creating the Custom Code List


1. Open Custom Business Objects application

2. Switch to the Custom Code List view



3. Start Creation process of a Code List by clicking the "New" action.

4. Maintain following information for the new code list.

  • Name: "Release Status"

  • Maximum Code Length: 1

  • First new Code Value: Code: 1, Description: "Not Released"

  • Second new Code Value: Code: 2, Description: "Released"




5. Execute action "Save and Publish"




Step 2: Enhancing Bonus Plan structure


To make use of this new code list, you first have to add it to the structure of the Bonus Plan Business Object.

1. Go back in Custom Business Objects application and switch to Custom Business Objects view.

2. Open "Bonus Plan".

3. Press "Edit Draft" action.

4. "Go to Fields and Logic".

5. Click the "New" field action.

6. Name the new field "Release Status".

7. Switch its Type to "Code List".

8. In the Code List field start typing yy1_releasestatus until the value help offers the right name to choose easily.



9. Go back inside the application and publish the Bonus Plan definition.




Step 3: Enhancing Bonus Plan logic


After having added it to the Business Object structure, also the business logic has to deal with it.
In the After Modification Event we want to find out if end user just set the bonus plan to "Released" and ensure that bonus plan's consistency allows to leave this end user change.

After Modification Event

1. In Custom Business Object application view on Bonus Plan "Go to Fields and Logic".

2. Open After Modification Event in Determination Logic.

3. Create a Draft implementation.

4. Implement following functionality:
General:
Set ReleaseStatus to “1” (Not Released) if still initial.
* set release status initially
IF bonusplan-releasestatus IS INITIAL.
bonusplan-releasestatus = '1'.
ENDIF.

5. Publish the logic

6. Go back

Before Save Event

1. In Custom Business Object application view on Bonus Plan "Go to Fields and Logic".

2. Open Before Save Event in Validation Logic.

3. Create a Draft implementation.

4. Implement following functionality:
Save rejection shall no longer be dependent on consistency but on release status.
Hint: Exporting parameter valid must be set to true for save and to false for save rejection

  • A consistent bonus plan which just shall get released, can be saved.

  • An inconsistent bonus plan which just shall get released, shall be set to "Not Released" by end user again and made consistent first.
    Hint: The release status from before current changes can be read from database

  • Changing and therefore saving an already released bonus plan is not allowed.

  • A bonus plan in status "Not Released" can be saved, but first consistency error shall be given back as information.
    Hint: Exporting parameter message gets automatically an information only if save is not rejected. (valid = abap_true)


* decide about save rejection
IF bonusplan-releasestatus EQ '2'.
SELECT SINGLE ( releasestatus ) FROM yy1_bonusplan INTO @DATA(releasestatus_db) WHERE id = @bonusplan-id.
IF releasestatus_db NE '2'.
IF bonusplan-isconsistent EQ abap_true.
valid = abap_true.
message = 'Bonus Plan released successfully.'.
ELSE.
valid = abap_false.
message = 'Bonus Plan is inconsistent and cannot be released. Set it back to "Not Released" and solve inconsistencies first.'.
ENDIF.
ELSE.
valid = abap_false.
message = 'Bonus Plan was already released before. Changes are forbidden and saving is not possible.'.
ENDIF.
RETURN.
ELSE.
valid = abap_true.
ENDIF.

* consistency check START
* same code as in Tutorial Part II following

5. Publish the logic




Step 3: Testing


1. Open the Bonus Plan application

2. Open the Bonus Plan, created in Part I tutorial

3. Execute the “Edit” action to start editing.

4. Delete the Target Amount value.

5. Save the Bonus Plan. Save succeeds, but brings Warning due to missing Target Amount.

6. Enter Edit mode again.

7. Choose Release Status "Released".

8. Save the Bonus Plan. Save fails due to release status change while having the inconsistency of a missing target amount.

9. Enter Target Amount 1000 again.

10. Save the Bonus Plan. Save succeeds.
2 Comments