Sunday, May 31, 2026

OData 5: Step for Delete

  • The DELETE operation comes into play whenever an existing entry needs to be Delete.
  • Similar to the other methods, that you need to redefine this method in the DPC extension class same as follow all the Step till 9
  • First, again handle the primary key of the entry to be deleted. With this information.
  • DELETE operations are always executed on a single entry. Therefore, you have to provide a URI that addresses a single-entry resource. The HTTP method has to be DELETE.
  • If DELETE was successful, you get an HTTP 204 (no content) response. 
  • Code: 
  • Method Code:

METHOD salesheaderset_delete_entity.


"&... Read key value

DATA(lv_sales_order) = VALUE #( it_key_tab[ name = 'SalesOrder' ]-value OPTIONAL ).

lv_sales_order = CONV vbeln( |{ lv_sales_order ALPHA = IN }| ).


DELETE FROM zms_sales_head WHERE vbeln = lv_sales_order.

IF sy-subrc EQ 0.

COMMIT WORK.

ELSE.

ROLLBACK WORK.

mo_context->get_message_container( )->add_message_text_only(

iv_msg_type = /iwbep/if_message_container=>gcs_message_type-error

iv_msg_text = TEXT-004 ).

RAISE EXCEPTION NEW /iwbep/cx_mgw_tech_exception( message_container = mo_context->get_message_container( ) ).

ENDIF.


ENDMETHOD.

  • Output:


OData 4: Step for Update

  • The UPDATE operation comes into play whenever an existing entry resource needs to be changed.
  • Similar to the Read/Query methods, you need to redefine this method in the DPC extension class same as follow all the Step till 9
  • First, use the io_data_provider input object reference to fetch the incoming data from the HTTP body
  • Code:
  • Method Code:

METHOD salesheaderset_update_entity.


DATA: ls_data TYPE zcl_zodata_project_mpc=>ts_salesheader,

ls_sales_head TYPE zms_sales_head.


"Read HTTP Body response using this method

TRY.

io_data_provider->read_entry_data( IMPORTING es_data = ls_data ).

CATCH /iwbep/cx_mgw_tech_exception INTO DATA(lv_exception). " mgw technical exception

ENDTRY.


"&... Read primay key from HTTP request

io_tech_request_context->get_converted_keys( IMPORTING es_key_values = is_key_val).


"Write your own business logic

IF ls_key_val-salesorder EQ ls_data-salesorder.

ls_sales_head-vbeln = ls_data-salesorder.

ls_sales_head-audat = ls_data-documentdate.

ls_sales_head-auart = ls_data-documenttype.

ls_sales_head-vkorg = ls_data-salesorganization.

ls_sales_head-vtweg = ls_data-distributionchannel.

ls_sales_head-spart = ls_data-division.

ls_sales_head-kunnr = ls_data-soldto.

ls_sales_head-kunwe = ls_data-shipto.

ls_sales_head-erdat = cl_abap_context_info=>get_system_date( ).

ls_sales_head-erzet = cl_abap_context_info=>get_system_time( ).

ls_sales_head-ernam = cl_abap_context_info=>get_user_technical_name( ).


INSERT zms_sales_head FROM ls_sales_head.

IF sy-subrc EQ 0.

COMMIT WORK.

er_entity = ls_data.

ELSE.

ROLLBACK WORK.

mo_context->get_message_container( )->add_message_text_only(

iv_msg_type = /iwbep/if_message_container=>gcs_message_type-error

iv_msg_text = TEXT-002 ).

RAISE EXCEPTION NEW /iwbep/cx_mgw_tech_exception( message_container = mo_context->get_message_container( ) ).

ENDIF.

ELSE.

mo_context->get_message_container( )->add_message_text_only(

iv_msg_type = /iwbep/if_message_container=>gcs_message_type-error

iv_msg_text = TEXT-002 ).

RAISE EXCEPTION NEW /iwbep/cx_mgw_tech_exception( message_container = mo_context->get_message_container( ) ).

ENDIF.


ENDMETHOD.

  • Select PUT Method fill the payload and execute the method
  • If the update was successful (see Figure 6.74), you only get an HTTP 204 (no content) response
  • Difference between PUT and PATCH Method, PATCH method Update single properties of an existing entry where PUT method update all properties of an existing entry
  • Payload
{
  "d" : {
    "SalesOrder" : "1200001050",
    "DocumentDate" : "2026-12-31T00:00:00",
    "DocumentType" : "",
    "SalesOrganization" : "US20",
    "DistributionChannel" : "10",
    "Division" : "10",
    "SoldTo" : "0007315101",
    "ShipTo" : "0001010904"
  }
}

OData 3: Step for Create

  • CREATE is used whenever you want to create a new entry into the respective collection.
  • Using the read_entry_data method of the io_data_provider import object reference, you can retrieve the data that was passed along the POST request in the HTTP body. The entry is retrieved in the format of the entity type definition.
  • Similar to the Read/Query methods, you need to redefine this method in the DPC extension class same as follow all the Step till 9. If you want to know the Step 9 details kinldy follow the step from the this link.
  • Method Code:
METHOD salesheaderset_create_entity.
DATA: ls_data TYPE zcl_zodata_project_mpc=>ts_salesheader,
ls_sales_head TYPE zms_sales_head.
"Read HTTP Body response using this method
TRY.
io_data_provider->read_entry_data( IMPORTING es_data = ls_data ).
CATCH /iwbep/cx_mgw_tech_exception INTO DATA(lv_exception). " mgw technical exception
ENDTRY.
"Write your own business logic
ls_sales_head-vbeln = ls_data-salesorder.
ls_sales_head-audat = ls_data-documentdate.
ls_sales_head-auart = ls_data-documenttype.
ls_sales_head-vkorg = ls_data-salesorganization.
ls_sales_head-vtweg = ls_data-distributionchannel.
ls_sales_head-spart = ls_data-division.
ls_sales_head-kunnr = ls_data-soldto.
ls_sales_head-kunwe = ls_data-shipto.
ls_sales_head-erdat = cl_abap_context_info=>get_system_date( ).
ls_sales_head-erzet = cl_abap_context_info=>get_system_time( ).
ls_sales_head-ernam = cl_abap_context_info=>get_user_technical_name( ).
INSERT zms_sales_head FROM ls_sales_head.
IF sy-subrc EQ 0.
COMMIT WORK.
er_entity = ls_data.
ELSE.
ROLLBACK WORK.
mo_context->get_message_container( )->add_message_text_only(
iv_msg_type = /iwbep/if_message_container=>gcs_message_type-error
iv_msg_text = TEXT-002 ).
RAISE EXCEPTION NEW /iwbep/cx_mgw_tech_exception( message_container = mo_context->get_message_container( ) ).
ENDIF.
ENDMETHOD.
  • If the CREATE operation was successful, you get an HTTP 201 response as shown below.
    • First xecute the read or query method get the payload and Click on "Use as Request" button.
    • Modify your pay load as per your need and select POST Method, add content-type as “application/json”
 
  • Payload:
{
  "d" : {
    "SalesOrder" : "1200001050",
    "DocumentDate" : "2026-12-31T00:00:00",
    "DocumentType" : "ZSD",
    "SalesOrganization" : "US20",
    "DistributionChannel" : "10",
    "Division" : "10",
    "SoldTo" : "0007315101",
    "ShipTo" : "0001010904"
  }
}

OData 2: Step for the Query

  •  In this post will show you Create Query in OData.
  • For creating query Kinldy follow all the step's till 9 from this link and process further step's.
  • Step 10: Expand the Service Implementation, Select the Required Entity Set as “SalesHeaderSet”, Expand the Entity Set “GetEntitySet (Query) as show in Below 
  • Step 11: Right click on “GetEntitySet (Query) and select the “Got to ABAP Workbench”
  • Step 12: Popup will show as below, click on Continue
  • Step 13: Redefine the Get EntitySet Methods as below        
  • Step 14: Implement logic inside the Method
  • Step 15: Output:
  • Method Code

METHOD salesheaderset_get_entity.

DATA: ls_key_val TYPE zcl_zodata_project_mpc=>ts_salesheader. "Refer to Type "ER_ENTITY


"Read Key value (IT_KEY_TAb - is obsolete now, below method convert the value to internal ex. adding leadinf zero etc.

io_tech_request_context->get_converted_keys(

IMPORTING es_key_values = ls_key_val ).

IF ls_key_val-salesorder IS NOT INITIAL.


SELECT

SINGLE FROM zms_sales_head

FIELDS vbeln AS SalesOrder,

audat AS DocumentDate,

audat AS OrderType,

vkorg AS SalesOrganization,

vtweg AS DistributionChannel,

spart AS Division

WHERE vbeln EQ @ls_key_val-salesorder

INTO @DATA(zls_sales_head).

IF sy-subrc EQ 0.

er_entity = CORRESPONDING #( zls_sales_head ).

ENDIF.


ENDIF.


ENDMETHOD.

  • Query/sap/SalesHeaderSet?filter=(SalesOrder eq '1200001025')&$filter=json

OData 1: Create First OData Project for Read Operation

  •  In this post will create OData project for read operation

Ø  Step 1: Execute SEGW Transaction





Ø  Step 2: Provide OData Project Name, Description and Project Type as below:



















Ø  Step 3: Right click on Data Model, Click on Import where we can see the multiple options for creating Entity Set (Since we are creating Declarative data model) will click on entity type as shown in Step 4).
Ø  Step 4: In this example we will create Entity type manually by Right click on Entity Types, provide Entity type name (in Camel case) and click on Create Related Entity Set Check box for creating Entity Set Entity Set

  Note: One Entity Type we can used in many Entity Set

Ø  Step 5: Click on Property, click on Append Row or Insert Row button and add field name, data type, length etc. as below (This is called as Declarative data model since we are declaring manually all the field name and length etc.):










  • Note: Entity type also has to have at least one property marked as the Key property.
  • Note: In case of date field, quantity and amount field always click on the Nullable check box. To avoid error in case of blank value in this field.
  • Note: For better metadata readable always provide all the details, ex. Max field length, filterable value like which field have filterable value etc.
  • Note: In case of Date format kindly follow below details, provide date field name, click on Enter and click on ABAP type editor as below:
  • Provide Mode as Explicit Assignment, Category as Date Element and Associated Type as Date Element so that date timestamp value will automatically convert to Date format

Ø  Step 6: Select Project and click on Generate Runtime Object Button so that Run time artifacts will create
























  • Note: When we perform any Date model or Entity type related activity like create new entity type, add new field in entity, modify field length, assign any key field then always Re-generate Runtime object.
Ø  Step 7: Here we can see the Run time artifacts details, click on continue and provide package name





















Ø  Step 8: We can see the run time artifacts details as below:























Ø  Step 9: Click on Service Implementation and Redefine the required method, In this scenario we are going to Redefine the GetEntity (Read) as below:

















  • Step to Redefine method:
  • Go to DPX_EXT class: ZCL_ZODATA_PROJECT_DPC_EXT
  • Find the method: SALESHEADERSET_GET_ENTITY
  • Click on Redefine as below:
  • See the Redefine method as below:
  • Save check and activate method and check into the Service implementation
  • Note: For best practices, always create one Global class in SE24 (called as API class) and write all your logic inside that global class/method and call API global class inside the DPC_EXT, method. So that we can reuse that logic in another API as well.
Ø  Step 10: Go to the Project, Copy the Service Suffix <_SRV> as se in the below Project























Ø  Step 11: Execute transaction /IWFND/MAINT_SERVICE or /N/IWFND/MAINT_SERVICE and click on Add Service button









Ø  Step 12:  Select the System Alias as “LOCAL” (If Deployment type is “Central Hub Deployment” then provide the RFC system name as Alias name), provide the service name and click on enter, one  Service show below select the service and click on “Add Selected Service” button













Ø  Step 13: Popup show as below, select package and click on continue























Ø  Step 14: Once click on continue, Information popup message show as “Service loaded successfully”
  • Note: If you see the Service registered successfully but the service is not active then pls activate the service as below:
  • Again, Execute the Transaction /IWFND/MAINT_SERVICE or /N/IWFND/MAINT_SERVICE, filter your service and see the ICF Node, If ICF Node status not show as green color as below then activate the service
  • Click on ICF Nodes button and select the Activate, provide the package name and continue
  • Once the service is activated, we can see the status as Green Signal
  • We can activate service using SICF Transaction as well
Ø Step 15: GetEntity (Code)

















Ø Step 16: Output







RAP8: Early numbering

In this post will show you how to use early numbering . Step 1: Add early numbering key word in interface behavior definition and activate b...