on ‎2021 Dec 17 10:02 PM
I am developing a simple RAP service using BTP ABAP trial environment.
I have implemented a validation with the following code.
This BO is managed, draft-enabled, and the validation is triggered at the point of save.
validation mandatory_check on save {create; update; field FirstName, LastName; }
METHOD mandatory_check.
"Get Mandatory Fields
READ ENTITIES OF zi_person_m IN LOCAL MODE
ENTITY Person
FIELDS ( FirstName LastName )
WITH CORRESPONDING #( keys )
RESULT DATA(persons).
"Do check
LOOP AT persons INTO DATA(person).
APPEND VALUE #( %tky = person-%tky
%state_area = 'mandatory_check')
TO reported-person.
IF person-FirstName IS INITIAL.
"Set failed keys
APPEND VALUE #( %tky = person-%tky )
TO failed-person.
"Set message
APPEND VALUE #( %tky = person-%tky
%element-FirstName = if_abap_behv=>mk-on
%state_area = 'mandatory_check'
%msg = new_message(
id = 'ZRAP_MSG_YASU2122_2'
number = 001
severity = if_abap_behv_message=>severity-error
v1 = 'First Name'
) )
TO reported-person.
ENDIF.
ENDLOOP.
ENDMETHOD.<br>
However, specifying %state_area = 'mandatory_check' causes the app to throw error. The following screen appears after the validation gets triggered.

Below code (without %state_area)works fine.
"Do check
LOOP AT persons INTO DATA(person).
IF person-FirstName IS INITIAL.
"Set failed keys
APPEND VALUE #( %tky = person-%tky )
TO failed-person.
"Set message
APPEND VALUE #( %tky = person-%tky
%element-FirstName = if_abap_behv=>mk-on
%msg = new_message(
id = 'ZRAP_MSG_YASU2122_2'
number = 001
severity = if_abap_behv_message=>severity-error
v1 = 'First Name'
) )
TO reported-person.
ENDIF.
ENDLOOP.<br>
According to the doc, state message can be used for validation on save in Managed Scenario.
Business Object with Draft Capabilities: Determinations and Validation that are allocated to the PREPARE or a determine action
Unmanaged Business Object: Finalize/Check Before Save Code Exit
Managed Scenario: Determinations/Validation on Save
Do you have any idea what is causing this error? Should I use state message for my scenario or not?
Best regards,
Mio
Request clarification before answering.
Hi Mio,
Perhaps this link will explane the problem to you. (This is a known backend problem that will be fixed with the upcoming release.)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
| User | Count |
|---|---|
| 15 | |
| 9 | |
| 6 | |
| 4 | |
| 4 | |
| 4 | |
| 3 | |
| 2 | |
| 2 | |
| 2 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.