The RAP Generator
When preparing hands-on sessions for the SAP Fiori Programming Model (in the past) and now for the ABAP RESTful Application Programming Model (RAP) I always faced the problem that we had to start from scratch.
That means that the participants were forced to create all objects of the stack such as table(s), interface CDS view(s), projection view(s), metadata extension view(s), behavior definition and projection for interface view(s) and projection view(s) and behavior Implementations alongside with a service definition and a service binding.
Most of what a developer has to do here is to write boiler plate coding such as the use of the insert all elements option when creating a CDS view based on a table or another CDS view.
For educational purposes it’s OK that you learn how to develop all the objects step by step. But if you want to provide a deep dive session it is not much fun if you have to create lots of boiler plate coding before having the chance to dive into the more interesting topics.
Also for a normal developer it would be nice to have the chance to speed up the development process by getting an up- and running starter business object.
So I was very pleased when begin of 2020 I saw in an SAP internal review the new XCO framework (“Extension Components”) which allows you to generate various ABAP repository objects via released ABAP API’s.
So I started to develop a class that allows you to generate nearly the complete stack of a RAP business object based on one root/header and multiple child and grandchild tables.
Meanwhile the project has grown and the RAP Generator project contains a RAP business object so that it offers a cool SAP FIori Elements UI. This Fiori Elements UI can be started using the Fiori Elements preview functionality from within ADT. And since the Fiori Elements UI offers an ADT link once the repository objects have been generated this UI well embedded in ADT as well.
Since I decided to make my development available on GitHub https://github.com/SAP-samples/cloud-abap-rap you can alway retrieve the latest version from there.
New: SAP Fiori Elements UI
With the 2202 release now the fifth version is available which now offers a SAP Fiori Elements UI similar to the well know key user tools in SAP S/4HANA. This can be as said started using the Fiori ELements preview of the RAP business object OData V2 service binding:
Lets have a look at the famous flight sample and take the two tables that are part flight sample repository
When you have dowloaded the RAP Generator and run the setup class so that the service binding ZDMO_UI_RAPGENERATOR_O2 is available.
Once you have created the RAP Generator project and have added the root and the child entity based on the two tables the RAP Generator will first create a JSON file
and once you press the “Generate Repository Objects” button the generator will create the following repository objects:
- Draft tables
- CDS restrictive reuse views
- CDS interface views
- CDS projection views
- Metadata Extensions
- Behavior Definition
- Behavior implementation classes
- Service definition
- Service binding
After the generation has taken place you will find an ADT link that lets you navigate back ADT to continue to work on the repository objects that have been generated for your convenience as shown in the following screen shot:
Please note that the generated artefacts follow the naming convention which is used for the development in SAP S/4HANA.
When using the RAP BO of the RAP Generator you will find that it offers some advanced features or RAP programming such as:
- type ahead support when searching for packages or data sources (tables, CDS views or abstract entities)
- drop down lists
- fields and actions that change their behavior based on the current status of the instance of your RAP Generator project
- storage of hierachial data in one table
First ADT based generation of RAP objects (SAP standard delivery available)
Meanwhile (as of release 2111) it is also possible to generate a RAP business object from within ADT as part of the SAP standard.
The process is described in the SAP Online Help:
Why do I still work on the (openSource) RAP Generator though there is an ADT based version out?
This is because both generators have different goals / target groups.
The new ADT based wizard focuses on a simple used case. It does only support the generation of a RAP business object based on one table and will generate a draft enabled managed business object.
When starting my opensource based RAP Generator my goal was also to support more complex scenarios that encompass not only a root node but also scenarios where you deal with a root node and one or more child nodes that itself may have one or several childnodes themselves.
RAP generates RAP
The RAP Generator takes a JSON file as an input that contains all the information needed to generate all the objects of the business object hierachy.
The main problem was that the JSON file that I use as an input for the command line based RAP Generator class is nice from a technical point of view but it was not easy to handle by a developer who tries to use my tool for the first time.
The JSON file becomes however handy if you have to create multiple RAP business objects as we need them in RAP workshops or training courses.
To tackle the problem of having to explain how to handle the complex JSON file I decided to use our own tooling, namely RAP, to build a UI for my RAP Generator. (“eat your own dogfood ;-)).
The RAP Generator RAP BO is using a managed implementation with UUID based keys. While the root entity contains the header data of your RAP Generator project such as the implementation type being used (managed uuid, unmanaged semantic, …) or the data source type being used (tabel, cds view, …) or whether draft or not is to be supported the child entity contains the node hierachy of your RAP BO.
Special thanks for several discussions go to Soeren Schlegel who suggested to use an object oriented approach to get to a scalable architecture as we have it now.
A great thank you also to Sebastian Michler the product owner of the XCO libraries for answering all my questions.
I added a click through guide on how to use the RAP Generator (on premise and in Steampunk) in the readme.md file of the GitHub repository:
When you want to create a table maintenance app with multi inline capability and that is automatically registered in the Business Configuration App of your Steampunk System you can select these as an option in the new Fiori Elements UI.
You find the technical documentation to the readme.md file of the GitHub repository.
- Support for deletion of generated repository objects:The RAP Generator does currently not delete the objects that have been generated. When you choose “delete” only the project information will be deleted.
- Support to copy projectsRight now you cannot yet copy an existing project but would have to enter all data from scratch.A workaround would be to use the JSON file and make adjustments there and start the RAP Generator via a commandline implementation
Where can I get the source code?
The source code for RAP Generator can be found on GitHub
- 19.05.2020 – added link to GitHub repo
- 31.05.2020 – added the demo from my SAP Online Track talk [SOT114] The RAP generator
- 05.06.2020 – changed the code of the RAP Generator so that it works again after HFC3 has been applied
- 10.06.2020 – Published new version that offers the following
- Object oriented design
- BO node class
- BO generator class
- Support for multiple child, grandchild, … nodes
- Unit tests
- Exception class
- Object oriented design
- 31.08.2020 – New version that offers the following
- Structure of the BO can be defined in a JSON file
- Support for CDS views as a data source
- 11.09.2020 – Added a link to a how to a click through guide
- 12.01.2021 – Added a hint to the ADT based option to generated RAP business objects that is available as of 2111.
- 12.03.2021 – added new version for 2102 with full OData V4 and draft support
- 21.04.2021 – Added support to generate business configurations that are automatically registered for the Business Configuration Maintenance App and that record changes in transport requests
- 16.06.2021 – published a version for the use in SAP S/4HANA 2020 on premise systems
- 24.08.2021 – Added support for multi inline edit, abstract entities and structures as datasources
- 07.02.2022 – Added a first draft of a SAP FIori Elements UI (for cloud and 2021)
- 14.04.2022 – Refactoring and downport of the Fiori Elements UI also to 2020