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

BEHAVIOR_STATEMENT_ILLEGAL error using EML for entity I_ServiceOrderTP

TajShaik
Explorer
0 Likes
1,825

 While using RAP EML to update the startdatetime of a service order, I encountered the following ABAP runtime error: 

Help me understand why am I getting this error.

Short Text:
Statement "MODIFY ENTITIES" is not allowed with this status.

Runtime Error:
BEHAVIOR_STATEMENT_ILLEGAL

Program:
CL_IRES_RESERVATION===========CP

Application Component:
MM-IM-RS


Scenario and Code Overview:

I have developed a managed RAP application for stock transfer. Within this application, I have implemented an Action to handle stock transfer, and inside the action method of the behavior implementation class, I am invoking the API API_MATERIAL_DOCUMENT_SRV.

Everything works fine up to this point. However, after successfully creating the material document, there is a requirement to update the start date of the service order. To achieve this, I attempted to use EML (Entity Manipulation Language) to update the requestedservicestartdatetime field.

Unfortunately, this results in a BEHAVIOR_STATEMENT_ILLEGAL error.


Code Snippet:

Inside the action method, the public API is called to create a material document:

** Call public API for warehouse-managed scenario
public_api_post( EXPORTING is_param = ls_param
it_items = lt_items
it_srnobin = lt_srnobin
it_issueqty = lt_issueqty
it_srnoprofile = lt_srnoprofile
IMPORTING ev_get_resp_stat = DATA(lv_get_resp_stat)
ev_get_resp_text = DATA(lv_get_resp_text)
ev_post_resp_stat = DATA(lv_post_resp_stat)
ev_post_resp_text = DATA(lv_post_resp_text)
ev_exception_msg = DATA(lv_exception_msg) ).

IF lv_post_resp_stat-code = '201' OR lv_post_resp_stat-code = '200'.

** Fetch the requested service start date based on service order
SELECT SINGLE requestedservicestartdatetime FROM i_serviceordertp
WHERE serviceorder = @iv_serviceorder INTO @DATA(lv_startdate).

** Add 60 seconds (1 minute) to the start time
CALL METHOD cl_abap_tstmp=>add
EXPORTING
tstmp = lv_startdate
secs = 60
RECEIVING
r_tstmp = lv_startdate.

** Attempt to update the service order with the new start date
MODIFY ENTITIES OF i_serviceordertp FORWARDING PRIVILEGED
ENTITY serviceorder
UPDATE FIELDS ( requestedservicestartdatetime )
WITH VALUE #( ( serviceorder = iv_serviceorder
requestedservicestartdatetime = lv_startdate
* %control = VALUE #( requestedservicestartdatetime = cl_abap_behv=>flag_changed )
) )
FAILED DATA(lt_failed_modify)
MAPPED DATA(lt_mapped_modify)
REPORTED DATA(lt_reported_modify).

ENDIF.

 

Runtime Error Details:

The ABAP program "CL_IRES_RESERVATION===========CP" terminated due to an invalid statement execution.

Error Analysis:

  • The statement "MODIFY ENTITIES" is only permitted in specific phases of RAP behavior execution.
  • The execution is currently in the "SAVE" phase, where modifying data using MODIFY ENTITIES is not allowed.
  • The error message confirms that EML statements like "MODIFY ENTITY" and "COMMIT ENTITY" are not permitted in certain contexts, including:
    • UPDATE TASK processing
    • PERFORM ON COMMIT
    • PERFORM ON ROLLBACK
    • Event handlers for COMMIT WORK and ROLLBACK WORK

      Termination Point:

      • Program: CL_IRES_RESERVATION===========CP
      • Include: CL_IRES_RESERVATION===========CM00K
      • Line Number: 15

         

Accepted Solutions (0)

Answers (1)

Answers (1)

Chuma
Active Contributor
0 Likes

Hello @TajShaik 

You’re encountering BEHAVIOR_STATEMENT_ILLEGAL because MODIFY ENTITIES (EML) is only allowed during the interaction phase and within the finalise method of a saver, not during save/commit processing or in UPDATE TASK contexts. In your flow, after posting the material document via the public API—which triggers its own save/commit—your action continues in a state where EML is not permitted, hence the dump. SAP Help Portal/ABAP Keyword Documentation

What needs to be changed
Choose one of these supported patterns

  1. Do the EML update earlier (interaction phase).
    Update I_ServiceOrderTP.requestedServiceStartDateTime before calling the material document API, such as during the interaction phase. SAP Help Portal
  2. Split the steps into two LUWs.
    After the API finishes, trigger the service-order update in a separate behaviour session (e.g., an asynchronous follow-up or a small wrapper that runs after commit), or call the released OData API for Service Order in a new HTTP call—outside the current save. (EML across a foreign BO is not allowed during save.) SAP Help Portal
  3. Only for the same BO changes in save:
    If you must adjust your own BO during save, use MODIFY ENTITIES **IN LOCAL MODE** inside finalise but this works only for the same BO, not for I_ServiceOrderTP (a foreign/reuse BO). SAP Help Portal

Why the dump points to CL_IRES_RESERVATION...
That class shows you where you are in the runtime that processes the save/commit logic. In that status, EML modify is disallowed by design. SAP Help Portal/Save Sequence Runtime

References

With kind regards

Chuma

matus_humaj
Discoverer
0 Likes
Hello, Chuma. What would you recommend for us, we are facing same issue but a difference - we are not calling I_ServiceOrderTP from our custom RAP BO but from a standard ABAP class that serves as a application jobs. The issue occurs in just few Service Orders ( < 10 ) out of ~15 000. In the application jobs we just modify a custom YY1 fields on the Service Order Item and when we call COMMIT ENTITIES we get a shortdump. Thank you in advance, Matus
matus_humaj
Discoverer
0 Likes

Sorry, duplicate comment.