You should have done the following steps:

#1 – OData CRUD Crash Course – Query

#1 – OData CRUD Crash Course – Read

Step-by-Step Procedure

– Building Create operation

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


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 “…_CREATE_ENTITY” and press the Redefine icon.

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


3. Delete the commented out lines of code. You have an empty implementation. If you click “Signature” text, you’ll see the in & out parameters of this method. We’ll implement so that it returns “ER_ENTITY” parameter.


Here’s implementation:

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

03   DATA: ls_entityset    TYPE stravelag,
04         ls_key_tab      TYPE /iwbep/s_mgw_name_value_pair,
05         lv_error_entity TYPE string.
07   io_data_provider->read_entry_data( IMPORTING es_data = ls_entityset ).
09   ls_key_tab-value = ls_entityset-agencynum.
11   INSERT into stravelag values ls_entityset.
13   IF ( sy-subrc = 0 ).
14 * entity inserted
15     er_entity = ls_entityset.
16   ELSE.
17 * entity alredy exists
18     CONCATENATE iv_entity_name
19                 '('''
20                 ls_key_tab-value
21                 ''')'
22       INTO lv_error_entity.
23     RAISE EXCEPTION TYPE /iwbep/cx_mgw_busi_exception
24       EXPORTING
25         textid      = /iwbep/cx_mgw_busi_exception=>resource_duplicate
26         entity_type = lv_error_entity.
27   ENDIF.
29 endmethod.

#05 declares a variable which can have the error message if the Create operation failed. #07 picks up the entity value which comes in from the OData client. #09 sets the key value “agancynum” in a local key-value table (this will be helpful in other enhancement H2G later). #11 does a simple insert command to store a new entity value in the TravelAgency table. If the command goes successful, the sy-subrc value should be 0. #18 – #26 sets the user-friendly error message saying the key value already exists in the TravelAgency table.

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

– Testing Create 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


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)


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


4. Choose one of the entities in the returned Query operation – in <id> tag.


5. Run the Read operation.


6. You should obtain the entity value in a response body. Copy it.


7. And paste it in the Body payload.


8. By making use of this body content, we’ll create a new entity. For this case just change the <d:Agencynum> value to a new one which doesn’t yet exist on the TravelAgency table. You can change other values if you like – but make sure the XML tag is well formed by a set of opening and closing tags.


9. Let’s issue by HTTP POST. The URL is /TravelAgencySet without any key value.


10. You should receive HTTP 201 Created. The Create operation executed successfully!


What’s next? You can choose either of:

Update operation

Delete operation

List of H2Gs

To report this post you need to login first.

1 Comment

You must be Logged on to comment or reply to a post.

  1. paul thompson

    If you find you don’t have any test data for this service please go to the ABAP Editor (SE38) and execute the SAPBC_DATA_GENERATOR program.


Leave a Reply