OData Gateway
Architect / Cross-trackAdvanced

CREATE_ENTITY, UPDATE_ENTITY and DELETE_ENTITY

Implement write operations safely with payload reading, validation, BAPI calls and error messages.

Explanation

Write operations in OData are handled through CREATE_ENTITY, UPDATE_ENTITY and DELETE_ENTITY. The request payload must be read from IO_DATA_PROVIDER. Then data should be validated, mapped to SAP structures and processed through BAPIs, classes or business APIs. Direct database updates should be avoided for standard business documents. Error messages must be returned clearly so Fiori or external clients can show meaningful feedback. Transaction handling should follow the business API contract. For BAPIs, BAPI_TRANSACTION_COMMIT is usually called after successful processing.

Code example

ABAP Code
* Purpose:* Basic CREATE_ENTITY pattern.* Read payload, validate, call business logic and return created entity. METHOD orderset_create_entity.   DATA ls_input  TYPE zcl_zorder_mpc=>ts_order.  DATA ls_output TYPE zcl_zorder_mpc=>ts_order.   * Step 1: Read request payload from OData body  io_data_provider->read_entry_data(    IMPORTING      es_data = ls_input ).   * Step 2: Validate mandatory data before posting  IF ls_input-customer_id IS INITIAL.    RAISE EXCEPTION TYPE /iwbep/cx_mgw_busi_exception.  ENDIF.   * Step 3: Delegate posting logic to service class or BAPI wrapper  DATA(lo_service) = NEW zcl_order_create_service( ).   ls_output = lo_service->create_order( ls_input ).   * Step 4: Return created entity to caller  er_entity = ls_output. ENDMETHOD.

Real project scenario

A customer portal creates service requests through OData. CREATE_ENTITY reads JSON payload, validates mandatory fields, calls a custom service class and returns the created request number.

Common mistakes

- Not reading payload correctly. - Directly updating SAP standard tables. - Not validating mandatory fields. - Not returning created entity or error details.

Best practices

- Use business APIs or service classes. - Validate before posting. - Return clear errors. - Avoid direct standard table updates. - Handle transaction carefully.

Interview angle

A senior answer should mention payload reading, validation, BAPI/service call, commit and Gateway exceptions.