In the previous blog we have setup RFC enabled function module. If you want to expose this function module as ODATA service you can use the wizard in transaction SEGW. This blog assumes the basis ODATA basis activation has been performed (see this blog).
Questions that will be answered in this blog are:
- How do I generate an ODATA service based on a RFC function module?
- How do I test if the ODATA service is properly working?
Set up of the ODATA service
Start transaction SEGW and create a new project:
Now start the RFC import wizard by right clicking on Data Model and selecting the option Import and then RFC/BOR interface:
Now select the data parameters:
And enter which field is key field:
After pressing finish the wizard will generate the needed classes.
Save your work and press the check button to validate if everything is ok:
Now we need to map the implementation to the RFC module. Right click on the GetEntitySet below ZODATADEMOENTITYSet and select Map to Data Source:
Now map the fields (you can use drag and drop):
Now you need to map the data fields correctly and press check.
Save your work.
Generation of objects
You can see that the Runtime Artifacts section is still empty.
Now press the button Generate Runtime Artifacts:
Wait for the generation to finish:
Now the runtime artifacts are generated, but the service maintenance is not done yet. Open the section Service maintenance and double click on the system:
Now press the Register Service button:
Accept settings and assign package for transport:
Now the registration status is green.
Testing the ODATA service
Press the button SAP Gateway Client (or start transaction /IWFND/GW_CLIENT directly, and then enter the correct service):
The test client starts:
Enter the correct inputdata: /sap/opu/odata/SAP/ZODATADEMO_SRV/ZODATADEMOENTITYSet(‘1’)
And check the output:
Attention points
The example above seems simple, but you will face more issues in real live implementation when you need to add tables and more complex structures. In those cases additional configuration and many times extra coding in the methods of the generated classes is required.
Nice blogs to start with:
- SEGW ODATA code based development
- FIORI ODATA service creation
- ODATA example based on DDIC structure
- RFC based ODATA with multiple selection values
- Step by step creation of ODATA sales order
- CRUDQ explanation blog
- Step by step deep entity sets
- Media (attachments) handling in ODATA
ODATA security
The user calling the ODATA service needs a special right in SAP to be allowed to call the ODATA service.
Start transaction PFCG and create a new role. On the menu tab select the option Authorization Default. Then select type Tadir and object type IWSV gateway business suite enablement. Now you can finally search for our own developed and activated ODATA service:
Now save the role and assign it to the user(s) needing to call this ODATA service.
The application security relies on the function security authorization check inside the RFC function module.
ODATA V2 and V4
SAP is now moving from ODATA V2 towards ODATA V4. Read more on ODATA V4 activation in this blog.
Hello, thanks a lot for the post.
One thing i don’t understand is how the SEGW recognize your Ztable as a property of your entity ZODATADEMOENTITY during the mapping for the GETENTITYSET. Me i have also a function module with a table parameter, i use the wizzard to create all entities and sets but when it comes to the mapping, i don’t see the equivalent of your Ztable as a property and i can’t add it manually….How did you do that please? You don’t have any associations on your screen so i don’t understand what is missing here…