Reuse Libraries are certainly a significant advantage in the process of developing complicated software. Copy-paste is a kind of antipattern and we should always try to reuse a code.
Fortunately, SAP Fiori allows the creation and usage of reuse libraries.
However, this topic is not covered by detailed documentation and developers sometimes need to struggle with different problems to make it work.
Many people face problems when an application cannot find a library. There can be errors that the library is being searched under the path /sap/bc/ui5_ui5/ui2/ushell/resources where it normally cannot be.
There is a lot of advice over the internet to use the registerModulePath function to get it working. This solution can help but it’s a kind of a workaround. If we launch our application through the Fiori launchpad (and we always should do so) then it’s possible to avoid such a direct call by informing SAPUI5 where to find the library in the manifest.json file.
As soon as UI5 can be hosted on different kinds of platforms I would like to note that this article covers the case when UI5 is hosted on ABAP Netweaver on-premise instance.
When I faced that problem on the customer side I needed to investigate some errors and debug some code to find a solution.
Now I would like to share the knowledge that I achieved during the solving of that problem.
I’ll share some technical details about standard SAP mechanisms that are working during the usage of standard and customer libraries. I hope that looking under the hood can help one better understand how it works on the ABAP on-premise instance and troubleshoot possible problems more effectively.
Error description
For example, you have a Fiori application that depends on a library.
Sometimes you can get an error when the application cannot be opened. In the browser console, you can see that library is searched on the wrong path under /sap/bc/ui5_ui5/ui2/ushell/resources/…
For example, the error in the browser console can look like this:
The cause of this error is that the shell does not know the location of the library and searches for it in a standard SAP location.
A cause of this error can be a missing link to the library in manifest.json of the calling application in section sap.ui5 -> dependencies -> libs, for example:
The library name in the ‘dependencies’ section of the application’s manifest file must match the ‘id’ of the library which is contained in the library’s manifest file.
Below you can see an example of the ‘id’ parameter in the manifest.json file of a library:
In the next section, we will look under the hood to see how exactly the shell finds the path of a library given its id.
How the Fiori application finds the Fiori library
On the front-end
When the application is started then all dependent library paths are retrieved from the back end.
There exists the following web service in SICF:
/default_host/sap/bc/ui2/start_up
This service is called each time before the Fiori application is started from Fiori Launchpad.
In my version of SAP Netweaver, the call is sent from the following piece of code:
/sap/ushell_abap/bootstrap/abap-dbg.js
function requestFullTM
Note: You must open the Fiori Launchpad with the option sap-ui-debug=true to see debug versions of UI5 javascript sources. For example, the URL can look like this:
https://<myserver>:<myport>/sap/bc/ui2/flp?sap-ui-debug=true#Shell-home
After the service is called the response comes as JSON. The response contains a lot of information including the section ‘Dependencies’ with a list of all dependent libraries. If everything was set up and deployed correctly then your custom library should be among these dependencies and its path must also be present.
After that, the shell calls jQuery.sap.registerModulePath from the file /sap/fiori/core-min-0-dbg.js to map the library name with its path.
If something goes wrong then the call to registerModulePath can be missing and the error can occur.
In this case, an explicit calling of this module can help. However, it is always better to find a root cause and make the shell do the call automatically.
On the backend
When an application or a library is deployed to SAP Netweaver then its manifest is parsed in ABAP and all reference information is put into tables /UIF/LREPDEREFCD and /UIF/LREPDCONTCD. It is more convenient to explore these tables with the help of database view /UIF/LREPVEREFCD.
After that, all dependencies of an application can be retrieved from this view. Also, additional information can also be got including a path of a library.
It is possible to force the recalculation of data in these tables by running program /UI5/APP_INDEX_CALCULATE.
All dependencies of an application can be found by the following query to the view /UIF/LREPVEREFCD:
REF_TYPE = ‘UI5DEP’
REF_SUBTYPE = ‘LIBRARY’
NAMESPACE contains the id of your application from manifest.json.
For example, let the app id be as in the screenshot below:
Then we can find its dependencies by the following query from se16:
Reference to the custom library should be in the results:
After that, we can take the library name and make the following query to get its URI:
The result of the query:
If you cannot find any of these records in your system then something could be wrong in the manifest files of the library and application.
Debugging the program /UI5/APP_INDEX_CALCULATE can help you further investigate the issue and find the root cause.
Below are some hints about possible debugging.
The file manifest.json is parsed in method /UI5/CL_UI5_APP_METADATA->PARSE_MANIFEST.
Table /uif/lrepderefcd is updated in method /UIF/CL_LREP_DB_ACCESS_CDEP -> /UIF/IF_LREP_DB_ACCESS~WRITE_REFERENCES
The other table /uif/lrepdcontcd is updated in method /UIF/CL_LREP_DB_ACCESS_CDEP -> /UIF/IF_LREP_DB_ACCESS~WRITE_CONTENT
If data in database tables is okay but the error still persists you can also try debugging the service which returns data to the front end.
Starting point of the service is /UI2/CL_START_UP_HANDLER->IF_HTTP_EXTENSION~HANDLE_REQUEST.
The retrieval of dependencies happens in the following class:
/UI5/CL_UI5_APP_INDEX->/UI5/IF_UI5_APP_INDEX~GET_UI5_APP_INFO_JSON
As soon as data is cached on the backend, to be able to drill down to debugging of the code during the Fiori Launchpad startup you should clear the browser cache and run /UI5/APP_INDEX_CALCULATE beforehand.
It may be more convenient to run a separate method for retrieving dependencies.
For example, you can write the following short program for that:
DATA(lo_ui5_app_index) = /ui5/cl_ui5_app_index=>get_instance( ).
DATA: lt_components TYPE /ui5/app_index_component_id_t.
APPEND 'my.test.appuselib' TO lt_components.
lo_ui5_app_index->/ui5/if_ui5_app_index~get_ui5_app_info_json(
EXPORTING
it_components = lt_components
IMPORTING
et_dependencies_json = DATA(lt_dependencies) ).
Conclusion
I hope that the information was helpful for those who bumped into a similar error and wants to find the solution.
These investigations helped my customer to fix the issue but cases may be different. If you have problems and the article does not help, feel free to ask a question in the comments. I will be happy to help.
Links to some of the useful blogs on the topic
Creating a reusable library in SAP UI5 by Saurabh Sharma
https://blogs.sap.com/2018/02/20/creating-a-reusable-library-in-sap-ui5/
SAPUI5 Custom control library: Web IDE Development, deployment to HCP, and to on-premise ABAP Repository. Part 1. By Sergey Korolev
SAPUI5 custom libraries: Deploy to ABAP Repository and use in applications by Andreas Rothmund