RAP Managed Scenario with Unmanaged Save
Share

[[{“value”:”

Introduction

The ABAP RESTful Application Programming Model (RAP) is SAP’s modern programming model for developing business applications and APIs.

In RAP, we commonly work with two implementation approaches:

  • Managed RAP: The RAP framework handles most of the transactional processing and database operations.

  • Unmanaged RAP: The developer implements the transactional processing and database operations.

But what happens when we want to use the benefits of Managed RAP while still using an existing BAPI or Function Module to save data?

This is where Managed RAP with Unmanaged Save becomes useful.

In this blog, we will create a simple Sales Header application using RAP and call a custom BAPI during the save process.

Comparison of RAP Implementation Types

       Feature                    Managed RAP                      Managed RAP with Unmanaged Save     Unmanaged RAP

Transactional Buffer

Managed by RAP framework

Managed by RAP framework

Managed by developer

CRUD Handling

Managed by RAP framework

Managed by RAP framework

Implemented by developer

Database Save

Managed by RAP framework

Implemented by developer using save_modified

Implemented by developer

Existing BAPI Reuse

Requires custom integration

Easy to integrate

Easy to integrate

Development Effort

Low

Medium

High

Suitable For

New applications with standard database operations

RAP applications that need existing BAPIs or Function Modules

Applications requiring full custom transaction handling

Now we have Custom Sales Header Table

@EndUserText.label : ‘Custom Sales Table’
@AbapCatalog.enhancement.category : #NOT_EXTENSIBLE
@AbapCatalog.tableCategory : #TRANSPARENT
@AbapCatalog.deliveryClass : #A
@AbapCatalog.dataMaintenance : #ALLOWED
define table zbh_sales {
key vbeln : zb_vbeln not null;
ernam : zb_ernam;
erdat : zb_erdat;
vbtyp : zb_vbtyp;
vkorg : zb_vkorg;
last_changed_at : timestampl;

}

Now We Start Creating the RAP Application.

Step 1: Create the Root CDS View

@AccessControl.authorizationCheck: #NOT_REQUIRED
@EndUserText.label: ‘Sales order of manged in unmanaged Save’
@Metadata.ignorePropagatedAnnotations: true
@VDM.viewType: #COMPOSITE
define root view entity zi_sales_ums as select from zbh_sales

{
key vbeln ,
ernam ,
erdat,
vbtyp,
vkorg
}

Step 2: Create the Projection CDS View

@AccessControl.authorizationCheck: #NOT_REQUIRED
@EndUserText.label: ‘projection view for managed in unmanaged save’
@Metadata.ignorePropagatedAnnotations: true
@VDM.viewType: #CONSUMPTION
define root view entity zc_sales_ums
provider contract transactional_query
as projection on zi_sales_ums
{
@UI.facet: [{
label: ‘Sales Header’,
purpose: #STANDARD,
type: #IDENTIFICATION_REFERENCE

}]
@UI. lineItem: [{ position: 10 }]
@UI.identification: [{position: 10 }]
key vbeln,

@UI. lineItem: [{ position: 20 }]
@UI.identification: [{position: 20 }]
ernam,

@UI. lineItem: [{ position: 30 }]
@UI.identification: [{position: 30 }]
erdat,

@UI. lineItem: [{ position: 40 }]
@UI.identification: [{position: 40 }]
vbtyp,

@UI. lineItem: [{ position: 50 }]
@UI.identification: [{position: 50 }]
vkorg
}

Step 3: Create the Behavior Definition

managed implementation in class zbp_i_sales_ums unique;
strict ( 2 );

define behavior for zi_sales_ums alias SalesHeader
//persistent table ZBH_SALES
with unmanaged save
lock master
authorization master ( instance )
//etag master <field_name>
{
create;
update;
delete;
}

Step 4: Creating the Behavior Implementation Class 

CLASS lhc_SalesHeader DEFINITION INHERITING FROM cl_abap_behavior_handler.
PRIVATE SECTION.

METHODS get_instance_authorizations FOR INSTANCE AUTHORIZATION
IMPORTING keys REQUEST requested_authorizations FOR SalesHeader RESULT result.

ENDCLASS.

CLASS lhc_SalesHeader IMPLEMENTATION.

METHOD get_instance_authorizations.
ENDMETHOD.

ENDCLASS.

CLASS lsc_ZI_SALES_UMS DEFINITION INHERITING FROM cl_abap_behavior_saver.
PROTECTED SECTION.

METHODS save_modified REDEFINITION.

METHODS cleanup_finalize REDEFINITION.

ENDCLASS.

CLASS lsc_ZI_SALES_UMS IMPLEMENTATION.

METHOD save_modified.
ENDMETHOD.

METHOD cleanup_finalize.
ENDMETHOD.

ENDCLASS.

Now we Write our Custom Save Logic.

METHOD save_modified.
DATA: lt_sales_insert TYPE STANDARD TABLE OF zbh_sales,
lt_sales_update TYPE STANDARD TABLE OF zbh_sales,
lt_sales_delete TYPE STANDARD TABLE OF zbh_sales,
ls_return type BAPIRET2 .
“”””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””
*Create
“”””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””
IF create-SalesHeader IS NOT INITIAL.

* MOVE-CORRESPONDING create-zi_sales_ums TO lt_sales_insert.
LOOP at create-SalesHeader into data(ls_header).
CALL FUNCTION ‘ZBAPI_SALESHEADER_CREATE’
EXPORTING
sales_header = ls_header
IMPORTING
RETURN = ls_return .
ENDLOOP.
ENDIF.

If update-SalesHeader is not INITIAL.
MOVE-CORRESPONDING update-SalesHeader to lt_sales_update.
“Add The Custom Logic or BAPI or FM’s
ENDIF.

if delete-SalesHeader is not initial.
MOVE-CORRESPONDING delete-SalesHeader to lt_sales_delete.
“Add The Custom Logic or BAPI or FM’s
ENDIF.
ENDMETHOD.

Step 5: Create the Projection Behavior Definition

projection;
strict ( 2 );

define behavior for zc_sales_ums //alias <alias_name>
{
use create;
use update;
use delete;

}

Step 6: Create the Service Definition

@EndUserText.label: ‘service defination for zc_sales_ums’
define service Zsb_sales_ums {
expose zc_sales_ums;
}

Step 7: Create the Service Binding

bhuvaneswarg_0-1794216605567.png

Now Preview the Application:

 

bhuvaneswarg_2-1794216737167.png

Now you can Perform the Custom Save logic .

Conclusion:

The Managed with Unmanaged Save approach in SAP RAP combines automated transactional and CRUD handling with custom database save logic. This hybrid pattern allows developers to modernize applications by reusing legacy BAPIs and Function Modules within the save_modified phase. 

“}]] 

  Read More Technology Blog Posts by Members articles 

#abap

By ali

Leave a Reply