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.
cancel
Showing results for 
Search instead for 
Did you mean: 
Nachiketh
Newcomer
19,970

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 

 

Nachiketh_3-1722318640764.png

 

 

DATA MODEL 

Nachiketh_4-1722318640766.png

 

 

 

For example i take flight travel booking. 

  1. Travel->root entity . 
  1. Booking->child entity. 
  1. 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. 

Nachiketh_5-1722318672553.png

 

 

@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 

Nachiketh_6-1722318876584.png

 

 

@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. 
  1. Transactional query.
  2. Transactional interface. 
  3. Analytical query.
  4. SQL query.

Nachiketh_7-1722319218378.png

 

 

@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. 

Nachiketh_8-1722319313998.png

 

 

@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 ; 

 

Nachiketh_9-1722319394121.png

 

Then we have to create behavior definition for root entity. 

Right Click on root entity and create behavior definition. 

Nachiketh_10-1722319413897.png

 

 

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.

Nachiketh_11-1722319654490.png

 

 

@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. 

Nachiketh_12-1722319748102.png

 

We have to select binding type. 

Nachiketh_13-1722319771051.png

 

First we have to publish and Click on entity set and then click on preview. 

Create operation 

Nachiketh_14-1722319780914.png

 

 

Click on create. 

Nachiketh_15-1722319801259.png

 

 

Click on create 

Nachiketh_16-1722319801261.png

 

 

Delete. 

Select the check box and click on delete it will delete the record . 

Nachiketh_17-1722319801264.png

 

 

Now one pop up window will come. 

Nachiketh_18-1722319906861.png

And click on delete.

Nachiketh_19-1722319952298.png

 

Then now another behavior how eTag works. 

In the root entity for the field we have to specify annotations. 

@Semantics.systemDateTime.localInstanceLastChangedAt: true 

Nachiketh_20-1722319999696.png

Go to the behavior definition for root entity. 

Nachiketh_21-1722320064644.png

We have to provide eTag master. 

Then for behavior projected entity we have to use etag. 

Nachiketh_22-1722320126637.png

For example i open two tabs in session. 

Nachiketh_23-1722320159456.png

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. 

Nachiketh_24-1722320199034.png

 

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.

Nachiketh_27-1722320446973.png

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.

Nachiketh_28-1722320580737.png

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.

Nachiketh_29-1722320668381.png

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.

Nachiketh_30-1722320729202.png

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. 

Nachiketh_31-1722320768674.png

Step 2-> implement the methods place cursor on the action click control+1 it will ask to implement.

Nachiketh_32-1722321093174.png

factory action. 

STEP 1-> First we have to declare in behavior definition. 

Nachiketh_33-1722321156065.png

step 2->After the declaration U have to specify the action annotation in define view or metadata extension.

Nachiketh_34-1722321233180.png

Step3-> we have to implement the logic in action  approval travel method inside the class.

Nachiketh_35-1722321277585.png

Step->4 go to the service binding and  select the entity set and click on preview . 

Nachiketh_36-1722321313596.png

Step 5 -> click on any entity bo. 

Nachiketh_37-1722321350768.png

Step 6-> the 14th travel id overall status is open and click on 14th rap bo and click on accept travel action button.

Nachiketh_38-1722321386363.png

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 . 

Nachiketh_39-1722321428070.png

 

Step 2->we have to declare in projected entity also. 

Nachiketh_40-1722321448543.png

 

Step 3->go to metadata extension  and u have to specify actions.

Nachiketh_41-1722321469034.png

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. 

Nachiketh_42-1722321605063.png

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 . 

Nachiketh_43-1722321654253.png

 

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. 

Nachiketh_44-1722321705907.png

Step 4-> Syntax for deleting the rap bo instance. 

Nachiketh_45-1722321748409.png

 

 Syntax for update the rap bo instance. 

Nachiketh_46-1722321787325.png

 

                             OR

Nachiketh_47-1722321821452.png

 

 

 

 

1 Comment