Skip to content

Latest commit

 

History

History
263 lines (156 loc) · 17.2 KB

README_old.md

File metadata and controls

263 lines (156 loc) · 17.2 KB

REUSE status

Description

This repository contains sample code of the RAP Generator that helps you to create boiler plate coding for the ABAP RESTful Application Programming Model (RAP) in

  • SAP BTP, ABAP environment
  • SAP S/4HANA ABAP Environment
  • SAP S/4HANA 2022
  • SAP S/4HANA 2021

Technically it consists out of a RAP business object ZDMO_R_RapGeneratorBO that is used to generate other RAP business objects. For this the SAP Fiori Elements preview in ADT is used that is accessible via the service binding ZDMO_UI_RAP_GENERATOR_O2.

RAP Generator Overview

So in order to leverage this tool you just have to create a package ZDMO_RAP_GENERATOR in the software component ZLOCAL and link and pull the branch btp-abap.

In an on premise system you will have to create a package TEST_RAP_GENERATOR instead and import the content of one of the on-premise branches, either on-prem-2021* or on-prem-2022.

From a usability point of view the RAP Generator works similar like a key user tool since it works with a SAP Fiori UI rather than using an Eclipse based UI.

RAP Generator UI

What's new

  • The objects that have been generated by the RAP Generator can now be safely deleted. This allows you to regenerate the repository objects in case you redo the generation in case there was a typo in the parameters that you provided
  • The generation process is visualized in a table that displays the progress of the generation or deletion alongside with detailed responses of the generation project
  • You can copy a RAP Generator project

Motivation

The basic idea behind the RAP Generator is to ease the life of the developer such that the generator helps to create the complete stack of objects that are needed to implement a RAP business object. The goal is to generate most of the boiler plate coding so that the developer can start more quickly to implement the business logic.

Though there is an ADT based generator available for SAP BTP ABAP Environment and on premise as of SAP S/4HANA 2022 this generator offers some additional features and especially supports multiple nodes whereas the ADT based generator only supports 1 table.

As an input the RAP Generator zdmo_cl_rap_generator uses a JSON file which also reflects the tree structure of a RAP business object. This way all necessary input data is entered upfront and can be reused to create similar RAP business objects, for example for testing or training purposes.

Since it turned out that maintaining the JSON file is quite complex I thought how to add UI to the RAP Generator. Since building Eclipse plugins is a quite complex task I decided to build a RAP business object so that it is possible to use the FIori Elements preview to use the UI without having to deploy any additional components.

The Fiori Elements preview based UI provides value helps for the data that has to be entered and it provides validations and determinations that provides the heavy lifting of specifing which table field is used for which purpose (e.g. a field called local_last_changed_at or a field based on the data element abp_locinst_lastchange_tstmpl will be used as the etag of an entity).

So the RAP Generator works now similar like the well known Key user tools. Once the repository objects are generated the UI offers an ADT link that lets you conveniently navigate back into ADT to continue to work on your objects.

As a new feature the generator now also allows you to delete the objects that have been generated. This comes handy if you have generated your objects within a package that already contained several other objects which would make it cumbersome to delete only those objects that had been generated by this tool.

When using the RAP Generator in an on premise release (2022 or 2021) the generated objects will inherit the language version of the package that you have chosen for your RAP Generator project.

How to use the RAP Generator

Working with the RAP Genertor now works (in short) as follows:

  1. Open the service binding ZDMO_UI_RAPGENERATOR_O2 and double-click on the entity RAPGeneratorProjects to start the Fiori Elements preview
  2. Press the button New Project
  3. Select a name for the root entity and a package where the repository objects will be generated
  4. Select the header data for your project such as whether we are dealing with a managed scenario with uuid based key fields managed_uuid and what kind of data source is used (tables, cds views or abstract entities).
  5. Start to build the composition tree of your RAP BO
    • Enter a data source for your root entity
    • Specifiy which fields of your data source are used as the semantic key or as the total etag
  6. To add child nodes select the parent node and press the button Add Child and do what has been described in step 5 for the newly added child entity.

Start Fiori Elements Preview

Fiori Elements Preview

  • Press Ctrl+Shift+A to start the Open ABAP Development Object dialogue
  • Open the service binding `ZDMO_UI_RAPGENERATOR_O2
    1. Select the entity RAPGeneratorProjects
    2. Press the Preview button

Create a new RAP Generator project

Create new project I Create new project II

  • Press the Create Project button
  • Enter the following
    1. The name of your root entity
    2. Select the package where your RAP business object will be generated. Please note that type ahead support is present.

Maintain header data for your RAP Generator project

Maintain RAP Generator project header data

On the object page we see that the generator has selected ZR_Travel04TP a proposal for a unique name of our new RAP business object which follows the naming conventions of SAP S/4HANA. It basically uses the name of the root entity Travel, takes the namespace Z, uses the prefix R_ for so called reuse views, uses the suffix TP for transactional processing and adds 04 to the root bo name since I already created several objects with the root entity name Travel.

As a default the generator suggest to create a RAP business object that uses tables as data source that have UUID based key fields and that uses a managed implementation. For this in the drop down box Implementation Type the value managed_uuid is pre selected.
In addition table is pre-selected as the Datasource Type and odata_v4_ui as the Binding Type and the check box Draft enabled is marked.

Datasources

As datasources the RAP generator supports table, cds_view and abstract_entity.

Datasource types

As Implementation type the following values can be set managed_uuid, managed_semantic or unmanaged_semantic.

Implementation types

For the binding type you can select one of the following values odata_v4_ui, odata_v2_ui, odata_v4_web_api or odata_v2_web_api.

Implementation types

For green field scenarios a developer usually will choose the implementation type managed_uuid. That means tables will be used as a data source that have uuid based keys, so that a managed scenario can be used where no code needs to be implemented for the CRUD operations and earyl numbering can be used. The only thing that is left for the developer is to implement determinations, validations and actions.

For brownfield scenarios where existing business logic does exist to create, update and delete business data the implementation type unmanaged_semantic can be used. This generates an unmanaged scenario that uses tables with semantic keys.

As a second data source the RAP generator supports CDS views. This way it is possible to create RAP business objects based on existing CDS views.

As a third data source there is now support for abstract entities. Through the support of abstract entities you can generate a RAP BO based on the abstract entities that are generated when a service consumption model is created. Here the implementation type unmanaged_semantic has to be used.

Maintain details for the root entity

Implementation types

You first have to select the data source that shall be used by the root entity.

Implementation types

After you have selected the data source press Return to initiate a side effect. This works for the SAP Fiori Elements OData V2 preview on premise releases. This is why I chose to use the V2 preview.

( In cloud based systems the support for side-effects will be added once these can be added by appropriate implementations in the behavivor definition).

If the side effect does not work simply press the refresh button in your browser after having entered or changed an entry in the field data source.

As a result the generator will try to determine the names of the fields that perform certain roles such as the UUID based key field, the field used as the total etag, etc.

Implementation types

What can not be determined automatically is which field shall be used as the semantic key. Therefore you have to select the same via a value help.

Press Apply to return to the header object page.

(optional) add one or more child or grand child entities)

Implementation types

On the object page of our RAP business object we select the root entity Travel from the list of entities and used the action Add Child.

Implementation types

In the popup you have to enter the entity name of the child entity (here Booking).

Implementation types

You will see a new entry in the list of entities. Select the newly created entity Booking to navigate to the object page for the RAP BO nodes.

Implementation types

After having selected the table /DMO/A_BOOKING_D as a data source and after having pressed return to start the determination of most fields and after having specified BOOKING_ID as the semantic key. Press Apply to return to the (header) rap bo object page.

Implementation types

You can now press the Create button.

Implementation types

After having pressed the Create button the project is created and the json file that is used as an input for the RAP Generator has been created. And you will notice that a button Generate repository objects on the top of your page is now visible.

Implementation types

After having pressed the button to start the generation of repository objects you will see that the generation status changes to Scheduled. (Since RAP does not support to perform commit work statements in the interaction phase nor in the save sequence the RAP Generator is started technically in the background by running an application job).

Implementation types

For the same reason (no commits allowed) it might take a while (up to several seconds) before the status changes to in progress.

Implementation types

Finally you should see that the job has finished successfully. If this is the case you will also see an ADT link.

Implementation types

When clicking on the same you will navigate back to ADT thereby opening the root CDS view that has just been generated.

How to install the RAP Generator

SAP BTP ABAP Environment and SAP S/4HANA Cloud ABAP Environment

  1. Create a package 'ZDMO_RAP_GENERATOR'
  2. Link this package with the URL of the RAP Generator repo https://github.com/SAP-samples/cloud-abap-rap
  3. Pull changes
  4. Use mass activation to activate the objects that have been imported in step 3
  5. Run the class zdmo_cl_rap_generator_setup. This class generates the following objects
    • Application job template ZDMO_RAP_GEN_JOB_TEMPLATE
    • Application log object ZDMO_RAP_GEN_APPLLOG
    • Service binding ZDMO_UI_RAP_GENERATOR_O2
  6. Publish the service binding ZDMO_UI_RAP_GENERATOR_O2

SAP S/4HANA 2021 or 2022

  1. Create a package 'TEST_DMO_RAP_GENERATOR'.
  2. Start the report ZABAPGIT_STANDALONE ( you might have to download the source code of this open source tool first here ).
  3. Create an offline repository or an online repository with the package and with the URL of the RAP Generator repo
    https://github.com/SAP-samples/cloud-abap-rap
  4. Pull changes
  5. Use mass activation to activate the objects that have been imported in step 3
  6. Run the class zdmo_cl_rap_generator_setup. This class generates the following objects
    • Application job catalog entry - ZDMO_RAP_GEN_CATATALOG_ENTRY
    • Application job template - ZDMO_RAP_GEN_JOB_TEMPLATE
    • Application log object - ZDMO_RAP_GEN_APPLLOG
  7. Create an OData V2 UI service binding ZDMO_UI_RAP_GENERATOR_O2
    • Right click on the service definition ZDMO_RAP_GENERATOR

    • Choose Create service binding

    • Enter the name ZDMO_UI_RAP_GENERATOR_O2 and choose the binding type OData V2 - UI (NOT V4)

    • Activate the service binding

    • Publish the service binding locally

      Service binding

Requirements

This sample code does currently only work in

  • SAP BTP, ABAP environment
  • SAP S/4HANA 2022
  • SAP S/4HANA 2021

( I have removed the support for SAP S/4HANA 2020 for the time being since downporting it to this release is a cumbersome and especially errorprone task )

Make sure you have set the following option "Wrap and escape text when pasting into string literal" for your ABAP source code editor in your ADT preferences as described in my blog How to wrap long strings automatically in ADT

Download and Installation

SAP BTP, ABAP Environment or SAP S/4HANA Cloud, ABAP Environment

When you want to install this sample code in your own ABAP Environment systems you can simply download it using the abapGIT plugin in ABAP Development Tools in Eclipse when working with SAP BTP, ABAP environment or SAP S/4HANA Cloud, ABAP Environment

Use the following link to the GitHub repsitory https://github.com/SAP-samples/cloud-abap-rap.

For this you have to create a package in the Z-namespace ( for example ZDMO_RAP_GENERATOR ) in the software component ZLOCAL and link it as an abapGit repository.

Please make sure that you use the branch btp-abap.

SAP S/4HANA 2022 or SAP S/4HANA 2021 FSP1

It is also possible to install the RAP Generator in an on-premise system as of SAP S/4HANA 2020 FSP1.

And for on premise systems you have to use the appropriate branch on-premise-2021 or on-premise-2022

Known Issues

The sample code is provided "as-is".

  • In SAP BTP ABAP Environment system there is currently no support for side-effects in the SAP Fiori Elements preview. You therefore have to refresh the object page yourself in the browser in order to leverage the determinations that determine the mapping between the field names and their role in the RAP business object (e.g. etag).

  • It is currently not possible to set the names of the repository objects used by the virtual root node that is implicitly generated by the generator when using customizing tables with multi inline edit capabilities.

  • When using the RAP Generator in on premise systems you have to make sure that the latest SAPUI5 libraries are installed. If you don’t have the latest version of the SAPUI5 libraries installed you will get no dialogue when pressing the New Project button in the RAP Generator. If the latest SAPUI5 libraries cannot be installed you can use an implicit enhancment in method get_sapui5core_resources_url( ) of class CL_ADT_ODATAV2_FEAP as described in the following blog post:

https://blogs.sap.com/2022/04/16/how-to-use-the-latest-sapui5-library-for-the-fiori-elements-preview-in-adt/

on_premise_2021

  • the behavior implementation class has to be generated / regenerated manually in ADT.

How to obtain support

If you have problems or questions you can post them in the SAP Community using either the primary tag "SAP BTP, ABAP environment" or "ABAP RESTful Application Programming Model".

Contributing

You can add proposals for enhancements as issues.

License

Copyright (c) 2020 SAP SE or an SAP affiliate company. All rights reserved. This file is licensed under the Apache Software License, version 2.0 except as noted otherwise in the LICENSE file.