In this blog I will explain Creating Gateway service with all CRUD operations  Before starting, I am expecting that you have basic idea of gateway service and gateway service builder i.e SEGW

1. Create service in Gateway system with all the CRUD operations.(Create Read Update Delete)


Create project in SEGW (Gateway Service Builder).

Our Project looks as below.



    


Now we need to build our Data model, for that first Create the Entity type by importing an RFC Interface.

Give the Entity type name, RFC destination and name of the RFC to be imported and click on next


Untitled.jpg

Select the required properties for the entity type.

Set key property for the entity type, here we will make Material as key then click on Finish.

Our Entity type MATR and its properties look as below.

Create Entity set with necessary entity type.

Give appropriate Entity set name and select the necessary Entity type then click on continue.

Our Project looks as below.

After creating Entity set Service implementation also created with empty CRUD operations which needed to be implemented by mapping with RFC/BOR interface.

Now we need save our changes within a request.

Now click on generate button to generate runtime artifacts.

Data provider and Model provider classes will be created. Click on ok.

Save the changes.

Runtime artifacts are generated and looks as below.

Now we need to implement all the CRUD operations in Service implementation.

Create

Read/Query

Update

Delete


CREATE: This is to create a new entry. Right click on create and choose Map to data source option.

Give the RFC destination name and select required RFC then click on ok.

Untitled.jpg

Now click on propose mapping, the system will do mapping automatically or else we can do it manually for required fields. Here no need to map all the properties of the entity type; we will map only the required properties. We will do the mapping by drag drop from Function Module onto data source parameter of the Service operation.

Here all the required fields will have input mapping as below.

Here in our case we need to pass constant values for BASE_UOM, MATL_GROUP and BASIC_VIEW, we will do that as follows. First append the rows and maintain values under constant value tab.

Once mapping is done save your changes. Now we will implement DELETE operation.

DELETE: Right click on Delete and choose Map to data source option.

Give the RFC destination name and select required RFC then click on ok. Here we are mapping with BAPI_MATERIAL_SAVEDATA.

Do the required mapping as follows. Here we are passing Material, DelFlag, MatlGroup fields so do the mapping accordingly.

READ: Right click on Read and choose Map to data source option.

Give the required RFC and do the mapping as below. Here we are mapping Material, MatlDesc, IndSector, MatlType, MatlGroup, BaseUom fields. Except Material all are having output mapping.

Note: In READ operation all key fields should have input mapping, here in our example Material is key.

QUERY: Right click on Query and choose Map to data source option.

Note: In Query operation all key fields should have output mapping. Here we can also map ranges directly to pass range value for selection.

Give the required RFC and do the mapping as below. Here we are mapping with BAPI_MATERIAL_GETLIST

Here we will map MatlDesc property with appropriate Function field and our key property Material with range table, for that just drag drop that filed on to the data source field. Click on ok in the below screen.

Our mapping looks like below.

Here for display purpose we will again add Material property since all key fields should have output mapping in Query operation.

For this click on create button and choose the Material property and do the necessary mapping as shown below.

UPDATE: Right click on Update and choose Map to data source option.

Give the required RFC, Here we are mapping with BAPI_MATERIAL_SAVEDATA.Do the required mapping as follows. Here we are going to update MatlGroup Field.

After completing all the implementations save the changes and check for syntax errors.

Now again click on Generate button to regenerate the runtime artifacts.

Check the success messages.

With this we have successfully created a gateway service with implementing all CRUD operations.

In the next part Detailed step by step procedure for Creating Gateway Service with all the CRUD Operations and testing them in Service Explorer Part2

we will maintain our service and test it in Service Explorer


To report this post you need to login first.

21 Comments

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

  1. Mike Reader

    Hey Nagesh,

    Question for you about when you created the Data Model using the RFC BAPI_MATERIAL_SAVEDATA.

    Would you recommend use the save/create BAPI’s when creating the Data Model, or is there a time when using the *GETDETAIL etc might be better?

    I followed your document example and it worked well, a great walk through.

    -Mike

    (0) 
    1. Nagesh A Post author

      Mike,

      we can use any of those while creating data model, it is just for creating data model and nothing to do with it further..

      Thanks

      Nagesh

      (0) 
    2. Mike Reader

      Hey Nagesh … one more question.

      When you did your POST method, is there a way to have a return (exporting) parameter sent back. I see there was a status code of 201 and reason of “Created” … I am working on a GW Service with a POST method and it would be handy to have a return message sent back as well.  The Export params of the BAPI I have mapped to my POST method do not seem to populate in the response. Thoughts?

      -Mike

      (0) 
      1. Ashwin Dutt R

        Hello Mike,

        After create you have to perform a Read operation. Service builder it self will throw a warning saying Create without Read will cause problem during RunTime .

        GW looks for Read after Create or else it will dump.

        Regards,

        Ashwin

        (0) 
  2. Ashwin Dutt R

    Hello Nagesh,

    Good Work 🙂

    When you are passing values for Ranges as shown below will the GW allows to send the same Property multiples times ?? i mean property ‘ Material ‘ is sent twice in the below.

    http:// <hostname>:<port>/sap/opu/odata/sap/ZBPS_MATR_DEMO_SRV/matrset?$filter=Material ge ‘000000000000000023’ and Material le ‘000000000000000053’

    But i tried this way and GW is not allowing. Technical exception is being thrown.

    Can you please check again by executing the above URL ?

    Just want to confirm will GW allows this way.

    Regards,

    Ashwin

    (0) 
  3. Martin Maruskin

    Hi Nagesh,

    I’m using trial system SAP EHP 2 for SAP NetWeaver 7.0 with SAP Gateway SP04.

    In my system I do not have in attribute’s section Generation Strategy field on “Create project” windows:

    /wp-content/uploads/2014/08/create_prj_516433.png

    Also while I tried to create Entity Type I do not have RFC/BOR interface option.

    Entity_type.png

    Any chance I can proceed further?

    thanks

    m./

    (0) 
    1. Bhasker reddy Gudipally

      Hi Martin,

      In that case either use the option “DDIC structure” to import the BAPI structure fields or enter the fields manually like creating a structure in SE11 data dictionary.

      Thanks,

      Bhasker

      (0) 
  4. Abhay Singh

    Hello Nagesh,

    I have just begun to learn Odata, & precisely your blog is the first thing that I came across, now, I need you to elucidate a few things for me if it is not too much to ask.


    1) As visible in the blog do we essentially need to add input parameters + Output parameters of the BAPI while importing Entity Type & Sets?

    2) What if I have to create separate entity for each tables parameter mentioned in the BAPI for example

    MATERIALDESCRIPTION

    UNITSOFMEASURE

    UNITSOFMEASUREX

    INTERNATIONALARTNOS

    How do we tackle with that? Do we create input parameters while creation of each entity or we are required to create all tables parameter in the single entity as you did.

    Kindly respond.

    Thaks,

    Abhay.

    (0) 
  5. Hot Yao

    Hello Nagesh,


    I followed your steps to create a ODdata services, but when i tried to test the delete function, there is some problem: the delete action completed with return code 204, which is same with you. But i checked the data base and found that this material is still there. Would you help?


    Thanks,

    hot

    (0) 

Leave a Reply