Skip to Content

/wp-content/uploads/2015/03/query_678255.pngPrerequisites

 

You should have done the following steps:

 

#1 – OData CRUD Crash Course – Getting ready with offline store

 

Step-by-Step Procedure

 

– 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.

/wp-content/uploads/2015/03/1_672371.png

2. As the first implementation, you’ll see the popup.

/wp-content/uploads/2015/03/2_672372.png

3. Click on the *_DPC_EXT folder. The right pane should show the Class Interface shown in the next step.

/wp-content/uploads/2015/03/3_672373.png

4. You’ll see the list of the methods. Scroll down – click and focus on the “…_GET_ENTITYSET” and press the Redefine icon.

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

/wp-content/uploads/2015/03/4_672374.png

5. Here’s the generated code from the superclass. Delete the commented out lines of code.

/wp-content/uploads/2015/03/5_672375.png

6. You have an empty implementation now.

/wp-content/uploads/2015/03/6_672376.png

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.

/wp-content/uploads/2015/03/7_672377.png

Here’s implementation:



   Naming convention:
   l - local variable
   t - table
  
01 method TRAVELAGENCYSET_GET_ENTITYSET.
02
03   DATA: lt_entityset TYPE TABLE OF stravelag.
04
05   SELECT * FROM stravelag INTO TABLE lt_entityset.
06
07   et_entityset = lt_entityset.
08
09 endmethod.

#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? 🙂

 

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

 

– 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.

/wp-content/uploads/2015/03/8_672378.png

The Query result should come in correctly!

 

What’s next? You can choose either of:

Create operation

Read operation

Update operation

Delete operation

 

 

List of H2Gs

To report this post you need to login first.

Be the first to leave a comment

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

Leave a Reply