Introduction:
In most business applications, key fields such as Purchase Order number, Sales Order number, or Document ID are automatically generated using a number range object. This ensures uniqueness, consistency, and compliance with business standards.
In the SAP RESTful ABAP Programming Model (RAP), handling number generation requires a clear understanding of the framework lifecycle. Unlike classical ABAP, where numbers are typically generated during SAVE or in user exits, RAP introduces structured phases like Early Numbering and Late Numbering.
Early Numbering is used when the document number must be generated at the time of CREATE itself, even before the data is saved to the database.
Solution Overview:
In this blog, we will explore how to implement Early Numbering using a Number Range Object in RAP, including:
Creating and configuring a custom Number Range Object
Implementing EARLYNUMBERING_CREATE in the Behavior Implementation
Properly updating mapped entities using %control
Avoiding common mistakes like type mismatch and value reset issues
Root Entity:
@AccessControl.authorizationCheck: #NOT_REQUIRED
@EndUserText.label: ‘interface view for purchase header’
@Metadata.ignorePropagatedAnnotations: true
define root view entity zr_trv_etag as select from zpur_hdr
{
key ebeln as Ebeln,
bukrs as Bukrs,
bstyp as Bstyp,
bsart as Bsart ,
last_changed_at as lastchangedat
}
Projection View:
@AccessControl.authorizationCheck: #NOT_REQUIRED
@EndUserText.label: ‘purchase header consumption view’
@Metadata.ignorePropagatedAnnotations: true
define root view entity zc_pur_hdr as projection on zr_trv_etag
{
@UI.facet: [{ type: #IDENTIFICATION_REFERENCE, label: ‘Purchase Header’ }]
@UI.lineItem: [{ position: 10 }]
@UI.identification: [{ position: 10 }]
key Ebeln,
@UI.lineItem: [{ position: 20 }]
@UI.identification: [{ position: 20 }]
Bukrs,
@ui.lineItem: [{ position: 30 }]
@UI.identification: [{ position: 30 }]
Bstyp,
@ui.lineItem: [{ position: 40 }]
@UI.identification: [{ position: 40 }]
Bsart
}
Interface Behavior Definition & Define Early Numbering:
managed implementation in class zbp_r_trv_etag unique;
strict ( 2 );
with draft;
define behavior for zr_trv_etag alias i_purhdr
persistent table ZPUR_HDR
draft table zdpurhdr
lock master total etag lastchangedat
authorization master ( instance )
early numbering
//etag master <field_name>
{
create;
update;
delete;
field(readonly) Ebeln;
draft action Activate ;
draft action Discard;
draft action Edit;
draft action Resume;
draft determine action Prepare;
mapping for ZPUR_HDR{
Ebeln = ebeln;
Bukrs = bukrs;
Bsart = bsart;
Bstyp = bstyp;
}
}
Early Numbering Implementation:
METHOD EARLYNUMBERING_CREATE.
TRY.
cl_numberrange_runtime=>number_get(
EXPORTING
nr_range_nr = ’01’
object = ‘ZPUR_DOC_N’
quantity = 1
IMPORTING
number = data(lv_pur_id)
returncode = DATA(lv_subrc)
returned_quantity = DATA(lv_total_quantity)
).
CATCH cx_nr_object_not_found.
CATCH cx_number_ranges.
ENDTRY.
loop at entities into data(wa_entity) .
if WA_ENTITY-Ebeln is INITIAL.
wa_entity-Ebeln = lv_pur_id+10(10).
append value #( %cid = wa_entity-%cid
%key = wa_entity-%key
%is_draft = wa_entity-%is_draft )
to mapped-I_PURHDR.
else.
append value #( %cid = wa_entity-%cid
%key = wa_entity-%key
%is_draft = wa_entity-%is_draft )
to mapped-I_PURHDR.
ENDIF.
ENDLOOP.
ENDMETHOD.
Number Range Object Creation:
tcode : SNRO
give number range object.
Service Definition:
Service Binding:
Preview:
Create:
Conclusion:
Early Numbering in RAP allows us to generate document numbers at the time of creation itself using a Number Range Object. This is useful when the key field must be available immediately on the UI or required for draft processing. By correctly implementing the EARLYNUMBERING_CREATE method and updating the mapped entity with %control, we can ensure the generated number is properly assigned and saved. Understanding this concept helps developers avoid common mistakes and build stable, standard-compliant RAP applications.
Check Out My Other Blogs:
Follow Me On Linkedin For More Content:
Linkedin
Thanks For Reading Blog…
Introduction:In most business applications, key fields such as Purchase Order number, Sales Order number, or Document ID are automatically generated using a number range object. This ensures uniqueness, consistency, and compliance with business standards.In the SAP RESTful ABAP Programming Model (RAP), handling number generation requires a clear understanding of the framework lifecycle. Unlike classical ABAP, where numbers are typically generated during SAVE or in user exits, RAP introduces structured phases like Early Numbering and Late Numbering.Early Numbering is used when the document number must be generated at the time of CREATE itself, even before the data is saved to the database.Solution Overview:In this blog, we will explore how to implement Early Numbering using a Number Range Object in RAP, including:Creating and configuring a custom Number Range ObjectImplementing EARLYNUMBERING_CREATE in the Behavior ImplementationProperly updating mapped entities using %controlAvoiding common mistakes like type mismatch and value reset issuesRoot Entity:@AccessControl.authorizationCheck: #NOT_REQUIRED
@EndUserText.label: ‘interface view for purchase header’
@Metadata.ignorePropagatedAnnotations: true
define root view entity zr_trv_etag as select from zpur_hdr
{
key ebeln as Ebeln,
bukrs as Bukrs,
bstyp as Bstyp,
bsart as Bsart ,
last_changed_at as lastchangedat
}Projection View:@AccessControl.authorizationCheck: #NOT_REQUIRED
@EndUserText.label: ‘purchase header consumption view’
@Metadata.ignorePropagatedAnnotations: true
define root view entity zc_pur_hdr as projection on zr_trv_etag
{
@UI.facet: [{ type: #IDENTIFICATION_REFERENCE, label: ‘Purchase Header’ }]
@UI.lineItem: [{ position: 10 }]
@UI.identification: [{ position: 10 }]
key Ebeln,
@UI.lineItem: [{ position: 20 }]
@UI.identification: [{ position: 20 }]
Bukrs,
@ui.lineItem: [{ position: 30 }]
@UI.identification: [{ position: 30 }]
Bstyp,
@ui.lineItem: [{ position: 40 }]
@UI.identification: [{ position: 40 }]
Bsart
}Interface Behavior Definition & Define Early Numbering:managed implementation in class zbp_r_trv_etag unique;
strict ( 2 );
with draft;
define behavior for zr_trv_etag alias i_purhdr
persistent table ZPUR_HDR
draft table zdpurhdr
lock master total etag lastchangedat
authorization master ( instance )
early numbering
//etag master <field_name>
{
create;
update;
delete;
field(readonly) Ebeln;
draft action Activate ;
draft action Discard;
draft action Edit;
draft action Resume;
draft determine action Prepare;
mapping for ZPUR_HDR{
Ebeln = ebeln;
Bukrs = bukrs;
Bsart = bsart;
Bstyp = bstyp;
}
}Early Numbering Implementation:METHOD EARLYNUMBERING_CREATE.
TRY.
cl_numberrange_runtime=>number_get(
EXPORTING
nr_range_nr = ’01’
object = ‘ZPUR_DOC_N’
quantity = 1
IMPORTING
number = data(lv_pur_id)
returncode = DATA(lv_subrc)
returned_quantity = DATA(lv_total_quantity)
).
CATCH cx_nr_object_not_found.
CATCH cx_number_ranges.
ENDTRY.
loop at entities into data(wa_entity) .
if WA_ENTITY-Ebeln is INITIAL.
wa_entity-Ebeln = lv_pur_id+10(10).
append value #( %cid = wa_entity-%cid
%key = wa_entity-%key
%is_draft = wa_entity-%is_draft )
to mapped-I_PURHDR.
else.
append value #( %cid = wa_entity-%cid
%key = wa_entity-%key
%is_draft = wa_entity-%is_draft )
to mapped-I_PURHDR.
ENDIF.
ENDLOOP.
ENDMETHOD.Number Range Object Creation:tcode : SNROgive number range object. Service Definition: Service Binding: Preview:Create: Conclusion:Early Numbering in RAP allows us to generate document numbers at the time of creation itself using a Number Range Object. This is useful when the key field must be available immediately on the UI or required for draft processing. By correctly implementing the EARLYNUMBERING_CREATE method and updating the mapped entity with %control, we can ensure the generated number is properly assigned and saved. Understanding this concept helps developers avoid common mistakes and build stable, standard-compliant RAP applications.Check Out My Other Blogs:Topic1 : CALL BAPI IN CUSTOM ENTITY THROUGH RAP Link : CALL BAPI IN CUSTOM ENTITY THROUGH RAP Topic2 : Hide/Show Field In UI Dynamically Through Virtual Elements In RAP Link : Hide/Show Field In UI Dynamically Through Virtual Elements In RAP Topic3 : RAP BASED ADOBEFORM WITH CUSTOM ACTION and Annotations Link : RAP BASED ADOBEFORM WITH CUSTOM ACTION and Annotations Topic4 : Date Hierarchy Using Tree ALV(FM & OOPS ) Link : Date Hierarchy Using Tree ALV(FM & OOPS) Topic5 : Convert XML File to Internal Table And Download Into CSV Format In ABAP Link : Convert XML File to Internal Table And Download Into CSV Format In ABAP Topic6 : Dynamic Font Styling in Adobe Forms (JavaScript) Link : Dynamic Font Styling in Adobe Forms (JavaScript) Topic7 : Previewing and Downloading Adobe Forms Made Easy with ABAP Link : Previewing and Downloading Adobe Forms Made Easy with ABAP Follow Me On Linkedin For More Content:Linkedin Thanks For Reading Blog… Read More Technology Blog Posts by Members articles
#SAP
#SAPTechnologyblog