RAP additional save

Estimated read time 11 min read

Managed RAP additional save.

Introduction.

We can add external functionality to the managed save sequence by using the extra save. This feature facilitates the reusing of services such as change documents and application logs. The RAP framework defaults to handling managed saves in this way; however, additional steps can be added to the managed save. Here, we use the saver class and the save_modfied method. Updated fields, updated data, and completed operations are all saved when an operation is carried out on an entity’s instance. In this instance, the log table will contain any changed data that takes place within an entity instance.

 In this scenario for the data modified in the instance of an entity the changed data will be saved in the log table.

: create the log table to save the data. 

 

 

 

 

@EndUserText.label : ‘log data changes table’

@AbapCatalog.enhancement.category : #NOT_EXTENSIBLE

@AbapCatalog.tableCategory : #TRANSPARENT

@AbapCatalog.deliveryClass : #A

@AbapCatalog.dataMaintenance : #RESTRICTED

define table znp_t_log_travel {

key client : abap.clnt not null;

key change_id : abap.raw(16) not null;

travelid : /dmo/travel_id not null;

changing_operation : abap.char(10);

changed_field_name : abap.char(32);

changed_value : abap.char(32);

created_at : timestampl;

}

 

 

 

 

 

 

To do this additional save  is used, to save the data in a managed scenario addition.

In the Behavior definition define additional save  For the entity. It will create one local class and method save modified. In the implementation class. 

 

 
When a new instance is created, the additional data is saved in the entity’s database. Log table. 

For to this implement define the saver class and implement the methods in the behavior pool. 

For to save the implemented the save_modified method in the save class. 

 

 

 

 

 

 

METHOD save_modified.
DATA : lt_travel_log TYPE STANDARD TABLE OF znp_t_log_travel.
DATA : lt_travel_log_c TYPE STANDARD TABLE OF znp_t_log_travel.
DATA : lt_travel_log_u TYPE STANDARD TABLE OF znp_t_log_travel.

IF create-znp_i_travel_m IS NOT INITIAL.
lt_travel_log = CORRESPONDING #( create-znp_i_travel_m ).

LOOP AT lt_travel_log ASSIGNING FIELD-SYMBOL(<ls_travel_log>).
<ls_travel_log>-changing_operation = ‘CREATE’.
GET TIME STAMP FIELD <ls_travel_log>-created_at.
READ TABLE create-znp_i_travel_m ASSIGNING FIELD-SYMBOL(<ls_travel>)
WITH TABLE KEY entity
COMPONENTS TravelId = <ls_travel_log>-travelid.

IF sy-subrc IS INITIAL.

IF <ls_travel>-%control-BookingFee = cl_abap_behv=>flag_changed.

<ls_travel_log>-changed_field_name = ‘Booking Fee’.

<ls_travel_log>-changed_value = <ls_travel>-BookingFee.

TRY.

<ls_travel_log>-change_id = cl_system_uuid=>create_uuid_x16_static( ).

CATCH cx_uuid_error.

“handle exception

ENDTRY.

APPEND <ls_travel_log> TO lt_travel_log_c.
ENDIF.

IF <ls_travel>-%control-OverallStatus = cl_abap_behv=>flag_changed.

<ls_travel_log>-changed_field_name = ‘Overall Status’.

<ls_travel_log>-changed_value = <ls_travel>-OverallStatus.

TRY.

<ls_travel_log>-change_id = cl_system_uuid=>create_uuid_x16_static( ).

CATCH cx_uuid_error.

“handle exception

ENDTRY.
APPEND <ls_travel_log> TO lt_travel_log_c.
ENDIF.
ENDIF.
ENDLOOP.
INSERT znp_t_log_travel FROM TABLE @LT_travel_log_c.
ENDIF.

IF update-znp_i_travel_m IS NOT INITIAL.
lt_travel_log = CORRESPONDING #( update-znp_i_travel_m ).

LOOP AT update-znp_i_travel_m ASSIGNING FIELD-SYMBOL(<ls_log_update>).
ASSIGN lt_travel_log[ travelid = <ls_log_update>-travelid ] TO FIELD-SYMBOL(<ls_log_u>).
<ls_log_u>-changing_operation = ‘UPDATE’.

GET TIME STAMP FIELD <ls_log_u>-created_at.
IF <ls_log_update>-%control-customerid = if_abap_behv=>mk-on.
<ls_log_u>-changed_value = <ls_log_update>-customerid.

TRY.
<ls_log_u>-change_id = cl_system_uuid=>create_uuid_x16_static( ) .
CATCH cx_uuid_error.
ENDTRY.

<ls_log_u>-changed_field_name = ‘customer_id’.
APPEND <ls_log_u> TO lt_travel_log_u.
ENDIF.

IF <ls_log_update>-%control-description = if_abap_behv=>mk-on.
<ls_log_u>-changed_value = <ls_log_update>-description.
TRY.
<ls_log_u>-change_id = cl_system_uuid=>create_uuid_x16_static( ) .
CATCH cx_uuid_error.
ENDTRY.
<ls_log_u>-changed_field_name = ‘description’.
APPEND <ls_log_u> TO lt_travel_log_u.
ENDIF.
ENDLOOP.

INSERT znp_t_log_travel FROM TABLE @LT_travel_log_u.

ENDIF.

IF delete-znp_i_travel_m IS NOT INITIAL.
lt_travel_log = CORRESPONDING #( delete-znp_i_travel_m ).
LOOP AT lt_travel_log ASSIGNING FIELD-SYMBOL(<ls_log_del>).
<ls_log_del>-changing_operation = ‘DELETE’.
GET TIME STAMP FIELD <ls_log_del>-created_at.
TRY.
<ls_log_del>-change_id = cl_system_uuid=>create_uuid_x16_static( ) .
CATCH cx_uuid_error.

“handle exception
ENDTRY.
ENDLOOP.

INSERT znp_t_log_travel FROM TABLE @LT_travel_log.
ENDIF.

**********************************************************************

**********************************************************************

DATA: lt_book_suppl TYPE STANDARD TABLE OF znp_t_booksuppl.

IF create-znp_i_booksuppl IS NOT INITIAL.
lt_book_suppl = VALUE #( FOR ls_booksup IN create-znp_i_booksuppl (
travel_id = ls_booksup-TravelId
booking_id = ls_booksup-BookingId
booking_supplement_id = ls_booksup-BookingSupplementId
supplement_id = ls_booksup-SupplementId
price = ls_booksup-Price
currency_code = ls_booksup-CurrencyCode
last_changed_at = ls_booksup-LastChangedAt

) ).
INSERT znp_t_booksuppl FROM TABLE @LT_book_suppl.
endif.

IF update-znp_i_booksuppl IS NOT INITIAL.
lt_book_suppl = VALUE #( FOR ls_booksup IN update-znp_i_booksuppl (
travel_id = ls_booksup-TravelId
booking_id = ls_booksup-BookingId
booking_supplement_id = ls_booksup-BookingSupplementId
supplement_id = ls_booksup-SupplementId
price = ls_booksup-Price
currency_code = ls_booksup-CurrencyCode
last_changed_at = ls_booksup-LastChangedAt

) ).
UPDATE znp_t_booksuppl FROM TABLE @LT_book_suppl.
ENDIF.

IF delete-znp_i_booksuppl IS NOT INITIAL.
lt_book_suppl = VALUE #( FOR ls_del IN delete-znp_i_booksuppl (

travel_id = ls_del-TravelId

booking_id = ls_del-BookingId

booking_supplement_id = ls_del-BookingSupplementId

) ).
DELETE znp_t_booksuppl FROM TABLE @LT_book_suppl.
ENDIF.

ENDMETHOD.

 

 

 

 

. 

 

 For creating an instantiation operation. 

 

 

 

 

Edit operation. 

 

 

 

 

 

 

Delete operation, 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

​ Managed RAP additional save.Introduction.We can add external functionality to the managed save sequence by using the extra save. This feature facilitates the reusing of services such as change documents and application logs. The RAP framework defaults to handling managed saves in this way; however, additional steps can be added to the managed save. Here, we use the saver class and the save_modfied method. Updated fields, updated data, and completed operations are all saved when an operation is carried out on an entity’s instance. In this instance, the log table will contain any changed data that takes place within an entity instance. In this scenario for the data modified in the instance of an entity the changed data will be saved in the log table.: create the log table to save the data.     @EndUserText.label : ‘log data changes table’

@AbapCatalog.enhancement.category : #NOT_EXTENSIBLE

@AbapCatalog.tableCategory : #TRANSPARENT

@AbapCatalog.deliveryClass : #A

@AbapCatalog.dataMaintenance : #RESTRICTED

define table znp_t_log_travel {

key client : abap.clnt not null;

key change_id : abap.raw(16) not null;

travelid : /dmo/travel_id not null;

changing_operation : abap.char(10);

changed_field_name : abap.char(32);

changed_value : abap.char(32);

created_at : timestampl;

}       To do this additional save  is used, to save the data in a managed scenario addition.In the Behavior definition define additional save  For the entity. It will create one local class and method save modified. In the implementation class.   When a new instance is created, the additional data is saved in the entity’s database. Log table. For to this implement define the saver class and implement the methods in the behavior pool. For to save the implemented the save_modified method in the save class.       METHOD save_modified.
DATA : lt_travel_log TYPE STANDARD TABLE OF znp_t_log_travel.
DATA : lt_travel_log_c TYPE STANDARD TABLE OF znp_t_log_travel.
DATA : lt_travel_log_u TYPE STANDARD TABLE OF znp_t_log_travel.

IF create-znp_i_travel_m IS NOT INITIAL.
lt_travel_log = CORRESPONDING #( create-znp_i_travel_m ).

LOOP AT lt_travel_log ASSIGNING FIELD-SYMBOL(<ls_travel_log>).
<ls_travel_log>-changing_operation = ‘CREATE’.
GET TIME STAMP FIELD <ls_travel_log>-created_at.
READ TABLE create-znp_i_travel_m ASSIGNING FIELD-SYMBOL(<ls_travel>)
WITH TABLE KEY entity
COMPONENTS TravelId = <ls_travel_log>-travelid.

IF sy-subrc IS INITIAL.

IF <ls_travel>-%control-BookingFee = cl_abap_behv=>flag_changed.

<ls_travel_log>-changed_field_name = ‘Booking Fee’.

<ls_travel_log>-changed_value = <ls_travel>-BookingFee.

TRY.

<ls_travel_log>-change_id = cl_system_uuid=>create_uuid_x16_static( ).

CATCH cx_uuid_error.

“handle exception

ENDTRY.

APPEND <ls_travel_log> TO lt_travel_log_c.
ENDIF.

IF <ls_travel>-%control-OverallStatus = cl_abap_behv=>flag_changed.

<ls_travel_log>-changed_field_name = ‘Overall Status’.

<ls_travel_log>-changed_value = <ls_travel>-OverallStatus.

TRY.

<ls_travel_log>-change_id = cl_system_uuid=>create_uuid_x16_static( ).

CATCH cx_uuid_error.

“handle exception

ENDTRY.
APPEND <ls_travel_log> TO lt_travel_log_c.
ENDIF.
ENDIF.
ENDLOOP.
INSERT znp_t_log_travel FROM TABLE @LT_travel_log_c.
ENDIF.

IF update-znp_i_travel_m IS NOT INITIAL.
lt_travel_log = CORRESPONDING #( update-znp_i_travel_m ).

LOOP AT update-znp_i_travel_m ASSIGNING FIELD-SYMBOL(<ls_log_update>).
ASSIGN lt_travel_log[ travelid = <ls_log_update>-travelid ] TO FIELD-SYMBOL(<ls_log_u>).
<ls_log_u>-changing_operation = ‘UPDATE’.

GET TIME STAMP FIELD <ls_log_u>-created_at.
IF <ls_log_update>-%control-customerid = if_abap_behv=>mk-on.
<ls_log_u>-changed_value = <ls_log_update>-customerid.

TRY.
<ls_log_u>-change_id = cl_system_uuid=>create_uuid_x16_static( ) .
CATCH cx_uuid_error.
ENDTRY.

<ls_log_u>-changed_field_name = ‘customer_id’.
APPEND <ls_log_u> TO lt_travel_log_u.
ENDIF.

IF <ls_log_update>-%control-description = if_abap_behv=>mk-on.
<ls_log_u>-changed_value = <ls_log_update>-description.
TRY.
<ls_log_u>-change_id = cl_system_uuid=>create_uuid_x16_static( ) .
CATCH cx_uuid_error.
ENDTRY.
<ls_log_u>-changed_field_name = ‘description’.
APPEND <ls_log_u> TO lt_travel_log_u.
ENDIF.
ENDLOOP.

INSERT znp_t_log_travel FROM TABLE @LT_travel_log_u.

ENDIF.

IF delete-znp_i_travel_m IS NOT INITIAL.
lt_travel_log = CORRESPONDING #( delete-znp_i_travel_m ).
LOOP AT lt_travel_log ASSIGNING FIELD-SYMBOL(<ls_log_del>).
<ls_log_del>-changing_operation = ‘DELETE’.
GET TIME STAMP FIELD <ls_log_del>-created_at.
TRY.
<ls_log_del>-change_id = cl_system_uuid=>create_uuid_x16_static( ) .
CATCH cx_uuid_error.

“handle exception
ENDTRY.
ENDLOOP.

INSERT znp_t_log_travel FROM TABLE @LT_travel_log.
ENDIF.

**********************************************************************

**********************************************************************

DATA: lt_book_suppl TYPE STANDARD TABLE OF znp_t_booksuppl.

IF create-znp_i_booksuppl IS NOT INITIAL.
lt_book_suppl = VALUE #( FOR ls_booksup IN create-znp_i_booksuppl (
travel_id = ls_booksup-TravelId
booking_id = ls_booksup-BookingId
booking_supplement_id = ls_booksup-BookingSupplementId
supplement_id = ls_booksup-SupplementId
price = ls_booksup-Price
currency_code = ls_booksup-CurrencyCode
last_changed_at = ls_booksup-LastChangedAt

) ).
INSERT znp_t_booksuppl FROM TABLE @LT_book_suppl.
endif.

IF update-znp_i_booksuppl IS NOT INITIAL.
lt_book_suppl = VALUE #( FOR ls_booksup IN update-znp_i_booksuppl (
travel_id = ls_booksup-TravelId
booking_id = ls_booksup-BookingId
booking_supplement_id = ls_booksup-BookingSupplementId
supplement_id = ls_booksup-SupplementId
price = ls_booksup-Price
currency_code = ls_booksup-CurrencyCode
last_changed_at = ls_booksup-LastChangedAt

) ).
UPDATE znp_t_booksuppl FROM TABLE @LT_book_suppl.
ENDIF.

IF delete-znp_i_booksuppl IS NOT INITIAL.
lt_book_suppl = VALUE #( FOR ls_del IN delete-znp_i_booksuppl (

travel_id = ls_del-TravelId

booking_id = ls_del-BookingId

booking_supplement_id = ls_del-BookingSupplementId

) ).
DELETE znp_t_booksuppl FROM TABLE @LT_book_suppl.
ENDIF.

ENDMETHOD.    .   For creating an instantiation operation.     Edit operation.       Delete operation,                 Read More Technology Blogs by Members articles 

#SAP

#SAPTechnologyblog

You May Also Like

More From Author