Dynamic entity structure in the Odata service
Most of the time you will need a flexible Odata entity structure. For example, for adding customer fields or providing only fields which would be displayed in customer scenario.
I found this example from Aron for Media Links: http://scn.sap.com/docs/DOC-44864
But if you need it not for Stream media, but for old good abap tables, please have a look at some additional steps below:
1. You have to perform all steps as described by Aron (except redefining Model and Data provider class methods).
In our example, we will create model with two fields (CARRID and PLANETYPE) from SFLIGHT table:
2. Redefine method Define of model provider class as shown below:
3. Redefine method GET_ENTITYSET of Data provider class as shown below:
Now execute your service adding /Flights and you will see flights data:
With this, you could already build flexible Odata structure. Enjoy!