Technology Blogs by SAP
Learn how to extend and personalize SAP applications. Follow the SAP technology blog for insights into SAP BTP, ABAP, SAP Analytics Cloud, SAP HANA, and more.
cancel
Showing results for 
Search instead for 
Did you mean: 
Andre_Fischer
Product and Topic Expert
Product and Topic Expert

Update


There is a new version of the RAP Generator available.

New version of RAP Generator available | SAP Blogs

Introduction


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

  • /dmo/a_travel_d

  • /dmo/a_booking_d


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:

Example: RAP Business Service Generation

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.

Acknowledgements


Special thanks for several discussions go to soerenschlegel 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 sebastianmichler the product owner of the XCO libraries for answering all my questions.

Click-through guide


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:

cloud-abap-rap/README.md at main · SAP-samples/cloud-abap-rap (github.com)

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.

Roadmap



  • 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

https://github.com/SAP-samples/cloud-abap-rap 

 

Updates



  • 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



  • 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


 
57 Comments
IanStubbings
Active Participant
0 Kudos
Great blog post andre.fischer This will make things substantionally easier when faced with creating several config tables for example.  I'll test it out in the next few days.

I guess I'll have to edit my blog post after that as well 🙂

Cheers

Ian
hardyp180
Active Contributor
Can I ask what gets generated when you have a header and an item table e.g. sales order header and sales order item?

The reason I ask is that every blog (often from different SAP employees) I read seems to have a different take on what CDS views need to be created in such a case. Sometimes one (or more) each for both tables, and one (or more) combined CDS view(s), sometimes just one combined view, or any combination of the above options.

This is a wonderful step forward by the way. People are going to want to use this as a normal thing, not just for TechEd demos. It is just like the table control generator in DYNPROS or all the generated code in Web Dynpro or indeed the code that gets auto-generated when you want to call a BRF+ rule.

In every case you do not want to do the exact same thing again and again, month after month, year after year, possibly doing it slightly differently each time and missing something, when your aim to to write the exact same code as you did before.

Cheersy Cheers

Paul
ravi_rajput
Participant
0 Kudos
Great stuff Andre. I tested it and works like a dream. Thanks !
Vijay
Active Contributor
0 Kudos
Awesome!! Thanks for sharing andre.fischer..
dvankempen
Product and Topic Expert
Product and Topic Expert
0 Kudos
Thanks for publishing to GitHub (as mentioned).
SBurghardt
Explorer
0 Kudos
Very interesting approach, thanks for sharing. Are there any prerequisites before creating the class zrap_cl_bo_generator?

We are getting Errors since use of the sxco* elements is not permitted.
maheshpalavalli
Active Contributor
0 Kudos
Nice one andre.fischer . Especially the XCO framework sounds very interesting. Hope to get my hands dirty on this soon 🙂
Andre_Fischer
Product and Topic Expert
Product and Topic Expert
Andre_Fischer
Product and Topic Expert
Product and Topic Expert
As I wrote the XCO framework is currently only available via a feature toggle. But we plan to make it available for all Steampunk system soon as well as for future on premise systems.
sv_v
Explorer
0 Kudos
Great Blog! Thank you very much!
shanthi_bhaskar
Active Contributor
0 Kudos
Nice blog Andrew, Never knew we can create a table in this way.
Michæl
Participant
0 Kudos

Just had a quick chat with my robots: They love the generator and XCO!

Great piece of fuel for the steampunk and the head. Works like a charm.

Thanks

former_member596519
Participant
0 Kudos
I totally agree with you Paul!

 

This is going to be very useful and time-saving!!

 

Thanks andre.fischer for sharing.


Cheers,

Aleksandar
raeijpe
Contributor
0 Kudos

Andre, Great stuff again and very useful. Thanks for sharing

Astashonok
Participant
0 Kudos
If I get this in console:
start
XCO Generation: PUT exception:
"action | association | create | delete | determination | determine |
draft | factory | field | function | internal | mapping | static |
update | validation | }" expected, not ";".
"action | association | create | delete | determination | determine |
draft | factory | field | function | internal | mapping | static |
update | validation | }" expected, not ";".
"field | mapping | use | }" expected, not ";".
"action | association | create | delete | determination | determine |
draft | factory | field | function | internal | mapping | static |
update | validation | }" expected, not ";".

what has failed?
Andre_Fischer
Product and Topic Expert
Product and Topic Expert
0 Kudos
The generator has failed because it contained coding that I had to implement to provide a workaround for a tiny bug in the XCO framework.

This bug was fixed with Hotfix Collection 3 that has now been applied to the trial systems.

I have updated the code in GitHub.

Just pull it again.

It should work now.

Best regards,

Andre

 
Hi Andre,

I've just tested your rap code in my Abap trial account, and its brilliant.

I've uploaded your code in the following package:


Rap code in cloud


and i've generated my own tables and its generated successfully:


 

Thanks!!!
Föß
Active Participant
Hi andre.fischer

the RAP Generator is absolute brilliant. Today I tried it for the first time successfully in a ABAP Cloud Trial environment.

I think, you spent a lot of days (or/and evenings?) to bring the RAP Generator alive.

Thanks you very much!

Föß
Steentje
Explorer
0 Kudos
Fantastic,

 

Way to go thanks a lot for your time.

 

Greetings,

 

Danny
p619793
Active Participant
0 Kudos
Can we use it now in S/4HANA on-prem 1909?
Andre_Fischer
Product and Topic Expert
Product and Topic Expert
No  but in S/4HANA 2020.
p619793
Active Participant
0 Kudos

Thanks Andre for your prompt reply. Some of my use cases are to create ‘Display only’ apps and web APIs SAP S/4HANA 1909. So as I understand it, prerequisite to use this generator is to create the tables first with parent-child relationships. I am thinking of :

  1. creating them in ABAP cloud environment in ADT
  2. generate the RAP objects using the RAP generator ABAP cloud
  3. copy the generated package through abapgit into S/4HANA on-prem.

Is it possible or unmanaged scenario is not supported by RAP generator?

Best regards,

Sumit

Andre_Fischer
Product and Topic Expert
Product and Topic Expert

Hi Sumit,

you are totally right. This is possible.

You can create repository objects in a SAP Cloud Platform, ABAP Environment system and copy the generated objects via abapGit into S/4HANA 1909 on-prem. For this you can also use a trial system, but keep in mind that these systems are shared systems so the objects you are going to create are in principle visible for all trial users.

For the use case you are interested in “unmanaged_semantic_key” the Generator only expects that there is a hierarchy of tables where the header table always contains all key fields of the item table. See also the readme.md file for more details

https://github.com/SAP-samples/cloud-abap-rap/blob/master/README.md#managed_semantic_key-or-unmanage...

Best regards,

Andre

p619793
Active Participant
0 Kudos
Appreciate your detailed answer. Yes, I later realized that GitHub sample already contains sample JSON for unmanaged scenarios, should have peeked in there already.? Thanks for directing me to the right sample.

Best regards,

Sumit
jagdish_c
Employee
Employee
Hi Andre,

Really nice blog and RAP generator. I was trying out your RAP generator in my trial account. I found that it is generating ODATA V4 for the service definition. Is there a way to specify to choose the Odata version in the RAP generator? Perhaps an entry in the JSON?

 

Kind regards,

Jagdish
Andre_Fischer
Product and Topic Expert
Product and Topic Expert
Hi Jagdish,

You can do so using the new parameter "bindingtype".

sorry, but I wasn't able to update the documentation so far.

I just started to do so.

https://github.com/SAP-samples/cloud-abap-rap/blob/master/README.md#bindingtype

Best regards

Andre

 
jagdish_c
Employee
Employee
0 Kudos
Hi Andre,

Thank you for your swift reply 🙂 . I will try with this parameter to generate ODATA V2.

Kind regards,

Jagdish
Attila
Active Participant
0 Kudos
Hello Andre,

thanks for sharing this, I love code generation, and espeially this tool. Here we see the real power of the environment and we have a knob to grab and use it finally. I also felt the same for years know, that I am doing the same time to time with transactional applications in Fiori.

I have a question about the planned feature: Generation of CDS views for domain fixed values.

Comparing the Trial Environment to S/4HANA, we do not have the CDS View I_DomainFixedValue in ABAP Trial.
We do no have access even to table dd07t in Trial, so I was not able to create a reusable CDS View for domain texts myself.

Does it mean we need to create custom tables for codes and texts in the Trial environmentl instead of using Domain fixed values? Maybe yo know this better, and how to overcome, due you planned this feature.

Thank you, Attila

 
philipdavy
Contributor
0 Kudos

andre.fischer,

Can we also create consumption view with XCO library ?

Andre_Fischer
Product and Topic Expert
Product and Topic Expert

yes.

check out RAP BO Generation - SAP Help Portal 

and there check method 

add_ddls( )

and use

 ->add_entity( ) 

instead of

->add_view_entity( ).

 

DATA(lo_view_entity) = lo_interface_specification->set_short_description( 'Vacation request'
)->add_view_entity( ).
 
Pankaj1
Participant
0 Kudos
Hi andre.fischer ,

I hope u r doing well.

I am facing an issue while using RAP generator code in BTP, ABAP. Code has been loaded from git to BTP ABAP but it has syntax errors.


I am connecting this repo: SAP-samples/cloud-abap-rap: This repository contains several examples how to develop with the ABAP R....
Andre_Fischer
Product and Topic Expert
Product and Topic Expert
There are two branches available.

I assume that you have used the on premise branch.

cloud-abap-rap/#dmo#cl_rap_generator.clas.abap at On-Premise-2020 · SAP-samples/cloud-abap-rap (gith...

Only here you will find ABAP code that calls objects whose use is not permitted in the cloud.

Please make sure that you have used this URL.

https://github.com/SAP-samples/cloud-abap-rap.git

and that you have used the "main" branch.

Kind regards,

Andre

 

 
Pankaj1
Participant
0 Kudos
Thanks andre... you are right.. i am able to use it now.
Andre_Fischer
Product and Topic Expert
Product and Topic Expert
For any requirements you have that are not covered please raise an "issue" in the GitHub repo,
I just have posted a new version of the readme and the source code of the 2108 version.cloud-abap-rap/README.md at main · SAP-samples/cloud-abap-rap (github.com)
Pankaj1
Participant
0 Kudos
Sure Andre... i am able to use the latest code now.. thanks for your help and support to the community.
0 Kudos

Hi Experts,

 

Recently I was trying to use the RAP generator class /DMO/CL_FE_TRAVEL_GENERATOR. 

 

I get the error as below. Not sure what the problem is. Can anyone suggest?

 

PUT operation failed.
Class name:
CX_XCO_GEN_PUT_EXCEPTION
Source position:
Line 8 of EXECUTE in CL_XCO_GEN_O_PUT_ABSTRACT
Additional messages:
DDLS ZI_FE_STAT_000698: Creation of CDS views is not allowed in the current environment.
DDLS ZI_FE_CARR_000698: Creation of CDS views is not allowed in the current environment.
DDLS ZI_FE_CONN_000698: Creation of CDS views is not allowed in the current environment.
DDLS ZI_FE_FLIG_000698: Creation of CDS views is not allowed in the current environment.
Stack trace:
CX_XCO_RUNTIME_EXCEPTION constructor [method] Line: 15
CX_XCO_GEN_PUT_EXCEPTION constructor [method] Line: 1
CX_XCO_GEN_PUT_EXCEPTION for_ongoing_operation [method] Line: 3
CL_XCO_GEN_O_PUT_ABSTRACT execute [method] Line: 8
CL_XCO_GEN_DDLS_O_PUT if_xco_gen_ddls_o_put~execute [method] Line: 12
CL_XCO_CP_GEN_DDLS_O_PUT_SCT if_xco_cp_gen_o_put_section~execute_operation [method] Line: 1
CL_XCO_CP_GEN_D_WORK_SHOP put_section [method] Line: 1
CL_XCO_CP_GEN_D_WORK_SHOP if_xco_cp_gen_d_work_shop~put_sections [method] Line: 4
CL_XCO_CP_GEN_O_PUT if_xco_cp_gen_d_o_put~execute [method] Line: 4
/DMO/CL_FE_TRAVEL_GENERATOR main [method] Line: 92
CL_XCO_ADT_CR_SIMPLE_ACTION execute [method] Line: 1
CL_XCO_DP_ACTION_ABSTRACT if_xco_dp_action~execute [method] Line: 8
CL_XCO_ADT_CALL_CLASSRUN if_xco_rt_adt_call_classrun~dispatch [method] Line: 1
CL_XCO_RT_ADT_CLASSRUN_ABSTR if_oo_adt_classrun~main [method] Line: 12
CL_OO_ADT_RES_CLASSRUN execute_clas [method] Line: 118
CL_OO_ADT_RES_CLASSRUN post [method] Line: 41
CL_ADT_REST_RESOURCE if_rest_handler~handle [method] Line: 21
CL_REST_ROUTER if_rest_handler~handle [method] Line: 59
CL_REST_HTTP_HANDLER if_http_extension~handle_request [method] Line: 98
CL_ADT_WB_RES_APP lif_request_handler~handle_request [method] Line: 18
CL_ADT_WB_RES_APP handle_request [method] Line: 316
CL_ADT_WB_RES_APP if_http_extension~handle_request [method] Line: 19
CL_HTTP_SERVER execute_request [method] Line: 807
SAPLHTTP_RUNTIME http_dispatch_request [function] Line: 1600
SAPMHTTP %_http_start [module pbo] Line: 11

 

 

Thanks

Chirag

dhruvjaihind
Explorer
0 Kudos
Thanks for the wonderful work..tried with own db tables on steampunk..works seamlessly with zero effort.
sindhu_s
Explorer
0 Kudos
Hi Andre,

I just tried to install RAP Generator using the steps suggested in below link (from How to install RAP Generator section ), But when I pulled the code from GIT Hub for 2020 Service Binding is not getting generated/created.

cloud-abap-rap/README.md at main · SAP-samples/cloud-abap-rap · GitHub

2020 does not have a certain interface to create service binding is what I heard is there a alternate solution/way ,  please suggest!

Thanks and Regards,
Andre_Fischer
Product and Topic Expert
Product and Topic Expert

Sorry, in 2020 you have to create the service binding ZDMO_UI_RAP_GENERATOR_O2 (OData V2 UI) manually from the service definition ZDMO_RAPGENERATORBO.

Just right-click on the service definition and choose New Service Binding

I just updated the readme.md file.  

sindhu_s
Explorer
0 Kudos
Hi Andre ,

Thanks for the reply !

Yes now I was able to add Service Binding !

After all the steps as mentioned in the blog , I am getting below error !

Can you suggest if something is missed !

 

"A more recent version available" error as below , its not going inspite of refresh!


Thanks and Regards,

Sindhu S
Andre_Fischer
Product and Topic Expert
Product and Topic Expert
0 Kudos
There seem to be hickups from time to time with the draft enabled UI.

I suggest to close the browser and start the preview again.
sindhu_s
Explorer
0 Kudos
Hi Andre,

Tried in new browser and incognito mode as well ! still same issue 😞

We are at last step and very much excited to sail through this !

Could you please help or suggest !



 


Thanks and Regards,

Sindhu
shavneet1
Participant
0 Kudos
Hello Andre,

 

I was trying to create entire artifacts of the RAP model using rap generator , as explained by marcel in one of the SAP teched video. There i saw everything worked smoothly. While trying the same, i got lots of errors , started with the field client , then in the behavior definition also, usage of strict, global authorization not being implemented. i had to delete all these manually , and finally got the error INSTANCE_FEATURE method is not implemented , but in the demo , there was no such error, and none of the code was written or edited.

 

Can you or macel kindly tell me where did i get wrong. i am using trail version.

 

Regards ,

 

Shavneet
Andre_Fischer
Product and Topic Expert
Product and Topic Expert
Hello Shavneet,

can you please post the problem in the Q&A section Ask a Question | SAP Community ? There I would like to ask you to provide a few additional details such as the source code of the table you used, screen shots of error messages and the ADT version that you are using.

Kind regards,

Andre

 
shavneet1
Participant
0 Kudos
Hello Andre ,

Thanks for prompt reply.

Based on your reply , i checked the database table code , and found that administrative fields in the demo customer example were different than one i was using in the travel table. Changed that, and everything worked smoothly !!
tejeshshelar
Newcomer
0 Kudos
Hi Andre,

I am trying to add field to database table using XCO library .

How do I add annotation to currency and quantity field.

@Semantics.amount.currencyCode : 'zrap_abook.currency_code'
flight_price : /dmo/flight_price;
currency_code : /dmo/currency_code;

 

I tried following method

lo_identifier->add_annotation

but the add annotation method is not available for table field but only for CDS.

I noticed that RAP generator has generated the annotations for DB table as well.

 

 

Regards,

Tejesh
Andre_Fischer
Product and Topic Expert
Product and Topic Expert
0 Kudos
Check out method create_table in class ZDMO_CL_RAP_GENERATOR.







database_table_field type ref to if_xco_gen_tabl_dbt_s_fo_field

database_table_field->currency_quantity->set_reference_table( CONV #( to_upper( io_rap_bo_node->table_name ) ) )->set_reference_field( to_upper( dbt_ref_field_name ) ).

 
0 Kudos
Hi,

 

I was trying to generate objects via abstract_entity, which was also generated via Service Consumption Model (importing metadata.xml).. however I was getting this error" No etag master field found" . In the json string there was no value assigned to it. Can you advise how to fix this

 


Error in Etag

Marcel_Wahl
Advisor
Advisor
0 Kudos
Hi Oliva,

That error occurs if the system could not determine a last changed or local last changed timestamp.

e.g. because you entity doesn´t have admin fields.

Solution: add "last changed" and/or "local last changed" data fields with the SAP standard data elements.

see SAP help here:

https://help.sap.com/docs/ABAP_PLATFORM_NEW/fc4c71aa50014fd1b43721701471913d/982a40c45eba4443b2b6a25...

or sample here:


created_at : abp_creation_tstmpl;


created_by : abp_creation_user;


last_changed_at : abp_lastchange_tstmpl;


last_changed_by : abp_lastchange_user;


local_last_changed : abp_locinst_lastchange_tstmpl;


Hope tha thelps


Andre_Fischer
Product and Topic Expert
Product and Topic Expert
0 Kudos
For each entity you have to map a field that serves as an etag.

As a workaround you can select an arbritray field of your entity and map it.

I have added this requirement since OData services need an etag in order to be able to achieve optimistic locking.

After having generated the RAP BO you can try to remove the specifiction of an etag in the behavior definition.