cancel
Showing results for 
Search instead for 
Did you mean: 

What do 'GetEntitySet (Query)' & 'GetEntity (Read)' do.

sun197895
Participant
0 Kudos

Once we create a project in Netweaver Gateway and follow few other steps to create a OData service, we come across two methods which I think are very important for service implementation perspective.

Can some one please tell me what exactly does these two methods do : 'GetEntitySet (Query)' & 'GetEntity (Read)'

I am a Java developer / SAP Portal consultant so thinking that these are ABAP specific. But if some one can explain briefly I think I will be able to understand though I have min ABAP knowledge.

Thanks in advance.

Accepted Solutions (1)

Accepted Solutions (1)

EkanshCapgemini
Active Contributor
0 Kudos

Hi,

GET_ENTITY method is used when you need to fetch a single record from the database/backend. (READ)

While GET_ENTITYSET method is used when you need to fetch multiple records from the backend. (QUERY)

Can some one please tell me what exactly does these two methods do : 'GetEntitySet (Query)' & 'GetEntity (Read)'

I think the above mentioned is the only thing these methods do. If you are asking in terms of ABAP code, there are pretty clear comments mentioned in the generated code. Let me try to explain a generalized code of both methods.

In GET_ENTITY:

Firstly there is variable declaration part where we define the structures or containers for FM import, export parameters, RFC destination etc. Then there is code written to fetch the keys from the HTTP request. The code below this extracts the RFC destination to call the FM from the system alias associated with the service. Then it calls the FM based on the RFC destination. If any error occurs during this or there is an error msg coming in return table, the code below this handles errors. Then the response from the FM is transferred to the er_entity structure.

In GET_ENTITYSET:

The same variable declaration part. Then we extract the filters from the HTTP request. The long CASE statements extracts the filter values and put in the containers. Then RFC destination extraction and calling of FM followed by error handling part. Then there comes the code which handles paging. The paging is handled by 'skip' & 'top' parameters. 'Skip' means that skip the mentioned no. of records from the response while 'Top' means the maximum no. of records to be processed from the starting (e.g.: for the first time you may request skip=0 and top=100, then you will get top 100 records. After this you may request skip=100 and top=200, then you will get the next 100 records starting from 101 and ending at 200). Then we loop the output table based on the skip, top values and transfer the values to the et_entityset table.

Regards,

Ekansh

sun197895
Participant
0 Kudos

Thanks a lot Ekansh.

I have now almost implemented both getEntitySet() & also getEntity() methods.

getEntitySet() is working fine when I use below URL.

http://<Netweaver Gateway domain>:8000/sap/opu/odata/sap/ZUI5_SAMPLEUSERINFO_SRV/UserInfoSampleSet

I have also implemented getEntity() method to read a particular record. Below is the code which I have written inside getEntity() method.

******************

method USERINFOSAMPLESE_GET_ENTITY.

data : ls_key_tab   TYPE /iwbep/s_mgw_name_value_pair,

        lc_userInfo_struct type ZUSERINFO_STRUCT,

        lc_userId type zuser_info-zuserid,

        lc_addr type zuser_info-zaddr,

        lc_userinfo_it TYPE  zuser_info.

READ TABLE it_key_tab WITH KEY name = 'USERID' INTO ls_key_tab.

lc_userId = ls_key_tab-value.

select single * from zuser_info into lc_userinfo_it where zuserid = lc_userId.

IF sy-subrc = 0.

   er_entity-zuserid = lc_userinfo_it-zuserid.

   er_entity-zaddr = lc_userinfo_it-zaddr.

   er_entity-zcountry = lc_userinfo_it-zcountry.

ENDIF.

   endmethod.

**************************

But now when I try below URL to get particular record, I am getting below error.

http://<Netweaver Gateway domain>:8000/sap/opu/odata/sap/ZUI5_SAMPLEUSERINFO_SRV/UserInfoSampleSet('123098')

***********************

<error xmlns="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata">

<code>SY/530</code>

<message xml:lang="en">Resource not found for segment 'UserInfoSample'</message>

<innererror>

<transactionid>54A9A66FDD4A0A1CE10000000A298945</transactionid>

<timestamp>20150114132244.6908050</timestamp>

<Error_Resolution>

<SAP_Transaction>

Run transaction /IWFND/ERROR_LOG on SAP NW Gateway hub system and search for entries with the timestamp above for more details

</SAP_Transaction>

<SAP_Note>

See SAP Note 1797736 for error analysis (https://service.sap.com/sap/support/notes/1797736)

</SAP_Note>

</Error_Resolution>

<errordetails>

<errordetail>

<code>/IWBEP/CX_MGW_BUSI_EXCEPTION</code>

<message>Resource not found for segment 'UserInfoSample'</message>

<propertyref/>

<severity>error</severity>

</errordetail>

</errordetails>

</innererror>

</error>

Former Member
0 Kudos

Hi Sun,

possibly there is just a missspelling of the entity set name - UserInfoSample, or UserInfoSampleSet or similar.
It must be exactly the same name that you used when trying Get_Entityset, just with the value of the key property appended in brackets, as you did.

To find out the right name, you can call the service document at

http://<server>:8000/sap/opu/odata/sap/ZUI5_SAMPLEUSERINFO_SRV.

Have a look at the <app:collection> entries in the service document that you receive as response. The values of the attribute href in each collection is the name that you have to use.

Best regards,

Ringo

sun197895
Participant
0 Kudos

Perfect Ringo ... yeah I was not referring EntitySet and referring only Entity. Thanks a lot. But now I have one other issue which is related to my SAPUI5 program. Request your help.

I have implemented getEntity() method so that I can pass a parameter in the URL and get the line item related to that URL. After I corrected the spelling mistake as told by you, the below URL is working fine from netweaver gateway server directly or from browser .... (reads a specific record as per URL parameter)

However, if I use below code in my SAPUI5 program it still retrives all the three records. Please see below code.

var oModel = new sap.ui.model.odata.ODataModel("/sap/opu/odata/sap/ZUI5_SAMPLEUSERINFO_SRV/");

oModel.read("/UserInfoSampleSet('123098')/");

var oTable = new sap.ui.table.Table({width : "100%", visibleRowcount : 5});

oTable.addColumn(new sap.ui.table.Column({label : new sap.ui.commons.Label({text : "UserID"}), template : new sap.ui.commons.TextView({text : "{Zuserid}"})}));

oTable.addColumn(new sap.ui.table.Column({label : new sap.ui.commons.Label({text : "User Address"}), template : new sap.ui.commons.TextView({text : "{Zaddr}"}), visible : true}));

oTable.addColumn(new sap.ui.table.Column({label : new sap.ui.commons.Label({text : "Country"}), template : new sap.ui.commons.TextView({text : "{Zcountry}"}), visible : true}));

oTable.setModel(oModel);

oTable.bindRows({path : "/UserInfoSampleSet"});

return oTable;

Former Member
0 Kudos

Hi Sun,

as you received no further answers so far, I will try to do my best, even though I am not a JavaScript developer. I just used the GWPA tools with Eclipse to generate SAPUI5 starter applications.

1. As a trial, you could change your last-but-one code line to

oTable.bindRows({path : "/UserInfoSampleSet('123098')"});

2. Client-side filtering of the requested data is also a possibility, that´s what the generated starter applications do. They define a function search(oView, newValue) and call it...

/** * This method executes client side search on the given view with the given value

* @param oView - view the contains list to search on

* @param newValue - the value to search for

*/ function search(oView, newValue) {

     var filterPattern = newValue.toLowerCase(), oList = oView.oList,

     listItems = oList.getItems(), i, vBoxitems, visibility;

     for (i = 0; i < listItems.length; i++) { vBoxitems = listItems[i].getContent()[0].getItems();

     visibility = false;

     $.each(vBoxitems, function(index, item) {

         if (item.getText().toLowerCase().indexOf(filterPattern) != -1) {

             visibility = true;

             return false; // break

         }; }); listItems[i].setVisible(visibility);

     };

};

This function is called within the controller designated to the view for that entity type:

     search(this.getView(), oEvent.getParameters().newValue);

If you would like to see the complete code for the client-side filtering, you might sign-up for a HANA Cloud Platform Trial Account and use SAP Web IDE to create a similar Starter Application from a template. Web IDE with templates replaces the plugins for Eclipse, the GWPA plugin seems to be no longer available, unfortunately). See  SAP Web IDE Help to get started.

Best regards and lots of success,

Ringo

Answers (2)

Answers (2)

tharaka_fernando
Contributor
0 Kudos

Hi ,

It is very simple. So let me explain you with below image. Hope this lets you to have clear understanding.

Note : these(GetEntitySet (Query)' & 'GetEntity (Read)) are not ABAP specific. but oData.

kedarT
Active Contributor
0 Kudos

Hi,

'GetEntitySet (Query)' is to get a array of values i.e. if you need to get multiple records from a database table/tables


'GetEntity (Read)' is used to get one single record i.e. all the details of  a particular employee/customer.


Look at this blog -


Hope this helps.


Regards,

Kedar