cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

RAP: Using state message causes error

MioYasutake
SAP Champion
SAP Champion
0 Likes
13,239

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

View Entire Topic
juryrychko
Explorer

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

MioYasutake
SAP Champion
SAP Champion
0 Likes

Hi juryrychko,

Thanks for letting me know about this!

argupta199315
Associate
Associate
0 Likes

Hello juryrychko,
Is this backend problem solved? As I am also getting the error. So just wanted to know if it still exists or is there a way to fix the issue?

Thanks!