Create a number range for a document type

This page describes a sample business scenario for creating custom number ranges, and how such an extension is possible on SAP S/4HANA Cloud.

Sample Scenario

Your organization maintains documents for a fiscal year in the format YYYYNumberRange, for example 201900001, 201900002 and so on. The number range formats available in the standard system might not suit the format required by your organization. In such a scenario, you can use the Extensibility concepts of SAP S/4HANA Cloud to generate custom number ranges for the different business objects in the system. The generated numbers consist of two parts: a prefix and a number, both of which are configurable by a key user.

A new custom number range is generated with the help of custom logic. The Extensibility Catalog provides the Custom Business Objects app, with options to include a custom logic for Before Save and After Modify events. You use this extensibility feature to extend the standard solution and generate number ranges in a custom format.

For this extension, you would need two custom business objects. One to maintain the characteristics or properties of the number range, and the other to generate number ranges. This means that in one custom business object, you define the properties of the custom number range and in the other custom business object, you use or consume the number range that was defined in the first business object.

Note: Information provided on this page is as per features available on SAP S/4HANA Cloud release 1905. There might be variations to screen and field names in other release versions.

Prerequisites

  • You have administrative access to SAP S/4HANA Cloud.
  • You have implementation experience on SAP S/4HANA Cloud.
  • You have coding experience, since this extensibility solution requires implementation of coding logic.
  • Extensibility app is available on your system.

Authorizations

AreaBusiness Role ID
Extensibility
SAP_ BC _ CORE _ EXT

SAP S/4HANA Cloud Launchpad - > Extensibility -> Custom Business Object App


Create Custom Business Object to Define Properties of the Custom Number Range

  1. Create a business object to maintain number ranges.
  2. Define fields of the custom business object. Some relevant fields for the number range would be the code (ID of the number range) start number, current number, prefix and suffix.

Reference: Custom Business Objects on help.sap.com -> SAP S/4HANA Cloud - > Extensibility -> Custom Business Object.

Create Action to Increment Numbers in the Custom Number Range

  1. Open your custom business object in the edit mode.
  2. Click on the Logic tab.
  3. Specify the GetNextNumber action label and identifier.
  4. Publish the action.
  5. Open the newly published action in the edit mode.
  6. Enter a logic to increment the numbers in the number range in the draft logic section.
  7. Publish your custom business object.

Reference: References and Code Samples on help.sap.com -> SAP S/4HANA Cloud - > Extensibility -> Custom Business Object -> Code Samples to Write Data from Determinations or Actions to Custom Business Objects.

Create a New Number Range

  1. Open your Custom Business Object in the edit mode.
  2. Add a new custom number range.
  3. Specify relevant field data.

Implement Logic to Consume Custom Number Range in a Custom Business Object

  1. Create a new Custom Business Object. While creating the new custom business object, note that the field ID is a key field and it holds the number generated in the desired number range. The Name field holds the name of the generated ID. Features such as the Determination and Validation, UI Generation, Service Generation and System Administrative Data on the General Information tab are the other relevant information that needs to be input.

    • Note: You can also use an existing custom business object to implement the logic.
  2. Publish the new Custom Business Object.
  3. Implement logic in the custom business object:

    • Declare the variables that will be used in the logic implementation. The following variables are required:

      • Local variable of type of the key of the custom number range object.
      • Local structure of type of the instance of custom number range object.
      • Local variable of length 10, type char, that is used to hold the current number.
      • Local variables of timestamp type, used for the start time, end time, target waiting time and waiting time measurement.
    • Set the values of the target duration, locked variable and start time.
    • By setting the value of the lv_locked to X, the system considers the object as locked.
    • Execute the number range generation, for example, if the value of lv_locked has not changed and the waiting time is less than 200 milliseconds.