cancel
Showing results for 
Search instead for 
Did you mean: 

RAP: Using state message causes error

MioYasutake
Active Contributor
0 Kudos

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

Accepted Solutions (1)

Accepted Solutions (1)

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
Active Contributor
0 Kudos

Hi juryrychko,

Thanks for letting me know about this!

Answers (1)

Answers (1)

0 Kudos

Hello,

I'm on a 2021 SP2 system and couldn't find on the link mentioned above which release had or solved the issue. Please, are you aware if by any chance this error also affects messages on child entities in any way?

I have a validation running on save for Child entity, which is a list item within my object page, and I'm unable to properly highlight a field as you can see on the following print - the row is marked as unknown.

I checked this over and over but couldn't figure out what is missing. Shouldn't the following set of parameters be enough to provide a message with a highlight? I'm also feeding %tky to failed-child.

reported-child=
  VALUE #(
    BASE reported-child(
      %tky = ls_child-%tky
      %path = VALUE #(
        root-%is_draft = ls_child-%is_draft
        root-%key-RootUUID = ls_child-RootUUID
      )
      %msg = new_message(
        id       = 'ZTEST_MSG'
        number   = '018'
        severity = if_abap_behv_message=>severity-error
      )
      %element-%field-allocatedquantity = if_abap_behv=>mk-on
      "%state_area = 'qty_not_null'
      "%element-%assoc-_root = if_abap_behv=>mk-on
    )
).
"OData response 

{
    "error": {
        "code": "ZTEST_MSG/018",
        "message": "Allocated Quantity must be informed.",
        "target": "$Parameter/_it/_Child(ChildUUID=000d3a17-2339-1eed-ae8d-a23793571f23,IsActiveEntity=true)/AllocatedQuantity",
        "@SAP__common.ExceptionCategory": "Provider_Application_Error",
        "innererror": {
            "ErrorDetails": {
                "@SAP__common.Application": {
                    "ComponentId": "BC-ESI-ESF-GW",
                    "ServiceRepository": "SRVD",
                    "ServiceId": "ZTEST_SRV",
                    "ServiceVersion": "0001"
                },
                "@SAP__common.TransactionId": "039B658AE04600D0E0063F06F0085867",
                "@SAP__common.Timestamp": "20230301220915.319091",
                "@SAP__common.ErrorResolution": {
                    "Analysis": "Use ADT feed reader \"SAP Gateway Error Log\" or run transaction /IWFND/ERROR_LOG on SAP Gateway hub system and search for entries with the timestamp above for more details",
                    "Note": "See SAP Note 1797736 for error analysis (https://service.sap.com/sap/support/notes/1797736)"
                }
            }
        }
    }
}