Skip to Content
Author's profile photo Kenichi Unnai

#1 – OData CRUD Crash Course – Delete

/wp-content/uploads/2015/03/delete_678262.pngPrerequisites


You should have done the following steps:


#1 – OData CRUD Crash Course – Query


Step-by-Step Procedure


– Building Delete operation


1. In SAP transaction SEGW, expand a project folder and open TravelAgencySet. Click on Delete and choose Go to ABAP Workbench. As the first implementation, you’ll see the popup.

/wp-content/uploads/2015/03/1_672989.png

2. Click on the *_DPC_EXT folder. The right pane should show the Class Interface shown in the next step.You’ll see the list of the methods. Scroll down – click and focus on the “…_DELETE_ENTITY” and press the Redefine icon.

Tip: Make sure if your editor is in edit mode with the /wp-content/uploads/2015/03/edit_674237.pngicon. Redefine icon is /wp-content/uploads/2015/03/redefine_674238.png.

/wp-content/uploads/2015/03/2_672990.png

3. Delete the commented out lines of code. You have an empty implementation.

/wp-content/uploads/2015/03/3_672991.png

4. If you click “Signature” text, you’ll see the in & out parameters of this method.

/wp-content/uploads/2015/03/4_672992.png

Here’s implementation:

   Naming convention:
   l - local scope
   t - table
   s - structure
   v - variable

01 method TRAVELAGENCYSET_DELETE_ENTITY.
02
03   DATA: ls_entityset    TYPE stravelag,
04         ls_key_tab      TYPE /iwbep/s_mgw_name_value_pair,
05         lv_error_entity TYPE string.
06
07 * key is TravelAgencySet(agency#)
08   READ TABLE it_key_tab INTO ls_key_tab INDEX 1.
09
10   DELETE FROM stravelag WHERE agencynum = ls_key_tab-value.
11
12   IF ( sy-subrc = 0 ).
13 * delete completed
14   ELSE.
15 * entity not found
16     CONCATENATE iv_entity_name
17                 '('''
18                 ls_key_tab-value
19                 ''')'
20       INTO lv_error_entity.
21     RAISE EXCEPTION TYPE /iwbep/cx_mgw_busi_exception
22       EXPORTING
23         textid      = /iwbep/cx_mgw_busi_exception=>resource_not_found
24         entity_type = lv_error_entity.
25   ENDIF.
26
27 endmethod.

#05 declares a variable which can have the error message if the Delete operation failed. #08 picks up the key value of the deleting entity – such as ../TravelAgencySet(‘12345678‘). #10 does a simple delete command. If the command goes successful, the sy-subrc value should be 0. #16 – #24 sets the user-friendly error message saying the entity doesn’t exist in the TravelAgency table.

Make sure you activate it by /wp-content/uploads/2015/03/activate_675725.pngicon.


– Testing Delete operation

1. Do the Query operation. In the query step, set the two HTTP Header parameters – these are required to do any data modification (either Create/Update/Delete) against OData services in SAP Gateway.

X-CSRF-Token = Fetch

Content-Type = application/atom+xml; charset=UTF-8

/wp-content/uploads/2015/03/1_672989.png

2. In a response header, you’ll find the token value in X-CSRF-Token. Copy it. (Note: the token will keep valid until the browser gets closed)

/wp-content/uploads/2015/03/2_672990.png

3. Replace the copied value with “Fetch” string. Now your REST client is ready for Create operation via HTTP POST.

/wp-content/uploads/2015/03/3_672991.png

4. Choose one of the entities you want to delete in <id> tag.

/wp-content/uploads/2015/03/5_672993.png

5. Run the Delete operation.

/wp-content/uploads/2015/03/6_672994.png

6. You should receive HTTP 204 No Content. The Delete operation executed successfully!

/wp-content/uploads/2015/03/7_672998.png


What’s next? You can choose either of:

Create operation

Read operation

Update operation



List of H2Gs

Assigned Tags

      1 Comment
      You must be Logged on to comment or reply to a post.
      Author's profile photo Abhilash Pradhan
      Abhilash Pradhan

      Hello,

       

      Is there any way we can pass payload in delete or update(put)  HTTP calls ?

       

      Thanks,

      Abhilash