Developing CAP applications in SAP Business Application Studio
SAP Business Application Studio (BAS) is the evolution of SAP Web IDE. It is a modular development environment, built on ‘Eclipse Theia’, an open source IDE that embraces the VS Code experience. BAS simplifies onboarding and integration with SAP services and offers pre-configured containers, optimized for maximizing time-to-value when developing business applications. This includes specialized editors, productivity tools, run-time tools, know-how and a vivid community.
You are invited to read more about the value of BAS in this blog.
In my blog, I’ll give a high-level overview of how to develop a business application based on SAP Cloud Programming model (aka CAP) in BAS. In each step, I’ll also highlight the differences between the development experience in BAS vs. SAP Web IDE.If you’ve developed applications with CAP using SAP Web IDE Full-Stack, then I’m sure you’ll be delighted to learn of the exciting new capabilities in BAS, which allow much more flexibility than you used to have.
Let’s go over the end-to-end development process of CAP applications and see how it is different and better when using BAS.
Step 1: Environment Setup
SAP Web IDE includes a set of tools that are required to develop a CAP application. To start developing an application, you need to enter the IDE’s workspace and can immediately start working. The disadvantage in SAP Web IDE is that it included not only the CAP set of tools, but also additional ones which could lead to an overloaded workspace.
BAS introduces the concept of dev spaces. A dev space is a preconfigured environment with the required tools and extensions tailored for a specific business scenario. Before developing any application, you should create a dev space that is suitable to your development scenario. In our case, we’ll need to create a dev space for developing applications of type “SAP Cloud Business Application”.
There are a couple of advantages for using a dev space. First, it contains only a pre-defined set of tools required to develop CAP applications, so your environment is cleaner, faster, and easier to use. Second, you have the freedom to install your own tools to configure your dev space as you please, providing a local-like development experience.
Step 2: Creating an application
In SAP Web IDE, you can either import an existing application using Import or ‘Git clone’, or you can create a new application using the ‘New project from template’ wizard.
BAS supports all the above options, but it gives you the flexibility to create a new application using the CDS CLI as well. For developers who are used to working in a local environment, this may seem trivial, but since SAP Web IDE did not offer a terminal and support for CLI, this is a major improvement. Now, developers who prefer to work with the CDS CLI can do so. 🙂
By the way, since the ’New Project From Template’ tool in BAS uses Yeoman generators (a Yeoman generator is a CLI generator that helps you create an application scaffolding based on the answers you provide to a predefined series of questions), it is also possible to create a new project from template by running the Yeoman generator in the terminal. Just type ‘yo’ in the terminal and look for the option to create a CAP project.
BAS supports the creation of CAP Node.js applications as well as CAP Java applications. If you look at the applications created in BAS vs. SAP Web IDE, you will see some differences:
- Applications that are created in SAP Web IDE are always created with an ‘mta.yaml’ file, whereas in BAS, it is optional to create the application with it. The ‘mta.yaml’ file should be added by the developer when it is required. This change in behavior reflects grow as you go, one of the best practices of CAP.
- CAP Java applications created in BAS are Springboot applications, and their structure is different than the CAP Java applications created in SAP Web IDE. (To understand more about this conceptual change, see the CAP documentation.)
Step 3: Develop the application
The next step after creating an application is to pour some content into it. BAS offers much more than SAP Web IDE to help you write your code and improve your productivity. I already mentioned the terminal, but this is just the beginning….
One of the main use cases when developing CAP applications is importing a data model from an external resource. The BAS “Consume SAP Services” tool allows you to explore different services from various sources and consume them in your application. This is similar to the “new data model from external service” feature in SAP Web IDE. The “Consume SAP Services” tool is currently available via the command palette. Learn more about the IDE basic capabilities such as the command palette here
A couple of additional tools dedicated for the development of business applications are the CDS editor and the CAP Project Explorer, that provides a logical view of your application. These may look familiar if you’ve been developing in SAP Web IDE.
You can read more on BAS productivity tools here.
Step 4: Develop the application’s front-end
Use the Fiori freestyle OData V4 templates to create a UI on top of a CAP service. To edit the UI, you can use a code editor or the layout editor, which you may be familiar with from SAP Web IDE.
In the near future we hope to have out-of-the-box support for Fiori Elements as well.
Step 5: Testing and running the application
The most significant difference between SAP Web IDE and BAS in the end-to-end development of CAP applications is in the Test and Run step.
SAP Web IDE supports running the application modules remotely only. This means that the application’s database and service had to be deployed to Cloud Foundry and tested on Cloud Foundry, which is of course not ideal from the development productivity aspect. Furthermore, the only database supported by SAP Web IDE is SAP HANA.
Another important difference is that in SAP Web IDE, the logic required to run an application was implemented behind the scenes, so we saved the developer a lot of time on the one hand, but on the other hand, what was happening wasn’t always clear. In BAS we still automate some of the actions for the developer, but the developer has full control and visibility when running the application.
The Run Configurations tool in BAS is where you create and manage the run configurations of all your applications. The tool helps the developers configure how to run the application quickly and simply. Here are a few of the configuration options (these options are currently available for CAP node.js applications):
- Manage the dependencies of the application by choosing the remote services with which it will run.
- Choose an SAP HANA instance with which to run the application, and deploy your data-model to the selected instance.
- Choose to mock external OData services your application consumes.
With the Run Configurations tool, you can create different configurations to test your application. For example, you can create a configuration to test your application locally, with a local database and mocked services, and another configuration to test your application as it will run on Cloud Foundry, in which all your dependencies are bound to remote services.
To run the application, you only need to press on the run button of the run configuration. Fast and simple. When you ran it in SAP Web IDE, you had to run each module separately which was much more tedious.(Note that to run a CAP Java application that is not based on Springboot you’d need to run each module separately.)
A couple of additional tools for testing your application are the integrated REST client and the SQLTools view. The REST client has a simple interface and since it is used from within BAS, it spares you from having to handle security when sending requests. The SQLTools presents the data from the views and tables of the application’s data model and supports both sqlite and SAP HANA.
Step 6: Deploying the application
Once you’ve completed the application development and testing, you are ready to deploy.
Deploying the application from BAS is basically the same as in SAP Web IDE. You build your application into an MTAR file and deploy it. Both these actions are done using the MBT Tool and are available in the file explorer view via the context menu on the `mta.yaml` file.
As I mentioned before, CAP applications created in SAP Web IDE always contain an ‘mta.yaml’ file, while the applications created in BAS may not. If you had no need to create an ‘mta.yaml’ file before, you will need to create it now. Once the ‘mta.yaml’ file is available, you can continue to create the MTAR file and then deploy the application.
And… You’re done! 🙂
To try BAS and CAP yourself, checkout the following resources:
- SAP Business Application Studio Info blog
- Build a Business Application Using CAP for Java
- Building Applications with SAP Cloud Application Programming Model
To learn about migrating your CAP applications from SAP Web IDE to BAS, read this blog.
I hope you enjoyed this blog and happy coding!