Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

RAP: Error message in the definition method

imihailovs
Explorer
0 Kudos

Hello experts,

Does anybody know if it is possible to stop behavior execution and return the error back to API caller from the FOR DETERMINE method? I am using this method to call a BAPI and change my currently processed entity with a transaction ID returned from the BAPI. However, if the BAPI fails for any reason - I would like to return the error message back to API caller. I have tried populating REPORTED itab, but that doesn't stop the execution and save is eventually executed.

I know that this is possible via FOR VALIDATE methods and with FAILED itab, however I need to use the MODIFY ENTITIES statement (to update currently processed entity) which I cannot use in FOR VALIDATE method (hard error).

Any suggestions

1 REPLY 1

imihailovs
Explorer
0 Kudos

I think I somewhat figured it out.

First, in FOR DETERMINE method I store the message in %msg object of the reported structure, like so:

INSERT VALUE #( orderuuid   = <fs_repair_order>-orderuuid
                %create     = if_abap_behv=>mk-on
                %state_area = 'XYZ'
                %msg        = me->new_message_with_text( severity = CONV #( <fs_response>-type )
                                                         text     = <fs_response>-message ) ) INTO TABLE reported-repairorder.

Then in FOR VALIDATE ON SAVE, I read the entity in question like so:

READ ENTITIES OF zoem_i_repairorder IN LOCAL MODE
    ENTITY repairorder
    ALL FIELDS WITH CORRESPONDING #( keys )
    RESULT DATA(lt_data)
    REPORTED DATA(lt_reported_data).

In this case, lt_reported_data will contain the entity with %msg content that I can analyze and, if any errors are present, populate the "failed" structure.

If anyone knows different (more correct way) of doing it - please let me know.