0% found this document useful (0 votes)
113 views18 pages

Numbering in SAP RAP Create Operations

The document discusses numbering strategies in the SAP ABAP RESTful Application Programming Model (RAP) during Create operations and Create by Association. It outlines two types of numbering: Early Numbering, which can be managed or unmanaged, and Late Numbering, which occurs just before data is saved. The blog also provides examples and implementation steps for a Hospital and Patient entity scenario to illustrate these concepts.

Uploaded by

bauvesf
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
113 views18 pages

Numbering in SAP RAP Create Operations

The document discusses numbering strategies in the SAP ABAP RESTful Application Programming Model (RAP) during Create operations and Create by Association. It outlines two types of numbering: Early Numbering, which can be managed or unmanaged, and Late Numbering, which occurs just before data is saved. The blog also provides examples and implementation steps for a Hospital and Patient entity scenario to illustrate these concepts.

Uploaded by

bauvesf
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

26/07/25, 17:27 Numbering during create and create by association ...

- SAP Community
m
m
Products and Technology Groups Partners Topics Events What's New Get Started Explore SAP
u
ni
t
SAP Community / Groups / Interest Groups / Application Development and Automation / Blog Posts
y
/ Numbering during create and create by association ...

Application Development and Automation


Blog Posts
Learn and share on deeper, cross technology development topics such as
integration and connectivity, automation, cloud extensibility, developing at
scale, and security.

Blog  Search

 We are taking steps to make our moderation process friendlier while ensuring that SAP Community continues
to comply with the Digital Services Act (DSA). Learn more in this What’s New post.

Numbering during create and create by association in RAP

Ismail_05
Explorer


‎2025 Jan 24 3:25 PM

 7 Kudos  4,591

SAP MANAGED TAGS

SAP S/4HANA CLOUD ABAP ENVIRONMENT ABAP RESTFUL APPLICATION PROGRAMMING MODEL

Introduction

In SAP ABAP RESTful Application Programming Model (RAP), the concepts of Create and Create by
Association are fundamental for managing data persistence in business objects.

Implementing numbering mechanisms during these operations is essential to ensure unique identifiers
for newly created entities.

This blog explores strategies and best practices for numbering during the Create operation and Create by Association,
highlighting how RAP supports these processes in both managed and unmanaged scenarios.

Basic Information About Numbering

Numbering in RAP refers to the process of assigning unique values to the key fields of business entities during Create
operations.

[Link] 1/18
26/07/25, 17:27 Numbering during create and create by association ... - SAP Community

Types of Numbering

1. Early Numbering:

Primary key values are assigned immediately when a creation operation is initiated.

This mechanism is triggered during the interaction phase.


Types:

Managed Early Numbering:

The RAP framework automatically assigns a UUID (Universal Unique Identifier) to the key field during
the create request.
Applicable for key fields of type RAW (16) in managed scenarios.
Unmanaged Early Numbering:

Developers implement custom logic to assign key values during the creation operation.
Use Cases:

Suitable for scenarios requiring immediate key assignment, such as generating unique identifiers for new
records upon clicking "Create."

2. Late Numbering:

Primary key values are assigned just before the data is saved to the database.

Triggered during the save sequence phase.

Implementation:

Developers implement the ADJUST_NUMBERS method to handle late numbering.

This method is invoked during the save sequence to assign key values.

Scenario Example

In this example, we have designed a scenario with two views:

1. Hospital View (Root entity)

1. Patient View (Child entity, dependent on Hospital View)

The Hospital View is the root entity, and the Patient View is related to it via a composition relationship. The patient data
cannot exist independently of the hospital data.

Below are the CDS view definitions and behavior implementations for the scenario:

Hospital View

[Link] 2/18
26/07/25, 17:27 Numbering during create and create by association ... - SAP Community

1 @[Link]: [#NONE]
2 @[Link]: #NOT_REQUIRED
3 @[Link]: 'Hospital interface view'
4 @[Link]: true
5 @[Link]:{
6 serviceQuality: #X,
7 sizeCategory: #S,
8 dataClass: #MIXED
9 }
10 define root view entity zismo_i_hospital
11 as select from zismo_dt_hosp
12 composition [1..*] of zismo_i_patient as _patient
13 {
14 @[Link]: [{
15 label: 'Hospital information',
16 purpose: #STANDARD,
17 type: #IDENTIFICATION_REFERENCE,
18 position: 10
19 },
20 { label : 'Patient information',
21 purpose: #STANDARD,
22 type: #LINEITEM_REFERENCE,
23 position: 20,
24 targetElement: '_patient' } ]
25
26 @[Link]: [{ position: 10, label: 'Hospital Id' }]
27 @[Link]: [{ position: 10, label: 'Hospital Id' }]
28 key hospital_id as HospitalId,
29
30 @[Link]: [{ position: 20, label: 'Hospital name' }]
31 @[Link]: [{ position: 20, label: 'Hospital name' }]
32 hospital_name as HospitalName,
33
34 @[Link]: [{ position: 30, label: 'Hospital location' }]
35 @[Link]: [{ position: 30, label: 'Hospital location' }]
36 hospital_location as HospitalLocation,
37
38 @[Link]: [{ position: 40, label: 'No of doctors' }]
39 @[Link]: [{ position: 40, label: 'No of doctors' }]
40 no_of_doctors as NoOfDoctors,
41
42 @[Link]: [{ position: 50, label: 'No of rooms' }]
43 @[Link]: [{ position: 50, label: 'No of rooms' }]
44 no_of_rooms as NoOfRooms,
45 _patient
46 }

Patient View

[Link] 3/18
26/07/25, 17:27 Numbering during create and create by association ... - SAP Community

1 @[Link]: [#NONE]
2 @[Link]: #NOT_REQUIRED
3 @[Link]: 'Patient interface view'
4 @[Link]: true
5 @[Link]:{
6 serviceQuality: #X,
7 sizeCategory: #S,
8 dataClass: #MIXED
9 }
10 define view entity zismo_i_patient
11 as select from zismo_dt_patient
12 association to parent zismo_i_hospital as _hospital on $[Link] = _hospita
13 {
14 @[Link]: [{
15 purpose: #STANDARD,
16 type: #IDENTIFICATION_REFERENCE,
17 position: 10
18 }]
19
20 @[Link]: [{ position: 10, label: 'Hospital Id' }]
21 @[Link]: [{ position: 10, label: 'Hospital Id' }]
22 key hospital_id as HospitalId,
23
24 @[Link]: [{ position: 20, label: 'Patient Id' }]
25 @[Link]: [{ position: 20, label: 'Patient Id' }]
26 key patient_id as PatientId,
27
28 @[Link]: [{ position: 30, label: 'Patient name' }]
29 @[Link]: [{ position: 30, label: 'Patient name' }]
30 patient_name as PatientName,
31
32 @[Link]: [{ position: 40, label: 'Medical cause' }]
33 @[Link]: [{ position: 40, label: 'Medical cause' }]
34 medical_cause as MedicalCause,
35
36 @[Link]: [{ position: 50, label: 'Doctor assigned' }]
37 @[Link]: [{ position: 50, label: 'Doctor assigned' }]
38 doctor_assigned as DoctorAssigned,
39
40 @[Link]: [{ position: 60, label: 'Room no' }]
41 @[Link]: [{ position: 60, label: 'Room no' }]
42 room_no as RoomNo,
43
44 @[Link]: [{ position: 70, label: 'Payment status' }]
45 @[Link]: [{ position: 70, label: 'Payment status' }]
46 payment_status as PaymentStatus,
47 _hospital
48 }

 

[Link] 4/18
26/07/25, 17:27 Numbering during create and create by association ... - SAP Community

To manage the functionality of the scenario, I have created a behavior definition for the root view (Hospital View).

This behavior definition defines the operations and interactions that can be performed on the hospital entity and its
associated patient entities.

[Link] 5/18
26/07/25, 17:27 Numbering during create and create by association ... - SAP Community

1 managed implementation in class zbp_ismo_i_hospital unique;


2 strict ( 2 );
3
4 define behavior for zismo_i_hospital alias hospital
5 persistent table zismo_dt_hosp
6 lock master
7 authorization master ( instance )
8 {
9 create;
10 update;
11 delete;
12
13 field ( readonly : update ) HospitalId;
14 association _patient { create; }
15
16 mapping for zismo_dt_hosp
17 {
18 HospitalId = hospital_id;
19 HospitalName = hospital_name;
20 HospitalLocation = hospital_location;
21 NoOfDoctors = no_of_doctors;
22 NoOfRooms = no_of_rooms;
23 }
24 }
25
26 define behavior for zismo_i_patient alias patient
27 persistent table zismo_dt_patient
28 lock dependent by _hospital
29 authorization dependent by _hospital
30 {
31 update;
32 delete;
33
34 field ( readonly ) HospitalId;
35 field ( readonly : update ) PatientId;
36 association _hospital;
37
38 mapping for zismo_dt_patient
39 {
40 HospitalId = hospital_id;
41 PatientId = patient_id;
42 PatientName = patient_name;
43 MedicalCause = medical_cause;
44 DoctorAssigned = doctor_assigned;
45 RoomNo = room_no;
46 PaymentStatus = payment_status;
47 }
48 }

[Link] 6/18
26/07/25, 17:27 Numbering during create and create by association ... - SAP Community

Step by Step implementation


Early numbering managed

Let's start with parent entity, in our case hospital view

For managed early numbering, ensure that the key field is of type SYSUUIDx16 (RAW16)

And in the behavior definition of your BO use syntax “numbering: managed” for your key field

That's it, rest of the things will be managed by framework

Creation of record for parent entity, in our case its hospital view, using early numbering managed

[Link] 7/18
26/07/25, 17:27 Numbering during create and create by association ... - SAP Community

As we can see the unique ID has been generated for us by the framework

Now let’s see how to do it with child entity, in my case patient view

Same steps we need to follow to achieve early numbering managed for child entity

Behavior definition of patient view

[Link] 8/18
26/07/25, 17:27 Numbering during create and create by association ... - SAP Community

Creation of record for child entity, in our case patient view using early numbering managed

Early numbering unmanaged

Unlike managed early numbering here in unmanaged early numbering we can have key fields of any data type

Here in our scenario, I am not changing the data type of the field

To start with early numbering unmanaged, go to your behavior definition and write the syntax early numbering

Let's start with parent entity, in our case hospital view

Here if we see we are getting an error because at a time only one type of numbering can be used, so remove other
numbering and keep the early numbering syntax

[Link] 9/18
26/07/25, 17:27 Numbering during create and create by association ... - SAP Community

Now if we see we are getting a warning at create method of Hospital entity

The warning is related to implementing the method, so put cursor on the line and do a quick fix (CTRL + 1)

System will give the quick fix suggestion to implement the method

Double click and you will enter the behavior pool where you can write implementation for this method

So, let’s write a basic logic to understand unmanaged early numbering

Before writing the logic put cursor on the method name and click F2 to see the parameters related to the method

Here we need to mandatorily fill mapped parameter consisting of %CID and our key field hospitalID

[Link] 10/18
26/07/25, 17:27 Numbering during create and create by association ... - SAP Community

%CID refers to content id which should be unique while creation of new record, this %CID we can refer from entities
parameter

So, let’s start writing the code for it

1 METHOD earlynumbering_create.
2 SELECT MAX( hospital_id ) FROM zismo_dt_hosp INTO (lv_hos_id).
3
4 lv_hos_id = COND #( WHEN lv_hos_id IS NOT INITIAL THEN lv_hos_id + 1
5 ELSE 1 ).
6 mapped-hospital = VALUE #( ( %cid = entities[ 1 ]-%cid
7 HospitalId = lv_hos_id ) ).
8 ENDMETHOD.

It’s a simple logic where i am checking for maximum hospital id present in the DB and if present then i will increment by
one else i will start id by 1

And i am filling in the mapped parameter for hospital view.

Creation of record for parent entity in our case hospital view using early numbering unmanaged

As we can see the record has been created using the logic we implemented for unmanaged early numbering

Now let’s see how to do it with child entity, in my case patient view

Go to the behavior definition of patient view and write the syntax early numbering

Since creation of child entity is dependent on parent entity so the warning is being triggered at behavior definition of
parent entity at association

[Link] 11/18
26/07/25, 17:27 Numbering during create and create by association ... - SAP Community

So quick fix the warning and enter behavior pool

cba means create by association

So, let’s write a sample implementation to understand create by association in unmanaged early numbering

Before writing the logic let’s check the method signature by clicking F2

Here inside entities, we don’t have child entity’s key field patientid

So, if we click on %target then we can see the components related to child entity

[Link] 12/18
26/07/25, 17:27 Numbering during create and create by association ... - SAP Community

So, we need to fill patientID present in %target and then we can append %target structure to mapped parameter of
patient view

1 METHOD earlynumbering_cba_Patient.
2 SELECT MAX( patient_id ) FROM zismo_dt_patient INTO (lv_pat_id).
3
4 lv_pat_id = COND #( WHEN lv_pat_id IS NOT INITIAL THEN lv_pat_id + 1
5 ELSE 1 ).
6
7 DATA(ls_target) = entities[ 1 ]-%target[ 1 ].
8 ls_target-PatientId = lv_pat_id.
9
10 APPEND CORRESPONDING #( ls_target ) TO mapped-patient.
11 ENDMETHOD.

Creation of child entity in our case patient view, using unmanaged cba early numbering

Late numbering

In late numbering also we can do numbering for key fields of any data type

To implement late numbering write the syntax late numbering in the behavior definition of hospital view

[Link] 13/18
26/07/25, 17:27 Numbering during create and create by association ... - SAP Community

And the moment we write late numbering for root/parent entity we get an error

The error is if parent entity is implemented as late numbering, then child entity must also have to contain late
numbering

So, lets write late numbering for child entity’s behavior definition as well

Now the error is gone but we get a warning to implement the adjust number method

In case of late numbering every time method name will be adjust numbers where we can write the logic for late
numbering

So quick fix the warning and enter behavior pool where we can see the method

Click F2 and analyze the method signature

Now here in this method itself we must write the late numbering logic for both parent and child entity

[Link] 14/18
26/07/25, 17:27 Numbering during create and create by association ... - SAP Community

So, i have written a sample logic

Here whenever we perform create operation the mapped parameter related to that entity will not be initial so by using
this condition, we can write a logic

Here to perform create by association we need to get the parent entity key value which we can get from %tmp of child
entity, so based on that parent key the associated child will be created

1 METHOD adjust_numbers.
2 IF mapped-hospital IS NOT INITIAL.
3
4 SELECT MAX( hospital_id ) FROM zismo_dt_hosp INTO (lv_hos_id).
5
6 lv_hos_id = COND #( WHEN lv_hos_id IS NOT INITIAL THEN lv_hos_id + 1
7 ELSE 1 ).
8
9 DATA(ls_mapped_hos) = VALUE #( mapped-hospital[ 1 ] OPTIONAL ).
10
11 ls_mapped_hos-HospitalId = lv_hos_id.
12 APPEND CORRESPONDING #( ls_mapped_hos ) TO mapped-hospital.
13
14 ELSEIF mapped-patient IS NOT INITIAL.
15
16 SELECT MAX( patient_id ) FROM zismo_dt_patient INTO (lv_pat_id).
17
18 lv_pat_id = COND #( WHEN lv_pat_id IS NOT INITIAL THEN lv_pat_id + 1
19 ELSE 1 ).
20
21 DATA(ls_mapped_pat) = VALUE #( mapped-patient[ 1 ] OPTIONAL ).
22 ls_mapped_pat-HospitalId = ls_mapped_pat-%tmp-HospitalId.
23 ls_mapped_pat-PatientId = lv_pat_id.
24
25 APPEND CORRESPONDING #( ls_mapped_pat ) TO mapped-patient.
26 ENDIF.
27 ENDMETHOD.

Creation of record for parent entity in our case hospital view using late numbering

[Link] 15/18
26/07/25, 17:27 Numbering during create and create by association ... - SAP Community

Creation of child entity in our case patient view, using late numbering

Yeah, this is about numbering in RAP

One thing to be careful of is while performing numbering with draft based BO we need to fill %is_draft field.

Thanks and Regards.

LABELS

ABAP ABAP RAP

3 Comments

AbhishekSharma 
Active Contributor
2025 Jan 24 10:26 PM

 0 Kudos

Hi @Ismail_05 nice and very useful post...


[Link] 16/18
26/07/25, 17:27 Numbering during create and create by association ... - SAP Community

Thanks-

xSAGARx 
Explorer
2025 Jan 25 5:30 AM

 0 Kudos

Resolved my issue

Thanks @Ismail_05

Basant_Joshi 
Participant
‎2025 Mar 01 4:38 AM

 0 Kudos

Does the use of UUID comes under early numbering concept in manage scenario ? rest is clear to me, they
are just normal counter methods if we not use early numbering in behavior definition we can still leverage
this functionality in cbaitem and during creation of header id in unmanage scenario.

My doubt is what are industry standard ?

Because we usually use number range in projects and UUID just throws a random number, what if i want a
set range like from 1000 with SNO-1000 sequence in my manage scenario ?

Thanks @Ismail_05 For Blog

 You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register
and sign in.

Comment

Top Kudoed Authors

maria_kondratyeva  4

ajmaradiaga  2

AmarUbhe  2

RAHUL1221  2

suketu_dave  2

[Link] 17/18
26/07/25, 17:27 Numbering during create and create by association ... - SAP Community

Naveen_n  2

jwood_bowdark  1

Victor_f33  1

Aakash_06  1

View all 

Privacy Terms of Use

Copyright Legal Disclosure

Trademark Support

Cookie Preferences
Follow

[Link] 18/18

You might also like