I am happy to share my very first blog post on SAP RAP (Restful Application Programming) managed Scenario example using flight booking.
In this blog i done these functionalities with the use of new syntax.
Create. Delete. Update. Read. Etag. Modify. Actions
DATA MODEL
For example i take flight travel booking.
Travel->root entity . Booking->child entity. Booking supplement->child entity/
First we have to create database table .
We need to create 3 database tables .
First we have to create root entity is travel managing table.
@EndUserText.label : ‘ Managing Travels’
@AbapCatalog.enhancement.category : #NOT_EXTENSIBLE
@AbapCatalog.tableCategory : #TRANSPARENT
@AbapCatalog.deliveryClass : #A
@AbapCatalog.dataMaintenance : #RESTRICTED
define table zna_travel_m {
key client : abap.clnt not null;
key travel_id : /dmo/travel_id not null;
agency_id : /dmo/agency_id;
customer_id : /dmo/customer_id;
begin_date : /dmo/begin_date;
end_date : /dmo/end_date;
@Semantics.amount.currencyCode : ‘ytravel_tech_m.currency_code’
booking_fee : /dmo/booking_fee;
@Semantics.amount.currencyCode : ‘ytravel_tech_m.currency_code’
total_price : /dmo/total_price;
currency_code : /dmo/currency_code;
description : /dmo/description;
overall_status : /dmo/overall_status;
created_by : abp_creation_user;
created_at : abp_creation_tstmpl;
last_changed_by : abp_locinst_lastchange_user;
last_changed_at : abp_locinst_lastchange_tstmpl;
}
Second for booking and we have to create foreign relationship with root entity
@EndUserText.label : ‘booking scenario’
@AbapCatalog.enhancement.category : #NOT_EXTENSIBLE
@AbapCatalog.tableCategory : #TRANSPARENT
@AbapCatalog.deliveryClass : #A
@AbapCatalog.dataMaintenance : #RESTRICTED
define table zna_booking_m1 {
key client : abap.clnt not null;
@AbapCatalog.foreignKey.label : ‘Travel’
@AbapCatalog.foreignKey.screenCheck : false
key travel_id : /dmo/travel_id not null
with foreign key [0..*,1] zna_travel_m
where travel_id = zna_booking_m1.travel_id;
key booking_id : /dmo/booking_id not null;
booking_date : /dmo/booking_date;
customer_id : /dmo/customer_id;
carrier_id : /dmo/carrier_id;
connection_id : /dmo/connection_id;
flight_date : /dmo/flight_date;
@Semantics.amount.currencyCode : ‘ybooking_tech_m.currency_code’
flight_price : /dmo/flight_price;
currency_code : /dmo/currency_code;
booking_status : /dmo/booking_status;
last_changed_at : abp_locinst_lastchange_tstmpl;
}
Third one we have to create booking suplement for this one also we need to create foreign key rerlationship with root entity.
@EndUserText.label : ‘booking suplemnent’
@AbapCatalog.enhancement.category : #NOT_EXTENSIBLE
@AbapCatalog.tableCategory : #TRANSPARENT
@AbapCatalog.deliveryClass : #A
@AbapCatalog.dataMaintenance : #RESTRICTED
define table zbooksuppl1_m3 {
@AbapCatalog.foreignKey.label : ‘Travel’
@AbapCatalog.foreignKey.screenCheck : false
key travel_id : /dmo/travel_id not null
with foreign key [0..*,1] zna_travel_m
where travel_id = zbooksuppl1_m3.travel_id;
@AbapCatalog.foreignKey.label : ‘Booking’
@AbapCatalog.foreignKey.screenCheck : false
key booking_id : /dmo/booking_id not null
with foreign key [0..*,1] zna_booking_m1
where travel_id = zbooksuppl1_m3.travel_id
and booking_id = zbooksuppl1_m3.booking_id;
key booking_supplement_id : /dmo/booking_supplement_id not null;
supplement_id : /dmo/supplement_id;
@Semantics.amount.currencyCode : ‘ybooksupp_tech_m.currency_code’
price : /dmo/supplement_price;
currency_code : /dmo/currency_code;
last_changed_at : abp_locinst_lastchange_tstmpl;
}
Next we have to create interface for root entity
@AbapCatalog.viewEnhancementCategory: [#NONE]
@AccessControl.authorizationCheck: #NOT_REQUIRED
@EndUserText.label: ‘travelmanagedinterface’
@Metadata.ignorePropagatedAnnotations: true
@ObjectModel.usageType:{
serviceQuality: #X,
sizeCategory: #S,
dataClass: #MIXED
}
define root view entity zna_i_travel_m1 as select from zna_travel_m
composition [0..*] of zna_i_BOOKING_m1 as _booking
association [0..1] to /DMO/I_Agency as _agency on $projection.AgencyId = _agency.AgencyID
association [0..1] to /DMO/I_Customer as _customer on $projection.CustomerId = _customer.CustomerID
association [0..1] to I_Currency as _currency on $projection.CurrencyCode = _currency.Currency
association [1..1] to /DMO/I_Overall_Status_VH as _overall on $projection.OverallStatus = _overall.OverallStatus
{
key travel_id as TravelId,
agency_id as AgencyId,
customer_id as CustomerId,
begin_date as BeginDate,
end_date as EndDate,
@Semantics.amount.currencyCode: ‘CurrencyCode’
booking_fee as BookingFee,
@Semantics.amount.currencyCode: ‘CurrencyCode’
total_price as TotalPrice,
currency_code as CurrencyCode,
description as Description,
overall_status as OverallStatus,
created_by as CreatedBy,
created_at as CreatedAt,
last_changed_by as LastChangedBy,
@Semantics.systemDateTime.localInstanceLastChangedAt: true
last_changed_at as LastChangedAt,
_booking,
_agency,
_customer,
_currency,
_overall
}
Now we have to create interface view for booking.
@AbapCatalog.viewEnhancementCategory: [#NONE]
@AccessControl.authorizationCheck: #NOT_REQUIRED
@EndUserText.label: ‘BOOKING’
@Metadata.ignorePropagatedAnnotations: true
@ObjectModel.usageType:{
serviceQuality: #X,
sizeCategory: #S,
dataClass: #MIXED
}
define view entity zna_i_BOOKING_m1 as select from zna_booking_m1
association to parent zna_i_travel_m1 as _travel on $projection.TravelId = _travel.TravelId
composition [0..*] of Z_i_BOOKSUPPL1_M3 as _booksup
association [1..1] to /DMO/I_Carrier as _CARRIER on $projection.CarrierId = _CARRIER.AirlineID
association [1..1] to /DMO/I_Customer as _customer on $projection.CustomerId = _customer.CustomerID
association [1..1] to /DMO/I_Connection as _cONNECTION on $projection.CarrierId = _cONNECTION.AirlineID
and $projection.ConnectionId = _cONNECTION.ConnectionID
association [1..1] to /DMO/I_Booking_Status_VH as _bookstatus on $projection.BookingStatus = _bookstatus.BookingStatus
{
key travel_id as TravelId,
key booking_id as BookingId,
booking_date as BookingDate,
customer_id as CustomerId,
carrier_id as CarrierId,
connection_id as ConnectionId,
flight_date as FlightDate,
@Semantics.amount.currencyCode: ‘CurrencyCode’
flight_price as FlightPrice,
currency_code as CurrencyCode,
booking_status as BookingStatus,
@Semantics.systemDateTime.localInstanceLastChangedAt: true
last_changed_at as LastChangedAt,
_booksup,
_travel,
_CARRIER,
_customer,
_cONNECTION,
_bookstatus
}
Now we have to create interface view for booking Supplement.
@AbapCatalog.viewEnhancementCategory: [#NONE]
@AccessControl.authorizationCheck: #NOT_REQUIRED
@EndUserText.label: ‘bboking suplement’
@Metadata.ignorePropagatedAnnotations: true
@ObjectModel.usageType:{
serviceQuality: #X,
sizeCategory: #S,
dataClass: #MIXED
}
define view entity Z_i_BOOKSUPPL1_M3 as select from zbooksuppl1_m3
association to parent zna_i_BOOKING_m1 as _booking on $projection.TravelId = _booking.TravelId
and $projection.BookingId = _booking.BookingId
association [1..1] to zna_i_travel_m1 as _travel on $projection.TravelId = _travel.TravelId
association [1..1] to /DMO/I_Supplement as _supplement on $projection.SupplementId = _supplement.SupplementID
association [1..1] to /DMO/I_SupplementText as _supplementtext on $projection.SupplementId = _supplementtext.SupplementID
{
key travel_id as TravelId,
key booking_id as BookingId,
key booking_supplement_id as BookingSupplementId,
supplement_id as SupplementId,
@Semantics.amount.currencyCode : ‘CurrencyCode’
price as Price,
currency_code as CurrencyCode,
@Semantics.systemDateTime.localInstanceLastChangedAt: true
last_changed_at as LastChangedAt,
_travel ,
_supplement,
_supplementtext,
_booking
}
Then next now we have to create projection entity.
Projection view define service-specific projections including denormalization of underlying data. We define here UI annotations , value help , calculations or defaulting. We have to specify provider contract for root entity. Transactional query.Transactional interface. Analytical query.SQL query.
@AccessControl.authorizationCheck: #NOT_REQUIRED
@EndUserText.label: ‘projection entity’
@Metadata.allowExtensions: true
define root view entity ZNA_C_TRAVEL_M1 provider contract transactional_query as projection on zna_i_travel_m1
{
key TravelId,
@ObjectModel.text:{ element: [ ‘AgencyName’ ] }
@Consumption.valueHelpDefinition: [{ entity : { name: ‘/DMO/I_AGENCY’ , element: ‘AgencyId’ } } ]
AgencyId,
_agency.Name as AgencyName,
@ObjectModel.text.element: [ ‘CustomerName’ ]
@Consumption.valueHelpDefinition: [{ entity : { name: ‘/DMO/I_CUSTOMER’ , element: ‘CustomerId’ } } ]
CustomerId,
_customer.LastName as CustomerName,
BeginDate,
EndDate,
BookingFee,
TotalPrice,
@Consumption.valueHelpDefinition: [{ entity : { name: ‘I_CURRENCY’ , element: ‘Currency’ } } ]
CurrencyCode,
Description,
@ObjectModel.text.element: [ ‘OVERALLTEXT’ ]
@Consumption.valueHelpDefinition: [{ entity : { name: ‘/DMO/I_Overall_Status_VH’ , element: ‘OverallStatus’ } } ]
OverallStatus,
_overall._Text.Text as OVERALLTEXT: localized ,
CreatedBy,
CreatedAt,
LastChangedBy,
LastChangedAt,
/* Associations */
_agency,
_booking : redirected to composition child ZNA_C_BOOKING_M2,
_currency,
_customer,
_overall
}
Next we have to create metadata extension right click on entity it will ask to create u create with annotate entity to maintain Ui annotations.
@Metadata.layer: #CORE
@Search.searchable: true
annotate view ZNA_C_TRAVEL_M1 with
{
@UI.facet: [{ id: ‘Travel’,
purpose: #STANDARD ,
position: 10,
label: ‘Travel’,
type: #IDENTIFICATION_REFERENCE}]
@Search.defaultSearchElement: true
@UI.identification: [{ position: 10 }]
@UI.lineItem: [{ position: 10 }]
TravelId;
@UI : { lineItem: [{ position: 20 }] ,
selectionField: [{ position: 10 }] }
@Search.defaultSearchElement: true
@UI.identification: [{ position: 20 }]
AgencyId;
@UI.lineItem: [{ position: 30 }]
// AgencyName;
// @ui.lineItem: [{ position: 40 }]
@UI.selectionField: [{ position: 20 }]
@Search.defaultSearchElement: true
@UI.identification: [{ position: 30 }]
CustomerId;
@UI.lineItem: [{ position: 50 }]
@UI.identification: [{ position: 40 }]
CustomerName;
@UI.lineItem: [{ position: 60 }]
@UI.identification: [{ position: 50 }]
BeginDate;
@UI.lineItem: [{ position: 70 }]
EndDate;
// @ui.lineItem: [{ position: 80 }]
// BookingFee;
@UI.lineItem: [{ position: 90 }]
@UI.identification: [{ position: 60 }]
TotalPrice;
// @ui.lineItem: [{ position: 100 }]
// CurrencyCode;
// @ui.lineItem: [{ position: 110 }]
// Description;
@UI.lineItem: [{ position: 120 }]
@UI.selectionField: [{ position: 30 }]
@Search.defaultSearchElement: true
OverallStatus ;
Then we have to create behavior definition for root entity.
Right Click on root entity and create behavior definition.
managed ; // implementation in class zbp_na_i_travel_m1 unique;
strict ( 2 );
define behavior for zna_i_travel_m1 //alias travel
implementation in class zcl_bp_na_i_travel_m1 unique
persistent table zna_travel_m
lock master
authorization master ( instance )
etag master LastChangedAt
{
create;
update;
delete;
// field ( readonly ) TravelId;
association _booking { create; }
mapping for zna_travel_m {
TravelId = travel_id;
AgencyId = agency_id;
CustomerId = customer_id;
BeginDate = begin_date;
EndDate = end_date;
BookingFee = booking_fee;
TotalPrice = total_price;
CurrencyCode = currency_code;
Description = description;
OverallStatus = overall_status;
CreatedBy = created_by;
CreatedAt = created_at;
LastChangedBy = last_changed_by;
LastChangedAt = last_changed_at ;
}
}
define behavior for zna_i_BOOKING_m1 //alias <alias_name>
implementation in class zcl_bp_na_i_boking_m1 unique
persistent table zna_booking_m1
lock dependent by _travel
authorization dependent by _travel
etag master LastChangedAt
{
update;
delete;
field ( readonly ) TravelId, BookingId;
association _travel;
association _booksup { create; }
mapping for zna_booking_m1
{
TravelId = travel_id;
BookingId = booking_id;
BookingDate = booking_date;
CustomerId = customer_id;
CarrierId = carrier_id;
ConnectionId = connection_id;
FlightDate = flight_date;
FlightPrice = flight_price;
CurrencyCode = currency_code;
BookingStatus = booking_status;
LastChangedAt = last_changed_at ;
}
}
define behavior for Z_i_BOOKSUPPL1_M3 //alias <alias_name>
implementation in class zcl_bp_na_i_bookingsupp_m1 unique
persistent table zbooksuppl1_m3
lock dependent by _travel
authorization dependent by _travel
etag master LastChangedAt
{
update;
delete;
field ( readonly ) TravelId, BookingId, BookingSupplementId;
association _travel;
association _booking;
mapping for zbooksuppl1_m3 {
TravelId = travel_id;
BookingId = booking_id;
BookingSupplementId = booking_supplement_id;
SupplementId = supplement_id;
Price = price;
CurrencyCode = currency_code;
LastChangedAt = last_changed_at;
}
}
And behavior definition for projected entity.
projection;
strict ( 2 );
define behavior for ZNA_C_TRAVEL_M1 //alias <alias_name>
use etag
{
use create;
use update;
use delete;
use association _booking { create; }
}
define behavior for ZNA_C_BOOKING_M2 //alias <alias_name>
use etag
{
use update;
use delete;
use association _travel;
use association _booksup { create; }
}
define behavior for Z_c_BOOKSUPPL1_M3 //alias <alias_name>
use etag
{
use update;
use delete;
use association _travel;
use association _booking;
}
Next we have to create service definition.
Right click on entity and create service definition.
@EndUserText.label: ‘service defnition’
define service Zna_S_travel {
expose ZNA_C_TRAVEL_M1;
expose ZNA_C_BOOKING_M2;
expose Z_c_BOOKSUPPL1_M3;
}
Then now we have to create service binding for service definition.
We have to select binding type.
First we have to publish and Click on entity set and then click on preview.
Create operation
Click on create.
Click on create
Delete.
Select the check box and click on delete it will delete the record .
Now one pop up window will come.
And click on delete.
Then now another behavior how eTag works.
In the root entity for the field we have to specify annotations.
@Semantics.systemDateTime.localInstanceLastChangedAt: true
Go to the behavior definition for root entity.
We have to provide eTag master.
Then for behavior projected entity we have to use etag.
For example i open two tabs in session.
If i click on edit and change the total price .
And i go on another session if i click on same field for edit it throws error like this etag works.
Read operation.
Read entity, short form,
Read statement allows read multiple instance of single entity.
Read entity, long form
Read statement allows read multiple instance of multiple entity.
Read entity operations ,dynamic form.
The dynamic form of the read statement allows collecting multiple instances to be read to be read in multiple read statements in one entity.
For example.
Shorter form.
I create a class for read the travel entity for particular fields.
CLASS zcl_read_operation1 DEFINITION
PUBLIC
FINAL
CREATE PUBLIC .
PUBLIC SECTION.
INTERFACES if_oo_adt_classrun.
PROTECTED SECTION.
PRIVATE SECTION.
ENDCLASS.
CLASS zcl_read_operation1 IMPLEMENTATION.
METHOD if_oo_adt_classrun~main.
READ ENTITY zna_i_travel_m1
FIELDS ( AgencyId CustomerId BeginDate ) WITH VALUE #( ( %key-TravelId = ‘00000008’ ) )
RESULT DATA(LT_RESULT)
FAILED DATA(LT_FAIL).
IF lt_fail IS NOT INITIAL.
OUT->write( ‘READ FAILED’ ) .
ELSE.
OUT->write( LT_RESULT ) .
ENDIF.
ENDMETHOD.
ENDCLASS.
OUTPUT.
Read the travel entity for all fields.
CLASS zcl_read_operation1 DEFINITION
PUBLIC
FINAL
CREATE PUBLIC .
PUBLIC SECTION.
INTERFACES if_oo_adt_classrun.
PROTECTED
SECTION.
PRIVATE SECTION.
ENDCLASS.
CLASS zcl_read_operation1 IMPLEMENTATION.
METHOD if_oo_adt_classrun~main.
READ ENTITY zna_i_travel_m1
all FIELDS WITH VALUE #( ( %key-TravelId = ‘00000008’ ) )
RESULT DATA(LT_RESULT)
FAILED DATA(LT_FAIL).
IF lt_fail IS NOT INITIAL.
OUT->write( ‘READ FAILED’ ) .
ELSE.
OUT->write( LT_RESULT ) .
ENDIF.
ENDMETHOD.
ENDCLASS.
OUTPUT.
read the Item table entity based on header entity.
CLASS zcl_read_operation1 DEFINITION
PUBLIC
FINAL
CREATE PUBLIC .
PUBLIC SECTION.
INTERFACES if_oo_adt_classrun.
PROTECTED SECTION.
PRIVATE SECTION.
ENDCLASS.
CLASS zcl_read_operation1 IMPLEMENTATION.
METHOD if_oo_adt_classrun~main.
READ ENTITY zna_i_travel_m1
by _booking
all FIELDS WITH VALUE #( ( %key-TravelId = ‘00000003’ ) )
RESULT DATA(LT_RESULT)
FAILED DATA(LT_FAIL).
IF lt_fail IS NOT INITIAL.
OUT->write( ‘READ FAILED’ ) .
ELSE.
OUT->write( LT_RESULT ) .
ENDIF.
ENDMETHOD.
ENDCLASS.
OUTPUT.
Longer form.
Read travel entity and booking entity together.
CLASS zcl_read_operation1 DEFINITION
PUBLIC
FINAL
CREATE PUBLIC .
PUBLIC SECTION.
INTERFACES if_oo_adt_classrun.
PROTECTED SECTION.
PRIVATE SECTION.
ENDCLASS.
CLASS zcl_read_operation1 IMPLEMENTATION.
METHOD if_oo_adt_classrun~main.
READ ENTITIES OF zna_i_travel_m1
ENTITY zna_i_travel_m1
all FIELDS WITH VALUE #( ( %key-TravelId = ‘00000008’ ) )
RESULT DATA(LT_RESULT)
ENTITY zna_i_booking_m1
all FIELDS WITH VALUE #( ( %key-TravelId = ‘00000008’
%key-BookingId = ‘00001’ ) )
RESULT DATA(LT_RESULT1)
FAILED DATA(LT_FAIL).
IF lt_fail IS NOT INITIAL.
OUT->write( ‘READ FAILED’ ) .
ELSE.
OUT->write( LT_RESULT ) .
OUT->write( LT_RESULT1 ) .
ENDIF.
ENDMETHOD.
ENDCLASS.
OUTPUT.
Actions.
Actions are the part of the business logic. They are defined in the behavior definition and they implemented in the behavior pool of the business object.
The following kinds of Action available.
Non factory actions : Custom logic that changes existing entity instances.
Factory actions : It can be used to create Rap bo entity instances.
Save actions : it can be non factory actions or factory actions executed during the
Rap save sequence .
Steps to declare actions.
Step1->go to the behavior definition and declare the actions.
Step 2-> implement the methods place cursor on the action click control+1 it will ask to implement.
factory action.
STEP 1-> First we have to declare in behavior definition.
step 2->After the declaration U have to specify the action annotation in define view or metadata extension.
Step3-> we have to implement the logic in action approval travel method inside the class.
Step->4 go to the service binding and select the entity set and click on preview .
Step 5 -> click on any entity bo.
Step 6-> the 14th travel id overall status is open and click on 14th rap bo and click on accept travel action button.
Now it is accepted this is how action button works.
Factory actions.
Instance bound factory actions can copy specfic value of an instance.
Output parameters are not allowed. It always produce one new bo entity instance.
It is mandatory to specify a cardinality. The cardinality must always be[1] for factory actions.
Steps to implement.
Step 1->First we have to declare in behavior definition in managed .
Step 2->we have to declare in projected entity also.
Step 3->go to metadata extension and u have to specify actions.
Step-4 -> in we have to implement our logic in classes.
METHOD copytravel.
data : it_travel TYPE TABLE FOR CREATE zna_i_travel_m1 ,
it_booking TYPE TABLE FOR CREATE zna_i_travel_m1_booking.
read TABLE keys ASSIGNING FIELD-SYMBOL(<ls_field_cid>) WITH KEY %cid = ‘ ‘.
ASSERT <ls_field_cid> is NOT INITIAL.
read ENTITIES OF zna_i_travel_m1 in LOCAL MODE
ENTITY zna_i_travel_m1 all FIELDS WITH CORRESPONDING #( keys )
RESULT DATA(lt_travel)
failed data(lt_failed).
read ENTITIES OF zna_i_travel_m1 in LOCAL MODE
ENTITY zna_i_BOOKING_m1 all FIELDS WITH CORRESPONDING #( keys )
RESULT DATA(lt_booking)
failed data(lt_failed1).
read ENTITIES OF zna_i_travel_m1 in LOCAL MODE
ENTITY zna_i_BOOKING_m1 all FIELDS WITH CORRESPONDING #( keys )
RESULT DATA(lt_booksupp)
failed data(lt_failed2).
LOOP at lt_travel ASSIGNING FIELD-SYMBOL(<ls_travel>).
APPEND VALUE #( %CID = KEYS[ KEY entity TravelId = <ls_travel>-TravelId ]-%cid
%data = CORRESPONDING #( <ls_travel> EXCEPT travelid ) )
TO it_travel ASSIGNING FIELD-SYMBOL(<ls_travel1>).
<ls_travel1>-BeginDate = cl_abap_context_info=>get_system_date( ).
<ls_travel1>-EndDate = cl_abap_context_info=>get_system_date( ) + 30.
<ls_travel1>-BeginDate = cl_abap_context_info=>get_system_date( ).
<ls_travel1>-OverallStatus = ‘O’.
APPEND VALUE #( %CID_REF = <ls_travel1>-%cid ) TO
IT_BOOKING ASSIGNING FIELD-SYMBOL(<LS_BOOKING>).
LOOP AT LT_BOOKING ASSIGNING FIELD-SYMBOL(<LS_BOOKING1>) USING KEY ENTITY
WHERE TRAVELID = <LS_TRAVEL>-TravelId.
APPEND VALUE #( %CID = <ls_travel1>-%cid && <LS_BOOKING1>-BookingId
%DATA = CORRESPONDING #( <LS_BOOKING1> EXCEPT TRAVELID ) )
TO <ls_booking>-%target ASSIGNING FIELD-SYMBOL(<LS_BOOKING_N>).
<ls_booking_n>-BookingStatus = ‘N’.
ENDLOOP.
ENDLOOP.
MODIFY ENTITIES OF zna_i_travel_m1 IN LOCAL MODE
ENTITY zna_i_travel_m1
CREATE FIELDS ( AgencyId CustomerId BeginDate BookingFee CreatedAt CurrencyCode CreatedBy )
with it_travel
ENTITY zna_i_travel_m1
CREATE BY _booking
FIELDS ( BookingDate BookingId ConnectionId CustomerId BookingStatus CurrencyCode CarrierId )
WITH it_booking
MAPPED DATA(IT_MAPPED).
MAPPED-zna_i_travel_m1 = IT_MAPPED-zna_i_travel_m1.
ENDMETHOD.
Step 5->click on any entity and click on copy travel action.
Based on the action it will copy and create the booking instance based on the travel id.
Modify operations.
Modify entity , entities.
Used to perform Rap modify operations on rap bo instance.
This includes Standard operations (Create , Create by , update ,delete) and non standard operations(actions) using the keyword Execute.
Steps.
Step1->Create a class .
Step 2->implement the logic for create operation.
CLASS zcl_na_modify_operations DEFINITION
PUBLIC
FINAL
CREATE PUBLIC .
PUBLIC SECTION.
INTERFACES if_oo_adt_classrun.
PROTECTED SECTION.
PRIVATE SECTION.
ENDCLASS.
CLASS zcl_na_modify_operations IMPLEMENTATION.
METHOD if_oo_adt_classrun~main.
MODIFY entity zna_i_travel_m1
CREATE FROM VALUE #( ( %cid = ‘cid1’
%data-BeginDate = ‘20240722’
%control-BeginDate = if_abap_behv=>mk-on
) )
FAILED FINAL(IT_FAILED)
MAPPED FINAL(IT_MAPPED)
REPORTED FINAL(IT_RESULT).
if it_failed is NOT INITIAL.
out->write( it_failed ) .
else.
out->write( IT_RESULT ).
ENDIF.
ENDMETHOD.
ENDCLASS.
Step 3->Syntax for create operation for both header and item.
Step 4-> Syntax for deleting the rap bo instance.
Syntax for update the rap bo instance.
OR
I am happy to share my very first blog post on SAP RAP (Restful Application Programming) managed Scenario example using flight booking. In this blog i done these functionalities with the use of new syntax. Create. Delete. Update. Read. Etag. Modify. Actions DATA MODEL For example i take flight travel booking. Travel->root entity . Booking->child entity. Booking supplement->child entity/ First we have to create database table . We need to create 3 database tables . First we have to create root entity is travel managing table. @EndUserText.label : ‘ Managing Travels’
@AbapCatalog.enhancement.category : #NOT_EXTENSIBLE
@AbapCatalog.tableCategory : #TRANSPARENT
@AbapCatalog.deliveryClass : #A
@AbapCatalog.dataMaintenance : #RESTRICTED
define table zna_travel_m {
key client : abap.clnt not null;
key travel_id : /dmo/travel_id not null;
agency_id : /dmo/agency_id;
customer_id : /dmo/customer_id;
begin_date : /dmo/begin_date;
end_date : /dmo/end_date;
@Semantics.amount.currencyCode : ‘ytravel_tech_m.currency_code’
booking_fee : /dmo/booking_fee;
@Semantics.amount.currencyCode : ‘ytravel_tech_m.currency_code’
total_price : /dmo/total_price;
currency_code : /dmo/currency_code;
description : /dmo/description;
overall_status : /dmo/overall_status;
created_by : abp_creation_user;
created_at : abp_creation_tstmpl;
last_changed_by : abp_locinst_lastchange_user;
last_changed_at : abp_locinst_lastchange_tstmpl;
}
Second for booking and we have to create foreign relationship with root entity
@EndUserText.label : ‘booking scenario’
@AbapCatalog.enhancement.category : #NOT_EXTENSIBLE
@AbapCatalog.tableCategory : #TRANSPARENT
@AbapCatalog.deliveryClass : #A
@AbapCatalog.dataMaintenance : #RESTRICTED
define table zna_booking_m1 {
key client : abap.clnt not null;
@AbapCatalog.foreignKey.label : ‘Travel’
@AbapCatalog.foreignKey.screenCheck : false
key travel_id : /dmo/travel_id not null
with foreign key [0..*,1] zna_travel_m
where travel_id = zna_booking_m1.travel_id;
key booking_id : /dmo/booking_id not null;
booking_date : /dmo/booking_date;
customer_id : /dmo/customer_id;
carrier_id : /dmo/carrier_id;
connection_id : /dmo/connection_id;
flight_date : /dmo/flight_date;
@Semantics.amount.currencyCode : ‘ybooking_tech_m.currency_code’
flight_price : /dmo/flight_price;
currency_code : /dmo/currency_code;
booking_status : /dmo/booking_status;
last_changed_at : abp_locinst_lastchange_tstmpl;
}
Third one we have to create booking suplement for this one also we need to create foreign key rerlationship with root entity. @EndUserText.label : ‘booking suplemnent’
@AbapCatalog.enhancement.category : #NOT_EXTENSIBLE
@AbapCatalog.tableCategory : #TRANSPARENT
@AbapCatalog.deliveryClass : #A
@AbapCatalog.dataMaintenance : #RESTRICTED
define table zbooksuppl1_m3 {
@AbapCatalog.foreignKey.label : ‘Travel’
@AbapCatalog.foreignKey.screenCheck : false
key travel_id : /dmo/travel_id not null
with foreign key [0..*,1] zna_travel_m
where travel_id = zbooksuppl1_m3.travel_id;
@AbapCatalog.foreignKey.label : ‘Booking’
@AbapCatalog.foreignKey.screenCheck : false
key booking_id : /dmo/booking_id not null
with foreign key [0..*,1] zna_booking_m1
where travel_id = zbooksuppl1_m3.travel_id
and booking_id = zbooksuppl1_m3.booking_id;
key booking_supplement_id : /dmo/booking_supplement_id not null;
supplement_id : /dmo/supplement_id;
@Semantics.amount.currencyCode : ‘ybooksupp_tech_m.currency_code’
price : /dmo/supplement_price;
currency_code : /dmo/currency_code;
last_changed_at : abp_locinst_lastchange_tstmpl;
} Next we have to create interface for root entity @AbapCatalog.viewEnhancementCategory: [#NONE]
@AccessControl.authorizationCheck: #NOT_REQUIRED
@EndUserText.label: ‘travelmanagedinterface’
@Metadata.ignorePropagatedAnnotations: true
@ObjectModel.usageType:{
serviceQuality: #X,
sizeCategory: #S,
dataClass: #MIXED
}
define root view entity zna_i_travel_m1 as select from zna_travel_m
composition [0..*] of zna_i_BOOKING_m1 as _booking
association [0..1] to /DMO/I_Agency as _agency on $projection.AgencyId = _agency.AgencyID
association [0..1] to /DMO/I_Customer as _customer on $projection.CustomerId = _customer.CustomerID
association [0..1] to I_Currency as _currency on $projection.CurrencyCode = _currency.Currency
association [1..1] to /DMO/I_Overall_Status_VH as _overall on $projection.OverallStatus = _overall.OverallStatus
{
key travel_id as TravelId,
agency_id as AgencyId,
customer_id as CustomerId,
begin_date as BeginDate,
end_date as EndDate,
@Semantics.amount.currencyCode: ‘CurrencyCode’
booking_fee as BookingFee,
@Semantics.amount.currencyCode: ‘CurrencyCode’
total_price as TotalPrice,
currency_code as CurrencyCode,
description as Description,
overall_status as OverallStatus,
created_by as CreatedBy,
created_at as CreatedAt,
last_changed_by as LastChangedBy,
@Semantics.systemDateTime.localInstanceLastChangedAt: true
last_changed_at as LastChangedAt,
_booking,
_agency,
_customer,
_currency,
_overall
} Now we have to create interface view for booking. @AbapCatalog.viewEnhancementCategory: [#NONE]
@AccessControl.authorizationCheck: #NOT_REQUIRED
@EndUserText.label: ‘BOOKING’
@Metadata.ignorePropagatedAnnotations: true
@ObjectModel.usageType:{
serviceQuality: #X,
sizeCategory: #S,
dataClass: #MIXED
}
define view entity zna_i_BOOKING_m1 as select from zna_booking_m1
association to parent zna_i_travel_m1 as _travel on $projection.TravelId = _travel.TravelId
composition [0..*] of Z_i_BOOKSUPPL1_M3 as _booksup
association [1..1] to /DMO/I_Carrier as _CARRIER on $projection.CarrierId = _CARRIER.AirlineID
association [1..1] to /DMO/I_Customer as _customer on $projection.CustomerId = _customer.CustomerID
association [1..1] to /DMO/I_Connection as _cONNECTION on $projection.CarrierId = _cONNECTION.AirlineID
and $projection.ConnectionId = _cONNECTION.ConnectionID
association [1..1] to /DMO/I_Booking_Status_VH as _bookstatus on $projection.BookingStatus = _bookstatus.BookingStatus
{
key travel_id as TravelId,
key booking_id as BookingId,
booking_date as BookingDate,
customer_id as CustomerId,
carrier_id as CarrierId,
connection_id as ConnectionId,
flight_date as FlightDate,
@Semantics.amount.currencyCode: ‘CurrencyCode’
flight_price as FlightPrice,
currency_code as CurrencyCode,
booking_status as BookingStatus,
@Semantics.systemDateTime.localInstanceLastChangedAt: true
last_changed_at as LastChangedAt,
_booksup,
_travel,
_CARRIER,
_customer,
_cONNECTION,
_bookstatus
} Now we have to create interface view for booking Supplement. @AbapCatalog.viewEnhancementCategory: [#NONE]
@AccessControl.authorizationCheck: #NOT_REQUIRED
@EndUserText.label: ‘bboking suplement’
@Metadata.ignorePropagatedAnnotations: true
@ObjectModel.usageType:{
serviceQuality: #X,
sizeCategory: #S,
dataClass: #MIXED
}
define view entity Z_i_BOOKSUPPL1_M3 as select from zbooksuppl1_m3
association to parent zna_i_BOOKING_m1 as _booking on $projection.TravelId = _booking.TravelId
and $projection.BookingId = _booking.BookingId
association [1..1] to zna_i_travel_m1 as _travel on $projection.TravelId = _travel.TravelId
association [1..1] to /DMO/I_Supplement as _supplement on $projection.SupplementId = _supplement.SupplementID
association [1..1] to /DMO/I_SupplementText as _supplementtext on $projection.SupplementId = _supplementtext.SupplementID
{
key travel_id as TravelId,
key booking_id as BookingId,
key booking_supplement_id as BookingSupplementId,
supplement_id as SupplementId,
@Semantics.amount.currencyCode : ‘CurrencyCode’
price as Price,
currency_code as CurrencyCode,
@Semantics.systemDateTime.localInstanceLastChangedAt: true
last_changed_at as LastChangedAt,
_travel ,
_supplement,
_supplementtext,
_booking
} Then next now we have to create projection entity. Projection view define service-specific projections including denormalization of underlying data. We define here UI annotations , value help , calculations or defaulting. We have to specify provider contract for root entity. Transactional query.Transactional interface. Analytical query.SQL query. @AccessControl.authorizationCheck: #NOT_REQUIRED
@EndUserText.label: ‘projection entity’
@Metadata.allowExtensions: true
define root view entity ZNA_C_TRAVEL_M1 provider contract transactional_query as projection on zna_i_travel_m1
{
key TravelId,
@ObjectModel.text:{ element: [ ‘AgencyName’ ] }
@Consumption.valueHelpDefinition: [{ entity : { name: ‘/DMO/I_AGENCY’ , element: ‘AgencyId’ } } ]
AgencyId,
_agency.Name as AgencyName,
@ObjectModel.text.element: [ ‘CustomerName’ ]
@Consumption.valueHelpDefinition: [{ entity : { name: ‘/DMO/I_CUSTOMER’ , element: ‘CustomerId’ } } ]
CustomerId,
_customer.LastName as CustomerName,
BeginDate,
EndDate,
BookingFee,
TotalPrice,
@Consumption.valueHelpDefinition: [{ entity : { name: ‘I_CURRENCY’ , element: ‘Currency’ } } ]
CurrencyCode,
Description,
@ObjectModel.text.element: [ ‘OVERALLTEXT’ ]
@Consumption.valueHelpDefinition: [{ entity : { name: ‘/DMO/I_Overall_Status_VH’ , element: ‘OverallStatus’ } } ]
OverallStatus,
_overall._Text.Text as OVERALLTEXT: localized ,
CreatedBy,
CreatedAt,
LastChangedBy,
LastChangedAt,
/* Associations */
_agency,
_booking : redirected to composition child ZNA_C_BOOKING_M2,
_currency,
_customer,
_overall
} Next we have to create metadata extension right click on entity it will ask to create u create with annotate entity to maintain Ui annotations. @Metadata.layer: #CORE
@Search.searchable: true
annotate view ZNA_C_TRAVEL_M1 with
{
@UI.facet: [{ id: ‘Travel’,
purpose: #STANDARD ,
position: 10,
label: ‘Travel’,
type: #IDENTIFICATION_REFERENCE}]
@Search.defaultSearchElement: true
@UI.identification: [{ position: 10 }]
@UI.lineItem: [{ position: 10 }]
TravelId;
@UI : { lineItem: [{ position: 20 }] ,
selectionField: [{ position: 10 }] }
@Search.defaultSearchElement: true
@UI.identification: [{ position: 20 }]
AgencyId;
@UI.lineItem: [{ position: 30 }]
// AgencyName;
// @ui.lineItem: [{ position: 40 }]
@UI.selectionField: [{ position: 20 }]
@Search.defaultSearchElement: true
@UI.identification: [{ position: 30 }]
CustomerId;
@UI.lineItem: [{ position: 50 }]
@UI.identification: [{ position: 40 }]
CustomerName;
@UI.lineItem: [{ position: 60 }]
@UI.identification: [{ position: 50 }]
BeginDate;
@UI.lineItem: [{ position: 70 }]
EndDate;
// @ui.lineItem: [{ position: 80 }]
// BookingFee;
@UI.lineItem: [{ position: 90 }]
@UI.identification: [{ position: 60 }]
TotalPrice;
// @ui.lineItem: [{ position: 100 }]
// CurrencyCode;
// @ui.lineItem: [{ position: 110 }]
// Description;
@UI.lineItem: [{ position: 120 }]
@UI.selectionField: [{ position: 30 }]
@Search.defaultSearchElement: true
OverallStatus ; Then we have to create behavior definition for root entity. Right Click on root entity and create behavior definition. managed ; // implementation in class zbp_na_i_travel_m1 unique;
strict ( 2 );
define behavior for zna_i_travel_m1 //alias travel
implementation in class zcl_bp_na_i_travel_m1 unique
persistent table zna_travel_m
lock master
authorization master ( instance )
etag master LastChangedAt
{
create;
update;
delete;
// field ( readonly ) TravelId;
association _booking { create; }
mapping for zna_travel_m {
TravelId = travel_id;
AgencyId = agency_id;
CustomerId = customer_id;
BeginDate = begin_date;
EndDate = end_date;
BookingFee = booking_fee;
TotalPrice = total_price;
CurrencyCode = currency_code;
Description = description;
OverallStatus = overall_status;
CreatedBy = created_by;
CreatedAt = created_at;
LastChangedBy = last_changed_by;
LastChangedAt = last_changed_at ;
}
}
define behavior for zna_i_BOOKING_m1 //alias <alias_name>
implementation in class zcl_bp_na_i_boking_m1 unique
persistent table zna_booking_m1
lock dependent by _travel
authorization dependent by _travel
etag master LastChangedAt
{
update;
delete;
field ( readonly ) TravelId, BookingId;
association _travel;
association _booksup { create; }
mapping for zna_booking_m1
{
TravelId = travel_id;
BookingId = booking_id;
BookingDate = booking_date;
CustomerId = customer_id;
CarrierId = carrier_id;
ConnectionId = connection_id;
FlightDate = flight_date;
FlightPrice = flight_price;
CurrencyCode = currency_code;
BookingStatus = booking_status;
LastChangedAt = last_changed_at ;
}
}
define behavior for Z_i_BOOKSUPPL1_M3 //alias <alias_name>
implementation in class zcl_bp_na_i_bookingsupp_m1 unique
persistent table zbooksuppl1_m3
lock dependent by _travel
authorization dependent by _travel
etag master LastChangedAt
{
update;
delete;
field ( readonly ) TravelId, BookingId, BookingSupplementId;
association _travel;
association _booking;
mapping for zbooksuppl1_m3 {
TravelId = travel_id;
BookingId = booking_id;
BookingSupplementId = booking_supplement_id;
SupplementId = supplement_id;
Price = price;
CurrencyCode = currency_code;
LastChangedAt = last_changed_at;
}
} And behavior definition for projected entity. projection;
strict ( 2 );
define behavior for ZNA_C_TRAVEL_M1 //alias <alias_name>
use etag
{
use create;
use update;
use delete;
use association _booking { create; }
}
define behavior for ZNA_C_BOOKING_M2 //alias <alias_name>
use etag
{
use update;
use delete;
use association _travel;
use association _booksup { create; }
}
define behavior for Z_c_BOOKSUPPL1_M3 //alias <alias_name>
use etag
{
use update;
use delete;
use association _travel;
use association _booking;
} Next we have to create service definition. Right click on entity and create service definition. @EndUserText.label: ‘service defnition’
define service Zna_S_travel {
expose ZNA_C_TRAVEL_M1;
expose ZNA_C_BOOKING_M2;
expose Z_c_BOOKSUPPL1_M3;
} Then now we have to create service binding for service definition. We have to select binding type. First we have to publish and Click on entity set and then click on preview. Create operation Click on create. Click on create Delete. Select the check box and click on delete it will delete the record . Now one pop up window will come. And click on delete. Then now another behavior how eTag works. In the root entity for the field we have to specify annotations. @Semantics.systemDateTime.localInstanceLastChangedAt: true Go to the behavior definition for root entity. We have to provide eTag master. Then for behavior projected entity we have to use etag. For example i open two tabs in session. If i click on edit and change the total price . And i go on another session if i click on same field for edit it throws error like this etag works. Read operation. Read entity, short form, Read statement allows read multiple instance of single entity. Read entity, long form Read statement allows read multiple instance of multiple entity. Read entity operations ,dynamic form. The dynamic form of the read statement allows collecting multiple instances to be read to be read in multiple read statements in one entity. For example. Shorter form. I create a class for read the travel entity for particular fields. CLASS zcl_read_operation1 DEFINITION
PUBLIC
FINAL
CREATE PUBLIC .
PUBLIC SECTION.
INTERFACES if_oo_adt_classrun.
PROTECTED SECTION.
PRIVATE SECTION.
ENDCLASS.
CLASS zcl_read_operation1 IMPLEMENTATION.
METHOD if_oo_adt_classrun~main.
READ ENTITY zna_i_travel_m1
FIELDS ( AgencyId CustomerId BeginDate ) WITH VALUE #( ( %key-TravelId = ‘00000008’ ) )
RESULT DATA(LT_RESULT)
FAILED DATA(LT_FAIL).
IF lt_fail IS NOT INITIAL.
OUT->write( ‘READ FAILED’ ) .
ELSE.
OUT->write( LT_RESULT ) .
ENDIF.
ENDMETHOD.
ENDCLASS.
OUTPUT.Read the travel entity for all fields. CLASS zcl_read_operation1 DEFINITION
PUBLIC
FINAL
CREATE PUBLIC .
PUBLIC SECTION.
INTERFACES if_oo_adt_classrun.
PROTECTED
SECTION.
PRIVATE SECTION.
ENDCLASS.
CLASS zcl_read_operation1 IMPLEMENTATION.
METHOD if_oo_adt_classrun~main.
READ ENTITY zna_i_travel_m1
all FIELDS WITH VALUE #( ( %key-TravelId = ‘00000008’ ) )
RESULT DATA(LT_RESULT)
FAILED DATA(LT_FAIL).
IF lt_fail IS NOT INITIAL.
OUT->write( ‘READ FAILED’ ) .
ELSE.
OUT->write( LT_RESULT ) .
ENDIF.
ENDMETHOD.
ENDCLASS. OUTPUT.read the Item table entity based on header entity. CLASS zcl_read_operation1 DEFINITION
PUBLIC
FINAL
CREATE PUBLIC .
PUBLIC SECTION.
INTERFACES if_oo_adt_classrun.
PROTECTED SECTION.
PRIVATE SECTION.
ENDCLASS.
CLASS zcl_read_operation1 IMPLEMENTATION.
METHOD if_oo_adt_classrun~main.
READ ENTITY zna_i_travel_m1
by _booking
all FIELDS WITH VALUE #( ( %key-TravelId = ‘00000003’ ) )
RESULT DATA(LT_RESULT)
FAILED DATA(LT_FAIL).
IF lt_fail IS NOT INITIAL.
OUT->write( ‘READ FAILED’ ) .
ELSE.
OUT->write( LT_RESULT ) .
ENDIF.
ENDMETHOD.
ENDCLASS. OUTPUT.Longer form. Read travel entity and booking entity together. CLASS zcl_read_operation1 DEFINITION
PUBLIC
FINAL
CREATE PUBLIC .
PUBLIC SECTION.
INTERFACES if_oo_adt_classrun.
PROTECTED SECTION.
PRIVATE SECTION.
ENDCLASS.
CLASS zcl_read_operation1 IMPLEMENTATION.
METHOD if_oo_adt_classrun~main.
READ ENTITIES OF zna_i_travel_m1
ENTITY zna_i_travel_m1
all FIELDS WITH VALUE #( ( %key-TravelId = ‘00000008’ ) )
RESULT DATA(LT_RESULT)
ENTITY zna_i_booking_m1
all FIELDS WITH VALUE #( ( %key-TravelId = ‘00000008’
%key-BookingId = ‘00001’ ) )
RESULT DATA(LT_RESULT1)
FAILED DATA(LT_FAIL).
IF lt_fail IS NOT INITIAL.
OUT->write( ‘READ FAILED’ ) .
ELSE.
OUT->write( LT_RESULT ) .
OUT->write( LT_RESULT1 ) .
ENDIF.
ENDMETHOD.
ENDCLASS. OUTPUT.Actions. Actions are the part of the business logic. They are defined in the behavior definition and they implemented in the behavior pool of the business object. The following kinds of Action available. Non factory actions : Custom logic that changes existing entity instances. Factory actions : It can be used to create Rap bo entity instances. Save actions : it can be non factory actions or factory actions executed during the Rap save sequence . Steps to declare actions. Step1->go to the behavior definition and declare the actions. Step 2-> implement the methods place cursor on the action click control+1 it will ask to implement.factory action. STEP 1-> First we have to declare in behavior definition. step 2->After the declaration U have to specify the action annotation in define view or metadata extension.Step3-> we have to implement the logic in action approval travel method inside the class.Step->4 go to the service binding and select the entity set and click on preview . Step 5 -> click on any entity bo. Step 6-> the 14th travel id overall status is open and click on 14th rap bo and click on accept travel action button.Now it is accepted this is how action button works.Factory actions. Instance bound factory actions can copy specfic value of an instance. Output parameters are not allowed. It always produce one new bo entity instance. It is mandatory to specify a cardinality. The cardinality must always be[1] for factory actions. Steps to implement. Step 1->First we have to declare in behavior definition in managed . Step 2->we have to declare in projected entity also. Step 3->go to metadata extension and u have to specify actions.Step-4 -> in we have to implement our logic in classes. METHOD copytravel.
data : it_travel TYPE TABLE FOR CREATE zna_i_travel_m1 ,
it_booking TYPE TABLE FOR CREATE zna_i_travel_m1_booking.
read TABLE keys ASSIGNING FIELD-SYMBOL(<ls_field_cid>) WITH KEY %cid = ‘ ‘.
ASSERT <ls_field_cid> is NOT INITIAL.
read ENTITIES OF zna_i_travel_m1 in LOCAL MODE
ENTITY zna_i_travel_m1 all FIELDS WITH CORRESPONDING #( keys )
RESULT DATA(lt_travel)
failed data(lt_failed).
read ENTITIES OF zna_i_travel_m1 in LOCAL MODE
ENTITY zna_i_BOOKING_m1 all FIELDS WITH CORRESPONDING #( keys )
RESULT DATA(lt_booking)
failed data(lt_failed1).
read ENTITIES OF zna_i_travel_m1 in LOCAL MODE
ENTITY zna_i_BOOKING_m1 all FIELDS WITH CORRESPONDING #( keys )
RESULT DATA(lt_booksupp)
failed data(lt_failed2).
LOOP at lt_travel ASSIGNING FIELD-SYMBOL(<ls_travel>).
APPEND VALUE #( %CID = KEYS[ KEY entity TravelId = <ls_travel>-TravelId ]-%cid
%data = CORRESPONDING #( <ls_travel> EXCEPT travelid ) )
TO it_travel ASSIGNING FIELD-SYMBOL(<ls_travel1>).
<ls_travel1>-BeginDate = cl_abap_context_info=>get_system_date( ).
<ls_travel1>-EndDate = cl_abap_context_info=>get_system_date( ) + 30.
<ls_travel1>-BeginDate = cl_abap_context_info=>get_system_date( ).
<ls_travel1>-OverallStatus = ‘O’.
APPEND VALUE #( %CID_REF = <ls_travel1>-%cid ) TO
IT_BOOKING ASSIGNING FIELD-SYMBOL(<LS_BOOKING>).
LOOP AT LT_BOOKING ASSIGNING FIELD-SYMBOL(<LS_BOOKING1>) USING KEY ENTITY
WHERE TRAVELID = <LS_TRAVEL>-TravelId.
APPEND VALUE #( %CID = <ls_travel1>-%cid && <LS_BOOKING1>-BookingId
%DATA = CORRESPONDING #( <LS_BOOKING1> EXCEPT TRAVELID ) )
TO <ls_booking>-%target ASSIGNING FIELD-SYMBOL(<LS_BOOKING_N>).
<ls_booking_n>-BookingStatus = ‘N’.
ENDLOOP.
ENDLOOP.
MODIFY ENTITIES OF zna_i_travel_m1 IN LOCAL MODE
ENTITY zna_i_travel_m1
CREATE FIELDS ( AgencyId CustomerId BeginDate BookingFee CreatedAt CurrencyCode CreatedBy )
with it_travel
ENTITY zna_i_travel_m1
CREATE BY _booking
FIELDS ( BookingDate BookingId ConnectionId CustomerId BookingStatus CurrencyCode CarrierId )
WITH it_booking
MAPPED DATA(IT_MAPPED).
MAPPED-zna_i_travel_m1 = IT_MAPPED-zna_i_travel_m1.
ENDMETHOD. Step 5->click on any entity and click on copy travel action. Based on the action it will copy and create the booking instance based on the travel id. Modify operations. Modify entity , entities. Used to perform Rap modify operations on rap bo instance. This includes Standard operations (Create , Create by , update ,delete) and non standard operations(actions) using the keyword Execute. Steps. Step1->Create a class . Step 2->implement the logic for create operation. CLASS zcl_na_modify_operations DEFINITION
PUBLIC
FINAL
CREATE PUBLIC .
PUBLIC SECTION.
INTERFACES if_oo_adt_classrun.
PROTECTED SECTION.
PRIVATE SECTION.
ENDCLASS.
CLASS zcl_na_modify_operations IMPLEMENTATION.
METHOD if_oo_adt_classrun~main.
MODIFY entity zna_i_travel_m1
CREATE FROM VALUE #( ( %cid = ‘cid1’
%data-BeginDate = ‘20240722’
%control-BeginDate = if_abap_behv=>mk-on
) )
FAILED FINAL(IT_FAILED)
MAPPED FINAL(IT_MAPPED)
REPORTED FINAL(IT_RESULT).
if it_failed is NOT INITIAL.
out->write( it_failed ) .
else.
out->write( IT_RESULT ).
ENDIF.
ENDMETHOD.
ENDCLASS.
Step 3->Syntax for create operation for both header and item. Step 4-> Syntax for deleting the rap bo instance. Syntax for update the rap bo instance. OR Read More Application Development Blog Posts articles
#SAP
+ There are no comments
Add yours