CDS Editors and IDEs
SAP Business Application Studio
SAP Business Application Studio offers a modern development environment tailored for efficient development of business applications for the SAP Intelligent Enterprise.
Setup in BTP
If not already done, set up SAP Business Application Studio on SAP BTP.
Set Up a Dev Space
Open the SAP BTP cockpit and choose SAP Business Application Studio from the Quick Tool Access section.
Choose Create Dev Space.
Provide a name for your dev space.
Choose Full Stack Cloud Application as the application type.
By selecting Full Stack Cloud Application, your dev space comes with several extensions out of the box that you need to develop CAP applications. For example, CAP Tools, Java Tools, and MTA Tools are built in to save setup time. See Developer Guide for SAP Business Application Studio for more details.
Choose Create Dev Space.
The creation of the dev space takes a while. You see that the status for your dev space changes from STARTING to RUNNING. See Dev Space Types for more details.
Once the dev space is running, choose the dev space by clicking on the dev space name.
In the trial version, any dev space that hasn't been running for 30 days will be deleted. See the full list of restrictions.
See Developing a CAP Application in SAP Business Application Studio
Tutorials
Combine CAP with SAP HANA Cloud to Create Full-Stack Applications
Video showing SAP Business Application Studio Productivity Tools
Visual Studio Code
Install Visual Studio Code
- Install Visual Studio Code and launch it.
- Only for macOS: Install the
code
shell command.
Add CDS Editor
- Go to Visual Studio Marketplace.
- Choose Install and VS Code opens the details page for the extension SAP CDS language support.
- In VS Code, choose Install to enable the extension.
Run Services
To run services, just open the Integrated Terminal in VS Code and use one of the cds serve
variants, for example, use cds watch
to automatically react on changes.
Alternatively, you can use the preconfigured tasks or launch configurations you get when creating a project with cds init
. For example, in the Debug view launch cds run with the green arrow button:
Debug Services
You can add and stop at breakpoints in your service implementations. For example, add one to line 10 of our srv/cat-service.js by clicking in the gutter as shown here:
... then send the .../Books request again to stop there.
Restart the Server
Restart the server when you did changes to your code using the Debug views restart button:
IntelliJ
The CAP CDS Language Support plugin for IntelliJ IDEs provides syntax highlighting, code completion, formatting, and more. It supports commercial IntelliJ IDEs including IntelliJ IDEA Ultimate and WebStorm.
See the detailed feature list and the installation instructions for how to get started.
Report issues and provide feedback.
CDS Editors & LSP
Using the CDS language server implementation, editors can provide additional source code validation and Intellisense for .cds files.
Watch the SAP CDS language support extension for VS Code in action by DJ Adams.
Features and Functions
Syntax Highlighting
Code Completion
- Keywords
- Identifiers including not yet imported identifiers with corresponding
using
statement - Using paths and artifacts including showing README.md documentation as details
- i18n translation IDs
- Turn on/off formatting regions
Where-used Navigation
- Navigate to definitions
- Navigate to references
- Highlight occurrences
Quick Fixes
- Create using statement for unknown artifacts.
- Maintain missing translation.
- Convert
@cds.doc
and@description
annotations to doc comments.
Code Formatting
Format...
- the whole document
- a selected range
- on-the-fly when completing statements using
;
or}
- on save (depending on the IDE)
- on paste (depending on the IDE)
Use...
- many options, configurable using
- settings file
- command line switches
- config UI with simulation of options for VS Code
- JSON schema for textual support
- also for markdown in doc comments
Inventory (symbols)
- An inventory for the current file.
- An inventory for the workspace including query capabilities to select. For example, artifact types, names, also include reuse models.
Snippets
- Namespace and context
using
service
type
- Entity and projections, ...
- Element, associations, and compositions
- Extend and annotate
- Annotations for documentation
With documentation extracts of capire explaining language concepts.
Hover Information
- Doc comments
@title
,@description
, and(deprecated) annotations@cds.doc
- Translations
Translation Support
- Properties, JSON, and CSV files
- Navigate to translation definitions from translation IDs like
'{i18n>customerName}'
. - Show translations on hover.
- Quickfix to maintain missing translations
And More…
- Plugin framework for external handlers of annotation domains
Settings
Code formatting settings
These are settings coming with the CDS language server implementation. Use the command CDS: Show Formatting Options Configuration. You see the settings, grouped into three tabs: Alignment, Other, and Whitespace
Format on Type, Format on Paste, and Format on Save in VS Code
These are settings from the editor in VS Code:
- Press F1
- Open Preferences: Open User Settings
- Filter for Format.
- Tick the checkboxes to enable the settings.
Cds: Workspace Validation Mode
Default: ActiveEditorOnly
Keeps track of the active editor in focus. Only changes there are immediately validated.
The ActiveEditorOnly mode is especially useful in situations when navigating through a large model, that is, having multiple files open (even if they are not shown as tabs) and editing a file that the others directly or indirectly depend on.
Large models can lead to high CPU and memory load
If switched to OpenEditorsAndDirectSources, all model files on every change, for example typed character, are recompiled.
If switched to OpenEditorsOnly, all open files, for example split tabs, are recompiled.
The high resource consumption might impact the editor's responsiveness.
Cds > Contributions > Enablement: Odata
Default: on
This setting enables extended support for annotations, that is, refined diagnostics and code completion. Can be switched off for performance gains.
Cds > Workspace: ScanCsn
Default: off
Switch on to scan the workspace also for CSN files, additionally to CDS source files.
Note: CSN files are still considered if used from a CDS source file.
Cds > Quickfix: ImportArtifact
Default: off
Enable to get quickfix proposals for artifact names, like entities, that aren't imported via a using
statement. For that, all definitions in the workspace need to be considered, which might be slow.
Commands
Welcome page
- Press F1
- Open CDS: Show CAP Release Notes
If there are new release notes, this page opens on startup. You can disable this behavior using the Cds > Release Notes: Show Automatically setting.
CAP Notebooks Page
- Press F1
- Open CDS: Open CAP Notebooks Page
This page provides information on all of features available in a CAP Notebook with a brief description and examples on each.
Beautify settings
- Press F1
- Open CDS: Show Formatting Options Configuration
Preview CDS sources
You want to create a preview of a specific .cds file in your project. You can do that using the command line. Here is how you do it in VS Code:
- Open the file you want to preview.
- Open the context menu.
- Select Preview CDS source as... .
- Choose the preview you want to see.
Visualize CDS file dependencies
Use the command from the context menu on a folder or CDS file.
A selection popup appears to choose one of three modes:
- File to file (detailed)
- File to file (reduced to folders)
- Complete folder to complete folder
The first option shows every model file on its own. For very large models, the number of files and interdependencies may be too complex to be graphically shown. A message about insufficient memory will appear. In this case use the second option.
The second option reduces the graph by only showing the folders of all involved files and their interdependencies.
TIP
Only those files are evaluated that are reachable from the start model where the command was invoked on.
The third option always considers all files in a folder and their dependencies. This can be useful to understand architectural violations.
Example for architectural violation:
You want a clean layering in your project: app -> srv -> db. With this option, you can visualize and identify that there is a dependency from a file in the service layer to an annotation file in the application layer.
Hovering over a node will show the number of files involved and the combined size of all involved files. Use this function to get a rough understanding about the complexity and the compilation speed.
The command requires the third-party extension Graphviz (dot) language support for Visual Studio Code (joaompinto.vscode-graphviz). If you haven't installed it already, it will be suggested to install.
Editor Performance
With the following settings you can influence the performance of the editor:
Editor > Goto Location: Alternative Definition Command
Do not select goToReferences. Otherwise, being already on a definition often requires all models to be recompiled.
Workbench > Editor > Limit: Value
If open editors have using
dependencies, a change in one editor will lead to a recompile of related editors. To decrease the impact on performance, lower the number.
Workbench > Editor > Limit: Enabled
To enable the limit value above, switch on.
Additional Hints to Increase Performance:
- Within SAP Business Application Studio: close CAP Data Models and Services view. Otherwise, it will ask for all workspace symbols at every change.
- Commands Go to References / Find All References will recompile all models that might have changed due to a change in a depending model. If there are index models, it often means that the complete workspace is being recompiled. Until a further change, reference calculation is reasonably fast.
- Command Go to Symbol in Workspace will recompile the complete workspace once, after that it is reasonable fast.
- Changing settings in CDS section will currently perform a complete workspace invalidation, that is, required indexes will lead to recompilations on demand as described above.
- Changing certain
cds.env
settings, for example folder configurations, will invalidate the workspace as well.
CDS Source Formatter beta
The CDS code formatter provides a command line interface. Use it as a pre-commit hook or within your CI/CD pipeline, to guarantee a consistent formatting.
Installation
Install the CDS language server globally as a library via npm i -g @sap/cds-lsp
. A new shell command format-cds
is available.
Usage
Show help via format-cds -h
. This explains all commands and formatting options in detail including the default value for each formatting option.
It is recommended to generate once for each project a settings file (.cdsprettier.json) with all default formatting options available. Execute format-cds --init
in the project root. An existing file would not be overwritten. To adapt your settings to your preferred style, open the .cdsprettier.json file in VS Code. You get code completion and help for each option. There is also a settings UI in SAP CDS Language Support, reachable via command CDS: Show Formatting Options Configuration
. This allows to see the effects of each formatting option on an editable sample source. Commit the .cdsprettier.json file into your version control system.
Use format-cds
to format all your CDS source files. The effective set of formatting options is calculated in order of precedence:
- Default options
- Options from .cdsprettier.json file
- Command line formatting options
It is possible to have .cdsprettier.json files in subfolders. In this case the most relevant settings file per CDS source file is taken.
Use format-cds <foldername1> <foldername2> <filename> ...
to restrict the set of CDS source files. By default, backup files with .bak file extension will be created.
Use -f
switch to force an overwrite without creating a backup. This is on your own risk. Should there be problems data loss might occur, especially when formatting in a pre-commit hook. Better add .bak to your .gitignore file and not use -f
.
CAP Notebooks
A CAP Notebook is a Custom Notebook in Visual Studio Code that serves you as a guide on how to create, navigate, and monitor CAP projects. With this approach, we want to encourage the CAP community to work with CAP in the same explorative manner that scientists work with their data, namely by:
- Visually interacting with their code
- Playing with REPL-type inputs (notebook input cells)
- Storing persistent code (notebook output cells)
The cell inputs/outputs are especially useful at later points in time when the project's details have long been forgotten. In addition, notebooks are a good way to share, compare, and also reproduce projects.
If you are new to CAP Notebooks, try out the notebooks based on our documentation. When available for a given page, these are accessible via the "Download Notebook" button on the top of the screen and enable you to try things out on your local machine, for example the Getting Started in a Nutshell guide.
To see which features are available in a CAP Notebook, open our CAP Notebook page: F1 → CDS: Open CAP Notebooks Page
Magics, or magic commands, known from IPython are convenient functions to solve common problems. To see which line- and cell-magics can be used within a CAP Notebook, run a code cell with
%quickref
.Start an empty CAP Notebook by creating a *.capnb file.
Provided that the CDS Editor is installed, the CAP Notebook will be rendered automatically as the file is selected.
Using Docker
Prerequisite: You have installed Docker.
Build an Image
Create a file called Dockerfile
and add this content for a quick setup:
FROM node:lts
# or use `FROM node:<NODEVERSION>` to match a specific Node version
# you have installed locally
USER node
ENV NPM_CONFIG_PREFIX=/home/node/.npm
ENV PATH=$NPM_CONFIG_PREFIX/bin:$PATH
RUN npm i -g @sap/cds-dk
Build your first image:
docker build -t cds .
Run a Service in a Container
Run a container that is based on the image:
shdocker run --publish 4004:4004 -it cds sh
You see a
$
command prompt from inside the container.Move to the home directory:
shcd
Write a simple cds file:
shecho 'service CatalogService { entity Books { key ID: UUID; } }' \ > services.cds
Run the service:
shcds run
Open http://localhost:4004 in a browser to test the application. You forwarded the port
4004
when running the container, which allows you to access the application as if it would run locally.