Gettings Field Reference from RFC into GateWay OData Service
In my career, I found that there are theories and there is a huge gap during actual practice. In real projects, there are exceptions which are not taught in the training sessions. You have to find solution or alternative to get your project rolling.
In this article we would see one scenario, which would practically be used in all OData Projects. How to import or take field references from an RFC?
Before we start, you should be familiar with creating OData services. If not, no need to worry.
For every UI5 application, you would need OData service to have interaction between your app and database (client and server). When you have a single server (embedded deployment) to create ABAP and OData service then no need to worry. It is usually straight forward. Even though embedded deployment has its own dis-advantages.
But when you have to deal with different servers to create an application in UI5, then there are complexities. Let’s see what servers can get involved. In my case, I had to deal with these the following two servers:
- Development Server.
- Gateway Server.
- Development Server : You can assume, this can be used to create or code all your ABAP related developments. Like creating FM, methods etc. Right now we are not concerned about ABAP, so we’ll only look it in perspective of UI5.
- Gateway Server : Gateway server is specifically used for creating OData services for UI5 applications and implementing(submitting) your application.
Most of the gateway server would be greenfield and there won’t be any domains, data elements or any FMs. They are like virgin SAP system, just for performing the gateway tasks. You may not even find the standard data dictionary objects and standard tables to refer.
This is what makes our work a little difficult. If we want to create an OData service, we would at least need the domains or data elements to take reference. But as said already, we might not be that lucky. Check the below screen. Even the world famous MARA table is not available in my gateway server.
Here i’m trying to search one of the standard tables in SAP i.e. MARA. You can see that a message is displayed telling that ‘MARA does not exist. Check name’. This shows that there are no standard data in gateway server.
So do we have to create each and every data element and domains if we want to create a OData service with reference? No way! It’s so time consuming and practically not a good solution. If that were the situation (to manually create each and every domain/data elements) then what is the point of this article.
Let’s check the solution I implemented. Create an OData service for an entity with RFC calling.
My requirement was to design an application to display vendor details like Vendor number, Vendor name etc.
Step 1 : Create an FM in development server. You can create your project relevant FM. The FM should be RFC enabled.
Step 2 : Create an OData service in Gateway server.
Step 3 : Now we will create an entity with RFC reference.
Right Click on ‘Data Model’ > Import > RFC/BOR Interface.
Step 4 : It’ll will open a dialog box. Input the following.
- Entity Name : VendorSH
- Target System : Choose Remote
- Provide RFC destination : Give the destination of your development server (if you don’t know what it is, please ask your basis team).
- In data source attributes choose
- Type : Remote Function Call
- Name : Provide the FM name which you have created in development server.
- Type : Remote Function Call
- Check the ‘Create Default Entity Set’. This will create entity set for your entity.
- Then press ‘Next’.
Note : You should have your FM RFC enabled else it’ll show a message saying that the FM is unavailable.
Step 5 : In next step you can see the below pop up. Expand the exporting parameter of your FM. You can see all the properties which are in your FM. Select the fields which are necessary for your project. Then press next.
Note : Usually we use exploring parameter fields. Because we need the structure like exporting parameter to hold data. Which give the results/output. We can take other structures as well, but there is the point in taking them if we do not use them.
In my example FM, I have only exporting parameter ‘ET_DATA’.
Step 6 : In next screen it’ll ask you to choose key as your usual odata creation. Then click on finish.
That’s it. We have our OData service ready. You can use this OData in your UI5 Applications.