OData and SAP Netweaver Gateway. Part V. CRUD Operations in OData Services

What is CRUD Operation?
Share on Facebook21Share on LinkedIn7Tweet about this on TwitterShare on Google+0
Please Share!!

As of now in our tutorial series, we have explored the GET Operation involving READ_ENTITY and READ_ENTITYSET methods. GET is used for pulling information and displaying. GET or READ Method is the “R” of the popular “CRUD” Operations. Others being Create, Update and Delete. In this article, we would concentrate on writing to the database using POST and PUT operations and remove entries using DELETE operation. We would be creating, updating and deleting entries in the database. And the Guinea pig remains the same, i.e. ZEKKOEKPO table.

A. POST Operation

As the name suggests, it is mainly used for creating new entries. For our stand-alone test, we cannot directly choose POST Operation and execute the URI. POST Operation is a two steps process in t-code /n/IWFND/GW_CLIENT. We need to first prepare the request string using GET Operation and then use the string to POST data.

i. Execute GET Operation with “Use as Request” option
URI: /sap/opu/odata/sap/ZGW_PO_SRV/zekkoekpoSet(Ebeln=’4580000990′,Ebelp=’00001′)

Use as Request

ii. Execute the POST operation

CRUD in OData Services

Oops, you get an error.

SAP Netweaver Gateway and oData Tutorial

What did you think? Can you execute the POST operation without writing any code? It is not magic even though ABAPers are magicians. 🙂

We still have two activities to perform.
i. Redefine CREATE_ENTITY method
ii. Call the POST Operation with correct URI

Let us redefine the method and write simple ABAP code to insert entries in the custom table. If you do not know how to re-define the Data Provider Class method, please refer to our earlier post: Create your first OData Service.

CREATE_ENTITY

Before we execute the POST Operation, let us confirm there is no entry in the custom table.

SAP Odata

Put an external breakpoint on the CREATE_ENTITY Method to prove that it is triggered while executing POST operation.

the POST Operation

Let us execute the POST-Operation again.

URI: /sap/opu/odata/sap/ZGW_PO_SRV/zekkoekpoSet(Ebeln=’4580000990′,Ebelp=’00001′)

You get the same error “Method Not Allowed”.

/sap/opu/odata/sap/

Did you mark; our action did not stop at the breakpoint. What does it mean? It means the method was not triggered at all and the URI is not the correct one.

Scroll up and check, we specifically said: “Call the POST Operation with correct URI”. So the correct URI to POST is: /sap/opu/odata/sap/ZGW_PO_SRV/zekkoekpoSet

CRUD in SAP

Finally, the Method is triggered and the debugger stops at the break point.

Check the status is “Created”.

CREATE READ UPDATE DELETE

Let us validate if the entry is really populated in the custom table.

Yes!! It is.

Congrats, you just did a POST Operation in OData Service. Remember the above steps and URI options. We would need them when we consume these URIs in our SAPUI5 Applications (SAPUI5 Tutorial series to be commenced soon).

Did you take notice, there is only CREATE_ENTITY Method? No CREATE_ENTITYSET Method. Does it mean we can create just one row at a time? Absolutely not. You can always pull multiple entries and post into the database.

Also Read: ABAP Development for SAP HANA Tutorial Series.

B. PUT Operation

While POST is to create entries, PUT Operation is to update/modify existing entries. Like POST Operation, PUT also has two steps. Execute GET Operation with the option “Use as Request” and then execute the real PUT Operation.

URI: /sap/opu/odata/sap/ZGW_PO_SRV/zekkoekpoSet(Ebeln=’4580000990′,Ebelp=’00001′)

Once we have the Request, let us execute the PUT Operation.

Were you expecting to update the table without writing any code? My friend, who will implement the Update_Entity Method? 🙂

PUT Operation

URI: /sap/opu/odata/sap/ZGW_PO_SRV/zekkoekpoSet(Ebeln=’4580000990′,Ebelp=’00001′)

Let us pass the URI to update the MENGE value of the entry which we created above.

Check we have changed the MENGE value to 14 from 7 in the Request String which would be passed to PUT Operation.

Request String in PUT

Let us execute.

The status looks green. But the text says, “No Content”. I am sure, you are as confused as me. What really happened?

No Content

When I go the table, it shows the entry was successfully updated. All is well that ends well. The status code for correct Update is ‘204’. So we are good.

Hopefully, this was enough demonstration of PUT/UPDATE Operation. If you still have doubt, just put a breakpoint at the UPDATE_ENTITY method and understand the flow. If your method is not triggered, it means your URI is incorrect. Keep this as your homework. Debug PUT Operation.

C. DELETE Operation

For DELETE we do not need to execute GET and Use as Request. We just need to pass the right URI with correct options.

Let us delete the same entry which we created and modified above.

URI: /sap/opu/odata/sap/ZGW_PO_SRV/zekkoekpoSet(Ebeln=’4580000990′,Ebelp=’00001′)

modify using OData service

We have missed it the third time today. Remember, if we want to execute any Operation, the corresponding Method has to be redefined and implemented. Hopefully, in your real project, you would not miss it.

Let us redefine and implement the DELETE_ENTITY Method.

Implement DELETE_ENTITY

Put an external break point and execute the DELETE Operation.

KEY TAB IN ODATA

Check the status. It is Green with the message ‘No Content’.

DELETE OData Service

The message text is a little misnomer, but this time I am not worried. I know it worked as the message code is green and the method triggered. Let us validate it.

The only entry present in the table ZEKKOEKPO has been deleted. So our DELETE Operation has executed successfully.

PS: There are two other Operations viz PATCH and MERGE. You might want to check them separately.

Hope you have a fair idea about CRUD operations now. In real work, the logic to read, edit and parse would be more complex depending on the business needs. But the fundamentals would remain the same. The corresponding methods you need to re-define and implement would remain the same. So be confident!! You can handle CRUD features of the any OData Service, however crude it might be. 😀

This is all about SAP Netweaver Gateway basics and OData fundamentals. In the next post, we would summarize whatever we have learned and understood till now. We will talk about common terminologies and jargons used in SAP OData and Netweaver Gateway meetings. Thereafter, we would jump into consuming these OData Service in our SAPUI5 Applications.

If you GENUINELY like our articles then it would be a HUGE help if you subscribed and liked us on facebook. It might seem insignificant, but it helps more than you might think.

Do you have anything to add to this article? Have you faced any issue understanding OData or SAP Netweaver Gateway? Do you want to share any real project requirement or solutions? Please do not hold back. Please leave your thoughts in the comment section.

Thank you very much for your time!!

Useful Tutorials in SAPYard

1. ABAP for SAP HANA Tutorials
2. ABAP Web Dynpro Tutorials
3. GOS Tutorial
4. OOPs ABAP Tutorial
5. HANA Tutorial
6. SAP Netweaver and OData Tutorial
7. SAP Adobe Form Tutorial
8. SAP Fiori Tutorial
9. SAPUI5 Tutorial

 

Call for Guest Authors and Contributors to write SAP Articles on our page and get noticed and also receive cool Gifts.

Do you have any tips or tricks to share? Do you want to write some articles at SAPYard? Please REGISTER and start posting and sharing your knowledge to the SAP world and get connected to your readers. Please check our simple guidelines for contributing your articles and receiving the gifts.

 

Share on Facebook21Share on LinkedIn7Tweet about this on TwitterShare on Google+0
Please Share!!

About the Author

SAP Yard
SAP Yard

SAPYard is one stop page for all Technical Folks in SAP. You would find un-conventional explanations, tutorials, and tricks.

Please like our Facebook Page and also join our LinkedIn Group.

9 Comments on "OData and SAP Netweaver Gateway. Part V. CRUD Operations in OData Services"

  1. Just a suggestion in a series post like this one, please post the other parts URL also .

    • Dear Azeem – Thank you for the feedback. Sure, we will post the other parts URL too in such series post. Thank you again.It helps.

      Regards,
      Team SAPYard.

  2. Thank you for the excellent Odata series.

  3. Arkajeet Dasgupta | January 23, 2017 at 5:35 am | Reply

    OData services are meant for consumption by browser based applications,mobile devices,Enterprise Software,consumer devices etc.
    Odata is a lightweight Web protocol for querying and updating data, applying and building on Web technologies such as HTTP, Atom Publishing Protocol (AtomPub), and RSS (Really Simple Syndication) to provide access to information from a variety of backend applications including SAP(on-premise) and cloud(XSOData).
    The consumer connects directly(or indirectly) to the system for the service call from a frontend consumer application at realtime and hence it is not something that gets published anywhere.
    Also it is stateless(although there are ways to defy this attribute but not meant to as per the REST PROTOCOL) hence does not store anything and is a to and fro communication of information through service calls.
    Hope this helps Kuldip’s query.

    Thanks
    Arkajeet Dasgupta

  4. Hi Raju, can you please explain how can we published this webservice for public what are the things which require to make web service publish on internet.

Leave a Reply to kuldeep joshi Cancel reply

Your email address will not be published.


*