Search

    Choose Your Preferred Tools

    Use CAP with the development tool of your choice.

    SAP Business Application Studio

    For the trial accounts, SAP Business Application Studio is only available on Amazon Web Services (AWS) - Frankfurt and US East (VA) regions.

    Learn more about using SAP Business Application Studio with a Trial account.

    For productive accounts SAP Business Application Studio is available in AWS and Azure regions.

    Learn more about using SAP Business Application Studio with a productive account.

    Log on to SAP BTP Cockpit

    1. Open the SAP BTP cockpit.

      If you are not subscribed to SAP Business Application Studio service, follow the onboarding tutorial.

    2. Choose SAP Business Application Studio from the Quick Tool Access section on the welcome page to SAP BTP Trial to access the service.

    Set Up Your Dev Space

    1. Choose Create Dev Space.

    2. Provide a name for your dev space.

    3. 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, CDS tools, Java Tools, and MTA Tools are built in. This saves setup time. See Developer Guide for SAP Business Application Studio for more details.

    4. 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 Managing Your Dev Spaces for more details.

    5. Once the dev space is running, choose the dev space by clicking on the dev space name.

      You’re using a trial version. Any dev space that hasn’t been running for 30 days will be deleted. See the full list of restrictions.

    Features in App Studio

    Starting a New Project from Template

    1. From the start page, select Start from template.

      This starts the project wizard in a new tab.

    2. Select the template CAP Project and choose Start.

    3. Enter your project name and choose Finish.

      You can add features now or later to your project.

    4. Choose your project to open your application in a new workspace and start working.

    Running the Service

    1. Open the Run Configurations view from the activity bar.

    2. Select Create Configuration, the small [+] at the top of the RUN CONFIGURATIONS view.

    3. Select your project from the command palette.

      Once your application is running, the Debug view and Debug Console open. If you’re prompted to expose a port, do that and open the application afterwards.

    See SAP Business Application Studio documentation for more details, like creating run configurations for CAP applications.

    Using the SQL Tools

    1. Open the SQLTools view from the activity bar.

      If you’ve bound the service in your run configuration, the connection is already established.

    2. Select Add New Connection, the small database symbol at the top of the CONNECTIONS view.

    3. Select your database, for example, SQLite (Node Native).

    4. Enter a name for the connection.

    5. Enter the path to your database file, for example sqlite.db, and choose SAVE CONNECTION.

      If you’re prompted to install SQLite, just confirm. Then your connection works.

    Using the REST Client

    1. Create an *.http file in your project, for example, test.http.

      In the samples bookshop application, go to test/request.http. You can use this request together with a running bookshop application.

    2. Add a request to this file, for example:
        GET http://localhost:4004/browse/Books?
      
    3. Choose Send Request in the test.http file. You can see the response side by side in editor groups.

    Restarting the Server

    Restart the server when you did changes to your code using the Debug view restart button.

    Troubleshooting

    You can find solutions for common troubleshooting issues in SAP Business Application Studio in the Guided Answers.

    Tutorials Using SAP Business Application Studio

    Visual Studio Code

    Install Visual Studio Code

    1. Install Visual Studio Code and launch it.
    2. Only for macOS: Install the code shell command.

    Add CDS Editor

    1. Go to Visual Studio Marketplace.
    2. Choose Install and VS Code opens the details page for the extension SAP CDS language support.
    3. In VS Code, choose Install to enable the extension.

    Learn more about the CDS Editor.

    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:

    Eclipse

    Prerequisites

    Docker

    Prerequisites

    Build an Image

    Create a file called Dockerfile and add this content for a quick setup:

    FROM node:lts-alpine
    # or use `FROM node:12.18.1` for example to match a specific Node
    # version you have installed locally
    
    RUN apk add python
    
    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 .
    

    If you experience issues building that image, replace the first line FROM node:lts-alpine with FROM node:12.18.1-alpine3.10 as this version has been successfully tested.

    Run a Service in a Container

    1. Run a container that is based on the image:
      docker run --publish 4004:4004 -it cds sh
      

      You see a $ command prompt from inside the container.

    2. Move to the home directory:
      cd
      
    3. Write a simple cds file:
      echo 'service CatalogService { entity Books { key ID: UUID; } }' \
       > services.cds
      
    4. Run the service:
      cds run
      
    5. 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.

    CDS Editor

    The editor powered by the CDS language server implementation, provides source code validation including diagnostics, like error messages and warnings.

    The following features are available for all editors based on our language server implementation for CDS in SAP Business Application Studio, Visual Studio Code, and Eclipse. The plugins are available for download for Visual Studio Code at Visual Studio Marketplace and for Eclipse at SAP Development Tools.

    Short video about 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

    QuickFixes

    • 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 and Eclipse
      • 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 for typical CDS language constructs

    • 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 based on

    • Doc comments
    • @title, @description, and @cds.doc (deprecated) annotations
    • 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:

    1. Press F1
    2. Open Preferences: Open User Settings
    3. Filter for Format.
    4. Tick the checkboxes to enable the settings.

    Cds: Workspace Validation Mode

    Default: OpenEditorsOnly

    If switched to OpenEditorsAndDirectSources all model files on every change, for example typed character, are recompiled. For large models this can lead to high CPU and memory load and weak 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

    1. Press F1
    2. 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 (cds.releaseNotes.showAutomatically) setting.

    Beautify settings

    1. Press F1
    2. 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:

    1. Open the file you want to preview.
    2. Open the context menu.
    3. Select Preview CDS source as… .
    4. Choose the preview you want to see.

    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.

    In addition, here are some 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 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 i.e. 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.

    Jupyter Notebooks

    You have the option to add a CAP Jupyter Notebook to your project.

    A CAP Jupyter Notebook is a Jupyter Notebook 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.

    Initiate a new project, for example Bookshop, with the --add notebook option:

    cds init Bookshop --add notebook
    

    Use cds add to add it to an already existing project by navigating to that directory and running:

    cds add notebook
    

    This scrapes the content from the documentation Getting started in a nutshell and converts it to a Jupyter Notebook. This conversion makes the code cells interactive such that you can execute them on your local machine. In Visual Studio Code, you can open, execute, and interact with the CAP Jupyter Notebook as shown below:

    Opening and interacting with a CAP Jupyter Notebook in Visual Studio Code

    Debugging with cds watch

    Start cds watch and enter debug. This restarts the application in debug mode. Similarly, debug-brk will start debug mode, but pause the application at the first line, so that you can debug bootstrap code.

    If you do this in VS Code’s integrated terminal with the ‘Auto Attach’ feature enabled, debugging starts right away: Debug with cds watch

    If you executed cds watch on a standalone terminal, you can still attach a Node.js debugger to the process.

    For example:

    • In VS Code, use the Debug: Attach to Node Process command.
    • In Chrome browser, just open chrome://inspect and click Inspect.
    Show/Hide Beta Features