Technology Blogs by SAP
Learn how to extend and personalize SAP applications. Follow the SAP technology blog for insights into SAP BTP, ABAP, SAP Analytics Cloud, SAP HANA, and more.
cancel
Showing results for 
Search instead for 
Did you mean: 

Introduction


This blog post provides an example on adding fields to the Input Parameter of an ABAP RESTful Application Programming Model (RAP) Business Object Behavior Action through Service Versioning.

Problem Statement (Example)


In this problem statement (Example), an initial Version of a RAP Service is implemented that has a Business Object Behavior Action with an Input Parameter with 2 fields (FIELD_1 and FIELD_2). A new field (FIELD_3) is required to be added in the Action Input Parameter.

Solution (Example)


The following approach suggests a solution (Example) with which a new field (FIELD_3) can be added to the Input Parameter of a Business Object Behavior Action by creating an additional Version of a RAP Service. The solution (Example) is based on RAP features such as Service Versioning and Projection Behavior Definition.

1. Steps to create Business Object Behavior Action with 2 fields (FIELD_1 and FIELD_2) in Input Parameter


 

Step 1.1: Initial implementation of Action with 2 fields (FIELD_1 and FIELD_2) in Input Parameter within the Business Object Behavior, can be as follows:
Define behavior for Z_BO alias BusinessObject
{
Action Action_V1 parameter Z_ACTION_PARAMETER_V1;
}

Define structure Z_ACTION_PARAMETER_V1
{
FIELD_1: <DATATYPE>;
FIELD_2: <DATATYPE>;
}

Step 1.2: Action with 2 fields (FIELD_1 and FIELD_2) in Input Parameter within the Business Object can be implemented in a Business Object Projection Behavior Definition using An External Name as follows:
projection;
Define behavior for Z_BO_PROJECTION_V1
{
use action Action_V1 external 'Action';
}

Step 1.3: Service using the Business Object Projection can be defined as follows:
Define service Z_SERVICE_V1
{
expose Z_BO_PROJECTION_V1 as Entity;
}

Step 1.4: Initial Version (V1) of the Service can be created using the Service Definition within a Service Binding. The Action End Point generated can be consumed through an HTTP POST Operation as follows:
POST <SERVICE_URL_V1>/Entity(Keys)/Action

Payload:
{
"FIELD_1": "Value_1",
"FIELD_2": "Value_2"
}

 

2. Steps to add field (FIELD_3) in Business Object Behavior Action Input Parameter


 

Step 2.1: Additional Action can be defined within the Business Object Behavior with Input Parameter Structure that has 3 fields (FIELD_1, FIELD_2 and FIELD_3) as follows:
Define behavior for Z_BO alias BusinessObject
{
//Previous Action with 2 fields in Input Parameter
Action Action_V1 parameter Z_ACTION_PARAMETER_V1;

//Additional Action with 3 fields in Input Parameter
Action Action_V2 parameter Z_ACTION_PARAMETER_V2;
}

Define structure Z_ACTION_PARAMETER_V2
{
FIELD_1: <DATATYPE>;
FIELD_2: <DATATYPE>;

//Additional field
FIELD_3: <DATATYPE>;
}

Step 2.2: Action with 3 fields (FIELD_1, FIELD_2 and FIELD_3) can be implemented in another Business Object Projection Behavior Definition using An External Name as follows:
projection;
//Additional Projection Behavior Definition
Define behavior for Z_BO_PROJECTION_V2
{
//Additional Action using same External Name
use action Action_V2 external 'Action';
}

Step 2.3: Additional Service using the Business Object Projection can be defined as follows:
//Additional Service Definition
Define service Z_SERVICE_V2
{
//Additional Projection View as Entity
expose Z_BO_PROJECTION_V2 as Entity;
}

Step 2.4: Additional Version (V2) of the Service can be created using the Service Definition within the Service Binding. The additional Action End Point generated can be consumed through an HTTP POST Operation as follows:
POST <SERVICE_URL_V2>/Entity(Keys)/Action

Payload:
{
"FIELD_1": "Value_1",
"FIELD_2": "Value_2"
"FIELD_3": "Value_3"
}

Summary


In the current blog post, a generic way of adding fields to Input Parameter of RAP Business Object Behavior Action through Service Versioning is mentioned.

For more understanding, please use the following references which have helped me in gaining knowledge on this feature and get motivated to write this blog post:

I would encourage you to read through other blog posts, post and answer questions on such topics at:

ABAP RESTful Application Programming Model

Please provide your feedback and ask questions in the comments section.
3 Comments