Sample Code

OData PUT Call – DPC_EXT_UPDATE_ENTITY method

This sample code read the incoming data, populate the and raise exception is case of error. Difference between CREATE and UPDATE call is that you have primary key of the entity type.

If you have already developed some OData calls or Fiori Apps, you may realize that any method is capable of creating, updating and deleting business objects in ERP but we follow some best practices as it makes the coding simple and easy to maintain.

As always, the code is not complete and fill in your business logic as per your requirement.


 DATA: ls_suinfo    LIKE er_entity.

 io_data_provider->read_entry_data( IMPORTING es_data = ls_suinfo ).

LS_SUINFO here has the same structure as the entity type (created in SEGW). Data is now received and can be used to run the logic in SAP.

If there is any exception, then raise exception like this:


DATA lv_message   TYPE bapi_msg.

mo_context->get_message_container( )->add_message_text_only(
                                    EXPORTING
                                      iv_msg_type = /iwbep/if_message_container=>gcs_message_type-error
                                      iv_msg_text = CONV bapi_msg( lv_message )
                                    ).
      RAISE EXCEPTION TYPE /iwbep/cx_mgw_busi_exception
        EXPORTING
          textid = /iwbep/cx_mgw_busi_exception=>business_error.

Since this is an update call, it is okay if you do not populate the er_entity set.

If you like the post, do share it with your colleagues and friends and like and follow our social media channels.

Leave a Reply

Your email address will not be published. Required fields are marked *

error

Enjoy this blog? Please spread the word :)

Follow by Email
Twitter
LinkedIn
LinkedIn
Share