cancel
Showing results for 
Search instead for 
Did you mean: 

How to fetch data from multiple tables in one GET_ENTITYSET method?

0 Kudos

Hi Experts,

Requirement is to fetch the data from three different tables and display in one single table on front end.

In single OData service i have 3 GET_ENTITYSET method for three different entity types. I want to fetch data from 3 different database tables based on key fields.

If I write select query in 3rd GET_ENTITYSET method then how i can access the 3 table's data in one method.

Thanks,

Prashant

Accepted Solutions (1)

Accepted Solutions (1)

AshwinDutt
Active Contributor
0 Kudos

Hello Prashant,

Below are the approaches as per my knowledge :

Approach 1 :

Say Table1 has fields A, B, C

Say Table2 has fields D, E, F

Say Table3 has fields X, Y, Z

Say u need only A, D, X fields in our GW response on passing of input from the above different tables.

In the data model create single entity which will have fields only A, D, X.

Implement Get_Entity_Set method and write your logic to get above fields from all those different 3 tables and populate in a single table and return as GW response.

This way u get all the required fields from different tables as a single entity in GW level.

Approach 2 :

If at all u r calling an RFC to this case, u can also change your RFC logic to get all required fields from those 3 tables and populate n a single output table in RFC level.

Then u can straight away implement Get_Entity_Set in SEGW and map the response and generate run time objects.

You can decide what approach to be used and implement

Regards,

Ashwin

0 Kudos

Hi Ashwin, 

Still i am stuck with how to create data model which will have A,D,X fields. i have tried to import but that is not possible. Please can you explored it more.

Thanks,

Prashant

AshwinDutt
Active Contributor
0 Kudos

Hello Prashant,

Do not import, U need to manually add the required fields / properties in the data model with appropriate edm types.

Then follow the steps which i have share in the previous reply of mine.

With that u should be able to implement what u exactly need. i.e., retrieve only those required fields from 3 different tables based on some input in one single output table as part of GW response.

Regards,

Ashwin

Answers (6)

Answers (6)

0 Kudos

Hi All,

Thanks for help. The problem is solved successfully.

Regards,

Prashant

vijaybhaskarraju_vegesana
Active Participant
0 Kudos

Hi Prashanth,

why don't you give a try with expand operation, You will get 3 different tables output in one single call.please refer to below link.

Thanks,

Vijay V

kammaje_cis
Active Contributor
0 Kudos

Prashant,

If you wanted all three entities together, why did you create three entities?

You need to correct your Entity Data Model first.

Create only one entity instead of three entities, having all the required properties.

In the Get Entityset method, fetch all the properties using a join. No need to create any RFC.

regards

Krishna

0 Kudos

Hi Krishna,

Can i import multiple tables in single entity types?

If it is possible then please share the sample entity data model.

Thanks,

Prashant

kammaje_cis
Active Contributor
0 Kudos

Entity is always a flat structure. Why don't you explain your use case? that would help us to design your entity model.

0 Kudos

Hi Krishna,

I have 3 database tables and show the data using sap.m.Table on screen.

For this, i have created OData service and inside it i have 3 entity types and and 3 entity sets. I want to fetch the data from 3 tables based on key fields and display the output. I know how to write select query but the problem is how to get all this fields in single GET_ENTITYSET method so that i can access single entity set and get it done.

If there any other solution/idea  please let me know.

Thanks,

Prashant

0 Kudos

Hi All, For this solution can i use GET_EXPAND_ENTITYSET. But don't know how to implement this method. I have also read about $expand and this is by default provided by SAP net weaver gateway. But still i am confused with this. Could any one help to clear this concept and how to implement it. Thanks, Prahsant

ChandraMahajan
Active Contributor
0 Kudos

Hi,

you can refer

Also read SAP help https://help.sap.com/saphelp_gateway20sp08/helpdata/en/ca/c683e803494b77a2e1290b987556e2/content.htm on Framework Expand (earlier known as Generic Expand) and Data Provider Expand (earlier known as Basic Expand).

Regards,

Chandra

AshwinDutt
Active Contributor
0 Kudos

Hello,

Create RFC wrapper by joining tables and store result in an out put table.

Use this table to map as a response table in segw.

Regards,

Ashwin

0 Kudos

Discussion moved to SAP Gateway community.  Not UI related.

Regards, Mike (Moderator)

former_member293602
Active Participant
0 Kudos

Hi Prashant,

a technical possibility to "save roundtrips" is to make use of batch requests. Here you can "bundle" requests for different entities of the same model. Just check the API Reference for the oData Model in OpenUI5 SDK - Demo Kit.

Regards, Frank

0 Kudos

Hi Frank, Thanks for reply. I have problem with GET_ENTITYSET. How i can get the 3 table's data in single entity set so that i can bind that entity set to my sap.m.Table items. Thanks, Prashant

arunchembra1
Participant
0 Kudos

Hi Prasanth,

Create a RFC wrapper in SAP and join the 3 tables in SAP and create a single ENTITY for the same.

Thanks,

Arun

0 Kudos

Hi Arun, Thanks for reply. Do you have any sample code for RFC and to create single entity. Please share with me. Thanks, Prashant

arunchembra1
Participant
0 Kudos

Hi Prasanth,

  1. SAP ABAP Developer will be able to help you to create RFC, its simple ABAP JOIN you have to use.
  2. Please reffer the below link to create Odata Service and Entity

http://scn.sap.com/community/gateway/blog/2014/03/06/let-s-code-crudq-and-function-import-operations...

Thanks,

Arun