CL_ABAP_BEHAVIOR_SAVER_FAILED in RAP
Learn how to use cl_abap_behavior_saver_failed in RAP to access the failed parameter in save_modified and stop the save process on errors.
We recently had a scenario in RAP (Managed with Unmanaged Save) where we needed to call a BAPI inside save_modified. This BAPI performs its own validations, and based on the result, we wanted to stop the save process if any errors occurred.
The challenge was related to the method signature of save_modified. By default, it only provides the reported parameter — there is no failed parameter available. Because of this, even when the BAPI returned an error, we had no direct way to populate failed and properly stop the save sequence.
To handle this, we changed the saver class inheritance from cl_abap_behavior_saver to cl_abap_behavior_saver_failed.
After doing this, the failed parameter became available. This allowed us to populate failed when the BAPI returned an error and correctly stop the execution, which was then reflected properly in the UI.
Inheriting from cl_abap_behavior_saver (no failed parameter):
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
CLASS lsc_class DEFINITION INHERITING FROM cl_abap_behavior_saver.
PROTECTED SECTION.
METHODS save_modified REDEFINITION.
ENDCLASS.
CLASS lsc_class IMPLEMENTATION.
METHOD save_modified.
LOOP AT update-entity_name ASSIGNING FIELD-SYMBOL(<fs>).
reported-entity_name = VALUE #( BASE reported-entity_name
( %key = <fs>-%key
%msg = new_message_with_text(
severity = if_abap_behv_message=>severity-error
text = 'some error' ) ) ).
ENDLOOP.
ENDMETHOD.
ENDCLASS.
Inheriting from cl_abap_behavior_saver_failed (failed parameter available):
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
CLASS lsc_class DEFINITION INHERITING FROM cl_abap_behavior_saver_failed.
PROTECTED SECTION.
METHODS save_modified REDEFINITION.
ENDCLASS.
CLASS lsc_class IMPLEMENTATION.
METHOD save_modified.
LOOP AT update-entity_name ASSIGNING FIELD-SYMBOL(<fs>).
failed-entity_name = VALUE #( BASE failed-entity_name
( %key = <fs>-%key ) ).
reported-entity_name = VALUE #( BASE reported-entity_name
( %key = <fs>-%key
%msg = new_message_with_text(
severity = if_abap_behv_message=>severity-error
text = 'some error' ) ) ).
ENDLOOP.
ENDMETHOD.
ENDCLASS.
Note: The use of
cl_abap_behavior_saver_failedis recommended only for exceptional cases. For more details on when and how to use it, refer to the SAP Help documentation.
📄 View PDF