Quantcast
Channel: SCN : All Content - SAP Gateway
Viewing all articles
Browse latest Browse all 2823

#1 - OData CRUD Crash Course - Read

$
0
0

read.pngPrerequisites


You should have done the following steps:


#1 - OData CRUD Crash Course - Query


Step-by-Step Procedure


- Building Read operation


1. In SAP transaction SEGW, expand a project folder and open TravelAgencySet. Click on GetEntity (Read) and choose Go to ABAP Workbench. As the first implementation, you'll see the popup.

1.png

2. Click on the *_DPC_EXT folder. The right pane should show the Class Interface shown in the next step.You'll see the list of the methods. Scroll down - click and focus on the "..._GET_ENTITY" and press the Redefine icon.

Tip: Make sure if your editor is in edit mode with the edit.pngicon. Redefine icon is redefine.png.

2.png

3. Delete the commented out lines of code. You have an empty implementation.

3.png

4. If you click "Signature" text, you'll see the in & out parameters of this method. We'll implement so that it returns "ER_ENTITY" parameter.

4.png

Here's implementation:

   Naming convention:    l - local scope   t - table   s - structure

01 method TRAVELAGENCYSET_GET_ENTITY.
02
03   DATA: ls_key_tab   TYPE /iwbep/s_mgw_name_value_pair,
04         ls_entityset TYPE stravelag.
05
06 * key is TravelAgencySet(agency#)
07   READ TABLE it_key_tab INTO ls_key_tab INDEX 1.
08
09   SELECT SINGLE * FROM stravelag INTO ls_entityset WHERE agencynum = ls_key_tab-value.
10
11   er_entity = ls_entityset.
12
13 endmethod.

#03 declares a variable which holds the "key" value in the URL - such as ../TravelAgencySet('12345678'). #07 picks up the key value. #09 selects an entity value with they key "agancynum". #11 sets the returning value which will be sent in OData.

 

Make sure you activate it by activate.pngicon.

 

- Testing Read operation

 

1. Run the Query operation.

5.png

2. In a response body, choose an entity you want to read - find the OData URL in <id> tag.

6.png

3. Paste the URL and do the HTTP GET.

7.png

4. You should receive a response body content of the entity. The Read operation executed successfully!

8.png

 

What's next? You can choose either of:

 

- Create operation

- Update operation

- Delete operation


Viewing all articles
Browse latest Browse all 2823

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>