Hello,

Sign up to join our community!

Welcome Back,

Please sign in to your account!

Forgot Password,

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

You must login to ask a question.

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

SAP EWM Help Latest Questions

  • 0
  • 0
DPM125

How to create a number range object in BTP ?

In a RAP application, you usually expose business objects and services as OData APIs (consumed by Fiori apps or external systems).
Every business object instance (like Complaint, Sales Order, Request) needs a unique identifier (key field).

  • In SAP GUI-based classic apps, we often set the key in a TMG or via SNRO config.

  • In RAP, we don’t rely on GUI transactions → instead, we need to generate the ID programmatically when a new entity is created via the service.

That’s exactly what this class is doing:
👉 It creates a Number Range Object, sets up its intervals, and provides a method to fetch the next number.
So in a RAP app, you’d call this class (e.g., get_number) when you handle the CREATE operation of an entity.

 

CLASS zcl_numrng_demo DEFINITION
PUBLIC FINAL
CREATE PUBLIC.

PUBLIC SECTION.
INTERFACES if_oo_adt_classrun.

PRIVATE SECTION.
CONSTANTS gc_obj_id TYPE cl_numberrange_objects=>nr_attributes-object VALUE ‘ZNR_DEMO’.
CONSTANTS gc_package TYPE cl_numberrange_objects=>nr_attributes-devclass VALUE ‘ZDEMO_PKG’.
CONSTANTS gc_transport TYPE cl_numberrange_objects=>nr_attributes-corrnr VALUE ”.

METHODS create_obj
IMPORTING io_console TYPE REF TO if_oo_adt_classrun_out.

METHODS create_interval
IMPORTING io_console TYPE REF TO if_oo_adt_classrun_out.

METHODS get_number
IMPORTING io_console TYPE REF TO if_oo_adt_classrun_out.
ENDCLASS.

CLASS zcl_numrng_demo IMPLEMENTATION.
METHOD if_oo_adt_classrun~main.
create_obj( out ).
create_interval( out ).
get_number( out ).
ENDMETHOD.

METHOD create_obj.
TRY.
cl_numberrange_objects=>create(
EXPORTING attributes = VALUE #( object = gc_obj_id
domlen = ‘ZNR_DEMO_DOM’
percentage = 5
devclass = gc_package
corrnr = gc_transport )
obj_text = VALUE #( langu = ‘E’
object = gc_obj_id
txtshort = ‘Demo Numbers’
txt = ‘Demo Number Range Object’ )
IMPORTING errors = DATA(lt_err)
returncode = DATA(lv_ret) ).
CATCH cx_number_ranges INTO DATA(lo_ex).
io_console->write( lo_ex->get_text( ) ).
ENDTRY.

io_console->write( lt_err ).
io_console->write( lv_ret ).
ENDMETHOD.

METHOD create_interval.
TRY.
cl_numberrange_intervals=>create(
EXPORTING interval = VALUE #(
( nrrangenr = ’01’
fromnumber = ‘500000’
tonumber = ‘599999’
procind = ‘I’ ) )
object = gc_obj_id
IMPORTING error = DATA(lv_err)
error_inf = DATA(ls_err)
error_iv = DATA(lt_err_iv)
warning = DATA(lv_warn) ).

CATCH cx_root INTO DATA(lo_ex).
io_console->write( lo_ex->get_text( ) ).
ENDTRY.

io_console->write( lv_err ).
io_console->write( ls_err ).
io_console->write( lt_err_iv ).
io_console->write( lv_warn ).
ENDMETHOD.

METHOD get_number.
TRY.
cl_numberrange_runtime=>number_get(
EXPORTING nr_range_nr = ’01’
object = gc_obj_id
IMPORTING number = DATA(lv_num)
returncode = DATA(lv_rc) ).

CATCH cx_root INTO DATA(lo_ex).
io_console->write( lo_ex->get_text( ) ).
ENDTRY.

io_console->write( lv_num ).
io_console->write( lv_rc ).
ENDMETHOD.
ENDCLASS.

Related Questions

Leave an answer

Leave an answer