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

RAP Action: The command "COMMIT-ENTITIES" is not allowed in a BEHAVIOR class

jheisler83
Explorer
0 Kudos
4,598

I have a business use case in which an enduser selects one or more sales orders in a custom app and presses an action to allocate them to another department.

In this allocation process the selected sales orders need to be modified in the backend.

My backend is a RAP-based OData v2 service with an action to allocate the sales orders an modify them:

 

action AfterSalesAllocate result [1..*] $self;

 

In my action implementation i am modifying the sales orders via EML and trying to commit the changes:

 

LOOP AT lt_aggr_ic_so ASSIGNING <ls_aggr_ic_so>.
            MODIFY ENTITIES OF r_salesordertp
                   ENTITY salesorderitem
                   EXECUTE removebillingblock
                   FROM VALUE #( ( %key-salesorder     = <ls_aggr_ic_so>-receivingreturnorder
                                   %key-salesorderitem = <ls_aggr_ic_so>-receivingreturnitem ) )
                   " TODO: variable is assigned but never used (ABAP cleaner)
                   FAILED   DATA(ls_failed_removebillingblock)
                   " TODO: variable is assigned but never used (ABAP cleaner)
                   REPORTED DATA(ls_reported_removebillingblock).

            MODIFY ENTITIES OF r_salesordertp
                   ENTITY salesorderitem
                   UPDATE
                   FIELDS ( requestedquantity )
                   WITH VALUE #( ( requestedquantity   = <ls_aggr_ic_so>-quantity
                                   %key-salesorder     = <ls_aggr_ic_so>-receivingreturnorder
                                   %key-salesorderitem = <ls_aggr_ic_so>-receivingreturnitem ) )
                   " TODO: variable is assigned but never used (ABAP cleaner)
                   FAILED   DATA(ls_failed_update)
                   " TODO: variable is assigned but never used (ABAP cleaner)
                   REPORTED DATA(ls_reported_update).

            COMMIT ENTITIES
                   RESPONSE OF i_salesordertp
                     " TODO: variable is assigned but never used (ABAP cleaner)
                   FAILED   DATA(ls_save_failed)
                   " TODO: variable is assigned but never used (ABAP cleaner)
                   REPORTED DATA(ls_save_reported).
          ENDLOOP.

 

But unfortunately i am receiving the error "The command "COMMIT-ENTITIES" is not allowed in a BEHAVIOR class." when activating and i don´t get why.

Aren´t actions meant to be able to modify its entities objects? Is there any workaround someone can suggest?

Accepted Solutions (1)

Accepted Solutions (1)

DiegoValdivia
Active Participant

See next extract from SAP help "COMMIT ENTITIES must be explicitly specified for change operations
that are triggered outside of a behavior implementation".

That means it's not required to call COMMIT ENTITIES inside an action.

Andre_Fischer
Product and Topic Expert
Product and Topic Expert
0 Kudos

Diego is right. You must not perform COMMIT ENTITIES within the behavior implementation.
Therefore I marked it as solved.

popcorn
Newcomer
0 Kudos
How to capture errors if it fails to update sales order, since we cannot do commit ls_save_failed will be blank

Answers (1)

Answers (1)

junwu
SAP Champion
SAP Champion
0 Kudos

you are allow to make change in action, but it doesn't mean you have to use COMMIT-ENTITIES to persist the change.

just remove it.

Priya_Saindhavi22
Discoverer
0 Kudos
Hi, You can use cl_abap_behaviour_saver_failed implementation to get failed records.