天天看點

使用SAP C4C自定義BO實作自定義的Number Range

My series of Cloud Application Studio Blogs

How to detect EditMode in an Embedded Component

Step by step to enable your custom BO with attachment upload functionality

Step by step to create an Adobe Print form in Cloud application Studio

How to render PDF which displays picture from the image attachment of your custom BO

How to get current logged on business user’s employee information and assigned organization unit via ABSL

How to implement dynamic access control based on custom BO using OWL

How to make Code List Restriction work when control field and restricted field are not on the same BO

How to implement custom number range using custom business object

Two approaches to create Code List in Cloud Studio

In On-Premise world customer could use transaction code SNRO to create and maintain their custom number range object and consume via function module NUMBER_GET_NEXT.

使用SAP C4C自定義BO實作自定義的Number Range
使用SAP C4C自定義BO實作自定義的Number Range

In C4C it is not possible to use this backend approach for partner. In this blog a simple approach is introduced which fulfill the custom number range by leveraging custom Business object developed via Cloud studio.

Here below is what I have achieved:

(1) Every time a new Custom transaction BO is created, the new ID is automatically populated by the Number Range Business Object. This behavior is exactly the same as the one in On-Premise world.

使用SAP C4C自定義BO實作自定義的Number Range
使用SAP C4C自定義BO實作自定義的Number Range
使用SAP C4C自定義BO實作自定義的Number Range

(2) The current number interval is stored via an instance of Number Range object, which means even if you log off and log on system again, the current number range interval is loaded from backend persistence, instead of starting from scratch.

Detail implementation of this solution

(1) Create a Custom BO in Cloud Studio and paste the following source code:

使用SAP C4C自定義BO實作自定義的Number Range

2) Implement action InitializeInstance. Here I hard code the max number as 999999999.

使用SAP C4C自定義BO實作自定義的Number Range

(3) Implement action GenerateNextNumber. The logic is a simplified version of the good old function module NUMBER_GET_NEXT.

使用SAP C4C自定義BO實作自定義的Number Range
使用SAP C4C自定義BO實作自定義的Number Range

(4) In your transaction custom BO, consume the function exposed by Number Range BO in AfterModify.absl.

Here I hard code the number range prefix as “JerryBO”. You can for sure even use different prefix based on for example different transaction type of your custom BO.

使用SAP C4C自定義BO實作自定義的Number Range

繼續閱讀