Extend oData Services for My Travel & Expenses Fiori App – Part 1
1 Business Requirement – Why we need to extend standard app ?
The fields delivered in standard SAP Fiori app for “My Travel & Expenses” does not suffice the business needs.
- Changes required
- Document No required as input on screen so that user can enter original receipt no to it and save the same
- No of Employee is required for meal expenses so that user can enter no of employee attending the business dinner/lunch outing. Adding names of each employee is difficult job. And when you have around 150 attendees then it’s kind of waste of effort.
- %Lobby is also needed on the screen for input
- Per diem region has to be hidden, it’s no longer required
1.1 Extend Fiori App “My Travel and Expenses”
2 Fiori app extension has two part
2.1 Extending front-end of Fiori App (UI Extensibility)
- Screen and section to which field has to be added is identified and extended.
- Entity name which will be used to map data to new fields is also identified
2.2 Extending oData service on backend system
Front end developers confirm the entities which has to be extended and also the respective new custom field names.
For this scenario entity name provided by frontend developer is “EXPENSES“
Fields to be added are “DocumentNo”, “NoOfEmployees” & “LobbyPercentage”
2.2.1 oData service is extended using below step
- Identify the oData service name for standard app
- Identify the corresponding ABAP DDIC structures for entities to be extended
- Create custom gateway project & Redefine the standard oData service
- Add custom field to entities confirmed for extension
- Implement BADI for fetching and manipulating new Data
- Regenerate & Register the new service
3 Identify oData Service name of standard Fiori app
- Go To Fiori Reference App Library
- Search for My Travel & Expenses App (Direct Link for My Travel & Expenses Fiori App)
- Click on tab “Implementation Information”
- Navigate to Configuration
- Check for oData service name
PAOC_TRV_SRV is oData service for “My Travel & Expenses” Fiori App
Note: This information can also be provided by front end developers, they can locate it in Controller section of fiori app .
4 Extend corresponding ABAP structure
Entity name confirmed for this requiremnt is “Expense” and fields to be added are:
- “DocumentNo” (type=edm.String; MaxLength=20 ; )
- “NoOfEmployees” (type=edm.Decimal; MaxLength=3 ; )
- “LobbyPercentage” (type=edm.Decimal; MaxLength=3 ; )
4.1 Identify the corresponding abap structure
- Go to transaction “SEGW“
- Click on open project
- Enter the project name and execute (In general if we remove _SRV from technical service or oData servive then we will get name of standard gateway project or you can do search like PAOC_TRV* after removing _SRV from oData service name)
- Navigate to Data Model->Entity Types and get structure name for EXPENSE entity
4.2 Add custom field to identified structure
- Go to transaction “SE11“
- Enter structure name and click on display
- Click on Append Structure
- Click on create append
- Enter name of new append structure and hit enter
- Add field to new structure and activate
- Now new fields are added to standard structure
5 Redefine oData Service
- Go to transaction “SEWG“
- Click on Create Project
- Enter Project Name, Description and Package Name. Then hit enter
- Right Click on Data Model and select Redefine -> oData Service
- Enter standard oData Service name “PAOC_TRV_SRV” then hit enter
- Now all the Standard project objects are copied to custom project and new Z* runtime artifacts are created
6 Add custom field to Entity Types
- Navigate to Data Model -> Entity Types -> Expense . Double click on Properties
- Click on Append Row
- Blank row will added to bottom please enter Property Name ( e.g “DocumentNumber” )
- Select Edm Core Type ( You can type in Edm.String or select from F4 help )
- Check for the operation needed on this field, refer screen shot in step 6.3 . For e.g. Creatable, Updatable, Sortable, Nullable
- You can enter label for this field click on Label Help ( marked as red box 1 in step 6.3 )
- Select reference ABAP field . CLick on corresponding ABAP field blank space and press F4
- Save the changes
- Similarly add other fields NoOfEmployee, PercentLobby and save the changes to project
- Now select Project name and Generate Runtime Objects
7 Find & Implement BADI for My Travel and Expenses App
Refer Section 3. there we can find details about extesniblity in extensibility node, and also link to
“My Travel & Expenses” Extensibilty Help . In this help page you can find the name of BADI.
- Go to transaction “SE18” and open the BADI PAOC_MY_TRAVEL_EXPENSES_BADI in display mode
- Copy the Enhancement Spot Name and Go to “SE19” .
Create implementation for Enhancement Spot PAOC_MY_TRAVEL_EXPENSES
- Enter Implementation Name , Description and hit enter
- Enter Implementation name, implementing Class Name , Select BAdI and hit enter
- Select Create Empty Implementation
- Select Sample Class and Click Copy Sample Class
Activate BAdI implementation.
- Go to transaction SE24 and change implementing class ZCL_HR_NA_PAOC_MTE_EXTEND.
Check & remove any pre-existing unwanted code copied from sample class methods.
Activate the implementing class
Do you happen to know to which database table PAOC_TRV_SRV is writing to? Is it a HR info type?
I see that table PTRV_SADD is updated for Additional Receipt Information.
You can search for other tables by PTRV* .
Standard function module used for saving expense trip is “PTRA_WEB_EXPENSE_REPORT_SAVE_2”
It accepts data for Expenses in Fiori App or ESS ( WebDynpro App) using structure “PTRV_WEB_RECEIPTS_INT_2”
Good write up! I try extending oData but I have encountered the following error:
Did you encountered this? I'm already on the latest and greatest version of the Software Component for this.
Hello Soo M Tan,
Did you resolve this error ? Or still it is a concern.
This error has been solved by patching SAP_GWFND:
Thanks for Update 🙂
This is an excellent post. Thanks for posting.
I have one question:
Why did you redefine the service in step5? Couldn't you just implement the bady?
I think that you extended the service because you wanted to modify the entity "Expense" and there is no way to add fields to the entity of the standard service, but I want to confirm with you.
Like in this case:
How To: Enhancing an SAP Fiori App Gateway Service (PO Tracking)
Yes you are right.
There was bug in earlier version which did not allow me to get desired results.
So that time I redefine. But at later stage this was taken care and resolved by SAP in new versions.
You can absolutely just implement BADI and take care of extension in back end.
I will try to update this post ASAP.
Thanks for reminding.
I need your help, I am trying to add a new field at the head of the trip, exactly below the dates of the trip.
Perform the steps in the document, add append to the spaoc_trv_header structure, add the field to the data model and implement the badi.
In the webide add the extension project TRV_TE_CREE. By extending the S4_belowReportDetailDatesCustom.fragment.xml view, add the input field.
When saving the trip the value of the input field is not displayed in the method IF_PAOC_MY_TRAVEL_EXPENSES ~ TRAVELANDEXPENSE_GET_ENTITY.
I do not know what would be wrong.
I would appreciate the help.
Hi Prakash Saurav,
i followed this blog to extend my travel request V2 oData service SEGW some of the strings are missing from the annotation.
Please refer below mentioned my blog for more info about the error.
After Extending Standard Odata Service strings are missing in Annotation meta data
Please help to sort this issue.