#1 – OData CRUD Crash Course – Query
You should have done the following steps:
– Building Query operation
1. In SAP transaction SEGW, expand a project folder and open TravelAgencySet. Click on GetEntitySet (Query) and choose Go to ABAP Workbench.
2. As the first implementation, you’ll see the popup.
3. Click on the *_DPC_EXT folder. The right pane should show the Class Interface shown in the next step.
4. You’ll see the list of the methods. Scroll down – click and focus on the “…_GET_ENTITYSET” and press the Redefine icon.
5. Here’s the generated code from the superclass. Delete the commented out lines of code.
6. You have an empty implementation now.
7. If you click “Signature” text, you’ll see the in & out parameters of this method. We’ll implement so that it returns “ET_ENTITYSET” parameter.
l - local variable
t - table
01 method TRAVELAGENCYSET_GET_ENTITYSET.
03 DATA: lt_entityset TYPE TABLE OF stravelag.
05 SELECT * FROM stravelag INTO TABLE lt_entityset.
07 et_entityset = lt_entityset.
#03 defines a variable which holds the TravelAgency table contents. #05 loads the database table “stragelag” that contains the TravelAgency data into the local variable. #07 sets the value in the predefined output parameter “et_entityset” – as you see in the Signature pane, the data type is already generated as a TravelAgency structure “…_MPC=>TT_TRAVELAGENCY”.
Those tiny 3 lines of code does the database access and returns the TravelAgency collection in OData – how simple & powerful is that? 🙂
– Testing Query operation
Start your favorite REST Client tool – this one is using Firefox RESTClient. In this step, you should have seen the actual URL of the OData service. Type it in the REST client URL with HTTP GET.
The Query result should come in correctly!
What’s next? You can choose either of: