SAP Netweaver Gateway and OData. Section V. OData Services CRUD Operations

What is CRUD Operation?

SAP Netweaver Gateway ,We have already covered the GET Operation with the READ_ENTITY and READ_ENTITYSET methods in this tutorial series.Information is retrieved and displayed via GET.In the popular “CRUD” Operations, the “R” stands for GET or READ Method. the others being Add, Modify, and Remove. The POST and PUT operations for writing to the database and the DELETE operation for removing records are the main topics of this article.The database would be updated, deleted, and new entries created. The Guinea pig, or ZEKKOEKPO table, is still the same.

A. POST Operation

the primary function is the creation of new entries, as the name implies. We can’t just select POST Operation and run the URI for our standalone test. POST Operation in t-code /n/IWFND/GW_CLIENT is a two-step operation. Prior to using the request string to POST data, the GET Operation must be used to prepare it.

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

Use as Request

ii. Carry out the POST procedure.

CRUD in OData Services

You receive an error, oops.

SAP Netweaver Gateway and oData Tutorial

What emotions did you experience?Can the POST function be performed without writing any code?It’s not magic, even if ABAPers are magicians.

There are still two assignments for us to finish.
i. Adjust the CREATE_ENTITY function ii. Call the POST Operation using the correct URI.

Let’s write some simple ABAP code and rewrite the procedure to add entries in the custom table. If you require assistance redefining the Data Provider Class method, please refer to our earlier post:To begin, create an OData service.

CREATE_ENTITY

zekkoekposet_create_entity is the method.

ls_zekkoekpo LIKE er_entity in the data.

io_data_provider->read_entry_data( ls_zekkoekpo = IMPORTING es_data ).

sy-mandt = ls_zekkoekpo-mandt.

Lekpo Zekko Entity = er_entity.

Place the values of ls_zekkoekpo into zekkoekpo.

ENDMETHOD.

Let’s make sure there isn’t an entry in the custom table before performing the POST Operation.

SAP Odata

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

the POST Operation

Now let’s carry out the POST-Operation one more.

The identical “Method Not Allowed” error message appears.

/sap/opu/odata/sap/

Did you notice that we continued after the breakpoint?What does that signify?It indicates that the URI is incorrect and that the method was not invoked at all.

Check the section that says “Call the POST Operation with correct URI” by scrolling up. Thus, /sap/opu/odata/sap/ZGW_PO_SRV/zekkoekpoSet is the right URI to POST.

CRUD in SAP

At the break point, the debugger stops and the Method is finally triggered.

Verify that the status is “Created.”

CREATE READ UPDATE DELETE

Congratulations! You’ve completed an OData Service POST operation.Recall the URI choices and the preceding stages. When we use these URIs in our SAPUI5 Applications (a SAPUI5 Tutorial series will shortly begin), we will need them.

Have you noticed that the only method available is CREATE_ENTITY?CREATE_ENTITYSET Method not used. Does this imply that we can only make one row at a time? Not at all. Multiple entries can always be pulled and posted into the database.

B. Put Function

PUT operations update and change already-existing items, whereas POST operations create new entries. PUT has two steps, just like POST Operation. Use the “Use as Request” option to perform the GET Operation, and then perform the actual PUT Operation.

Let’s begin the PUT Operation as soon as we receive the Request.

Did you anticipate updating the table without having to write any code? Who will put the Update_Entity Method into practice, my friend?

PUT Operation

Zekkoekposet_update_entity is the method.

DATA: ts_zekkoekpo ls_request_input_data TYPE zcl_zgw_purchase_mpc.

io_data_provider->read_entry_data( ls_request_input_data = IMPORTING es_data ).

sy-mandt = ls_request_input_data-mandt.

Zekkoekpo is updated from ls_request_input_data.

ENDMETHOD.

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

To change the MENGE value of the record we created earlier, let’s pass the URI.

Verify that the MENGE value in the request string, which is provided to the PUT operation, has been changed from 7 to 14.

Request String in PUT

Now let’s get to work.

It appears like the status is green. However, the text states, “No Content.” You must be just as perplexed as I am.What actually took place?

No Content

The table indicates that the entry was correctly changed when I visit it.It’s all good that ends well.”204″ is the status code for an accurate update. Thus, everything is well.

This should be a sufficient explanation of PUT/UPDATE Operation.Simply comprehend the flow and place a breakpoint at the UPDATE_ENTITY method if you’re still unsure.Your URI is wrong if your method does not execute. This should remain your task.Debug the PUT function.

In order to enable Create operations using OData model, perform ICF settings for the produced OData service.

Navigate to the SICF transaction, double-click the ICF node of the OData service, and then select the GUI Configuration button.

Put the value of ~CHECK_CSRF_TOKEN to 0.

modify using OData service

This is the third time that we have missed it.Recall that every Operation requires the implementation and redefinition of its corresponding Method in order to be carried out.Ideally, you wouldn’t overlook it in your actual project.

Now let’s reinterpret and apply the DELETE_ENTITY Method.

Implement DELETE_ENTITY

Zekkoekposet_delete_entity is the method.

ls_key_tab data SMGW_name_value_pair, TYPE /iwbep, lv_ebeln, TYPE ebeln, lv_ebelp Ebelp is the type.

  • Obtain the values of the important properties.
    READ TABLE it_key_tab INTO ls_key_tab WITH KEY name = ‘Ebeln’.
    lv_ebeln = ls_key_tab-value IF sy-subrc = 0. ENDIF.
  • Obtain the values of the important properties.
    READ TABLE it_key_tab INTO ls_key_tab WITH KEY name = ‘Ebelp’.
    lv_ebelp = ls_key_tab-value IF sy-subrc = 0. ENDIF.
  • Remove entry DELETE FROM zekkoekpo WHERE ebelp = lv_ebelp AND ebeln = lv_ebeln.

ENDMETHOD.

Place a breakpoint outside of the system and do the DELETE operation.

KEY TAB IN ODATA

Verify the situation.The color is green and it says “No Content.”

DELETE OData Service

Although the message content is a little misleading, I’m not concerned about it this time.Since the method fired and the message code is green, I know it was successful. Let’s confirm it.

The lone entry in the ZEKKOEKPO table has been removed. Thus, the DELETE Operation was carried out without incident.

PS: The other two procedures are MERGE and PATCH. Maybe you could verify each one independently.

I hope you now have a decent understanding of CRUD processes. Depending on the demands of the business, the logic to read, edit, and parse would be more complicated in real work.The principles would not change, though.That would mean that the matching techniques you would need to redefine and apply would stay the same. So exude confidence! No matter how basic an OData service is, you can manage its CRUD functionalities.This covers the essentials of OData and SAP Netweaver Gateway. We will provide a summary of all we have discovered and comprehended thus far in the upcoming post. We would then immediately begin using these OData Services in our SAPUI5 Applications.

What more would you like to add to this article? Have you encountered any difficulties comprehending SAP Netweaver Gateway or OData? Would you like to share any actual project specifications or solutions?Do not hesitate to speak up.Kindly share your opinions in the space provided for comments.

I sincerely appreciate your time!

you may be interested in this Blog here:-

SAP UX Greatest Developments in Public Cloud in 2024

How Emma Discovered the Power of SAP Business Technology Platform: An Inspirational Journey

Related Posts

Important T codes for FI GL AR AP

Details of T Codes Accounting for Finances SPRO Put in the IMG OX02 Company Code to Create, Verify, and Delete OX03. Create Business Area Functional Areas for OKBD OB45 Establish…

Dynamically Download Data From Any SAP Table in ABAP-740 – Part 1

A few days ago, one of my SAP BI/BW friends requested a program that would accept any table as input and download it as a file to the local machine.…

Leave a Reply

Your email address will not be published. Required fields are marked *

You Missed

Important T codes for FI GL AR AP

  • By Varad
  • December 21, 2024
  • 18 views
Important T codes for FI GL AR AP

Dynamically Download Data From Any SAP Table in ABAP-740 – Part 1

  • By Varad
  • December 20, 2024
  • 13 views
Dynamically Download Data From Any SAP Table in ABAP-740 – Part 1

Error While Setting Up Trusted System RFC

  • By Varad
  • December 19, 2024
  • 10 views
Error While Setting Up Trusted System RFC

 Credit Management T codes in SAP

  • By Varad
  • December 18, 2024
  • 24 views
 Credit Management T codes in SAP

Troubleshooting SAP BD22: Delete Change Pointer Not Picking Correct Processed Messages

  • By Varad
  • December 17, 2024
  • 56 views
Troubleshooting SAP BD22: Delete Change Pointer Not Picking Correct Processed Messages

Working with Shell Scripts in SAP ABAP Environment

  • By Varad
  • December 16, 2024
  • 34 views
Working with Shell Scripts in SAP ABAP Environment