{"id":7570,"date":"2025-08-24T01:39:01","date_gmt":"2025-08-23T20:09:01","guid":{"rendered":"https:\/\/www.sapewmhelp.com\/?question=how-to-create-a-number-range-object-in-btp"},"modified":"2025-08-24T01:39:01","modified_gmt":"2025-08-23T20:09:01","slug":"how-to-create-a-number-range-object-in-btp","status":"publish","type":"question","link":"https:\/\/www.sapewmhelp.com\/?question=how-to-create-a-number-range-object-in-btp","title":{"rendered":"How to create a number range object in BTP ?"},"content":{"rendered":"<p>In a <strong>RAP application<\/strong>, you usually expose business objects and services as <strong>OData APIs<\/strong> (consumed by Fiori apps or external systems).<br \/>Every business object instance (like <em>Complaint<\/em>, <em>Sales Order<\/em>, <em>Request<\/em>) needs a <strong>unique identifier (key field)<\/strong>.<\/p>\n<ul>\n<li>\n<p>In SAP <strong>GUI-based classic apps<\/strong>, we often set the key in a TMG or via SNRO config.<\/p>\n<\/li>\n<li>\n<p>In <strong>RAP<\/strong>, we don\u2019t rely on GUI transactions \u2192 instead, we need to generate the ID <strong>programmatically<\/strong> when a new entity is created via the service.<\/p>\n<\/li>\n<\/ul>\n<p>That\u2019s exactly what this class is doing:<br \/>\ud83d\udc49 It creates a <strong>Number Range Object<\/strong>, sets up its intervals, and provides a method to <strong>fetch the next number<\/strong>.<br \/>So in a RAP app, you\u2019d call this class (e.g., <code>get_number<\/code>) when you handle the <strong><code>CREATE<\/code> operation<\/strong> of an entity.<\/p>\n<p>&nbsp;<\/p>\n<p>CLASS zcl_numrng_demo DEFINITION<br \/>\nPUBLIC FINAL<br \/>\nCREATE PUBLIC.<\/p>\n<p>PUBLIC SECTION.<br \/>\nINTERFACES if_oo_adt_classrun.<\/p>\n<p>PRIVATE SECTION.<br \/>\nCONSTANTS gc_obj_id TYPE cl_numberrange_objects=&gt;nr_attributes-object VALUE &#8216;ZNR_DEMO&#8217;.<br \/>\nCONSTANTS gc_package TYPE cl_numberrange_objects=&gt;nr_attributes-devclass VALUE &#8216;ZDEMO_PKG&#8217;.<br \/>\nCONSTANTS gc_transport TYPE cl_numberrange_objects=&gt;nr_attributes-corrnr VALUE &#8221;.<\/p>\n<p>METHODS create_obj<br \/>\nIMPORTING io_console TYPE REF TO if_oo_adt_classrun_out.<\/p>\n<p>METHODS create_interval<br \/>\nIMPORTING io_console TYPE REF TO if_oo_adt_classrun_out.<\/p>\n<p>METHODS get_number<br \/>\nIMPORTING io_console TYPE REF TO if_oo_adt_classrun_out.<br \/>\nENDCLASS.<\/p>\n<p>CLASS zcl_numrng_demo IMPLEMENTATION.<br \/>\nMETHOD if_oo_adt_classrun~main.<br \/>\ncreate_obj( out ).<br \/>\ncreate_interval( out ).<br \/>\nget_number( out ).<br \/>\nENDMETHOD.<\/p>\n<p>METHOD create_obj.<br \/>\nTRY.<br \/>\ncl_numberrange_objects=&gt;create(<br \/>\nEXPORTING attributes = VALUE #( object = gc_obj_id<br \/>\ndomlen = &#8216;ZNR_DEMO_DOM&#8217;<br \/>\npercentage = 5<br \/>\ndevclass = gc_package<br \/>\ncorrnr = gc_transport )<br \/>\nobj_text = VALUE #( langu = &#8216;E&#8217;<br \/>\nobject = gc_obj_id<br \/>\ntxtshort = &#8216;Demo Numbers&#8217;<br \/>\ntxt = &#8216;Demo Number Range Object&#8217; )<br \/>\nIMPORTING errors = DATA(lt_err)<br \/>\nreturncode = DATA(lv_ret) ).<br \/>\nCATCH cx_number_ranges INTO DATA(lo_ex).<br \/>\nio_console-&gt;write( lo_ex-&gt;get_text( ) ).<br \/>\nENDTRY.<\/p>\n<p>io_console-&gt;write( lt_err ).<br \/>\nio_console-&gt;write( lv_ret ).<br \/>\nENDMETHOD.<\/p>\n<p>METHOD create_interval.<br \/>\nTRY.<br \/>\ncl_numberrange_intervals=&gt;create(<br \/>\nEXPORTING interval = VALUE #(<br \/>\n( nrrangenr = &#8217;01&#8217;<br \/>\nfromnumber = &#8216;500000&#8217;<br \/>\ntonumber = &#8216;599999&#8217;<br \/>\nprocind = &#8216;I&#8217; ) )<br \/>\nobject = gc_obj_id<br \/>\nIMPORTING error = DATA(lv_err)<br \/>\nerror_inf = DATA(ls_err)<br \/>\nerror_iv = DATA(lt_err_iv)<br \/>\nwarning = DATA(lv_warn) ).<\/p>\n<p>CATCH cx_root INTO DATA(lo_ex).<br \/>\nio_console-&gt;write( lo_ex-&gt;get_text( ) ).<br \/>\nENDTRY.<\/p>\n<p>io_console-&gt;write( lv_err ).<br \/>\nio_console-&gt;write( ls_err ).<br \/>\nio_console-&gt;write( lt_err_iv ).<br \/>\nio_console-&gt;write( lv_warn ).<br \/>\nENDMETHOD.<\/p>\n<p>METHOD get_number.<br \/>\nTRY.<br \/>\ncl_numberrange_runtime=&gt;number_get(<br \/>\nEXPORTING nr_range_nr = &#8217;01&#8217;<br \/>\nobject = gc_obj_id<br \/>\nIMPORTING number = DATA(lv_num)<br \/>\nreturncode = DATA(lv_rc) ).<\/p>\n<p>CATCH cx_root INTO DATA(lo_ex).<br \/>\nio_console-&gt;write( lo_ex-&gt;get_text( ) ).<br \/>\nENDTRY.<\/p>\n<p>io_console-&gt;write( lv_num ).<br \/>\nio_console-&gt;write( lv_rc ).<br \/>\nENDMETHOD.<br \/>\nENDCLASS.<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"closed","template":"","question-category":[175],"question_tags":[178,201,200,177],"class_list":["post-7570","question","type-question","status-publish","hentry","question-category-rap","question_tags-abap","question_tags-btp","question_tags-rap","question_tags-sap"],"_links":{"self":[{"href":"https:\/\/www.sapewmhelp.com\/index.php?rest_route=\/wp\/v2\/question\/7570","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.sapewmhelp.com\/index.php?rest_route=\/wp\/v2\/question"}],"about":[{"href":"https:\/\/www.sapewmhelp.com\/index.php?rest_route=\/wp\/v2\/types\/question"}],"author":[{"embeddable":true,"href":"https:\/\/www.sapewmhelp.com\/index.php?rest_route=\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/www.sapewmhelp.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=7570"}],"wp:attachment":[{"href":"https:\/\/www.sapewmhelp.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=7570"}],"wp:term":[{"taxonomy":"question-category","embeddable":true,"href":"https:\/\/www.sapewmhelp.com\/index.php?rest_route=%2Fwp%2Fv2%2Fquestion-category&post=7570"},{"taxonomy":"question_tags","embeddable":true,"href":"https:\/\/www.sapewmhelp.com\/index.php?rest_route=%2Fwp%2Fv2%2Fquestion_tags&post=7570"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}