SAP Cloud Application Programming Model Getting Started (CAP): Unterschied zwischen den Versionen

Aus MattWiki
(13 dazwischenliegende Versionen desselben Benutzers werden nicht angezeigt)
Zeile 1: Zeile 1:
This article describes how to build Cloud Application Programming Model projects (CAP projects) and according artefacts with Core Data Services (CDS).
This article describes how to get started with building Cloud Application Programming Model (CAP) projects and according artefacts with Core Data Services (CDS).
 
Source: ABAP Freak Show Ep. 1 - HANA Cloud and the Business Application Studio
 
https://www.youtube.com/watch?v=a3WPQwmpbvI&list=PLoc6uc3ML1JR38-V46qhmGIKG07nXwO6X&index=71


For local native development see [[SAP HANA Local Native Development]]
For local native development see [[SAP HANA Local Native Development]]


All-in-one Quick Start: https://github.com/SAP-samples/cloud-cap-walkthroughs/blob/master/exercises-node/intro/README.md
== Sources and Further Reading ==
 
{| class="wikitable"
More Repositories: https://github.com/SAP-samples/cloud-cap-samples --> Use opensap*-Branches
|+
!Description
!URL
!Comment
|-
|All-in-one Quick Start
|https://github.com/SAP-samples/cloud-cap-walkthroughs/blob/master/exercises-node/intro/README.md
|
|-
|SAP CAP Sample Repositories
|https://github.com/SAP-samples/cloud-cap-samples
|Use opensap*-Branches
|-
|ABAP Freak Show Ep. 1 - HANA Cloud and the Business Application Studio
|https://www.youtube.com/watch?v=a3WPQwmpbvI&list=PLoc6uc3ML1JR38-V46qhmGIKG07nXwO6X&index=71
|
|}


== Installation of Prerequisites==
== Installation of Prerequisites==
Zeile 48: Zeile 60:
Deploy data model to different database types:
Deploy data model to different database types:


cds deploy
This deploys the cds entity models and csv files to the database specified in package.json in section ''cds.requires.db''. This should look like this:<syntaxhighlight lang="json" line="1">
{ "cds":
    { "requires": {
      "db": {
          "kind": "sqlite",
        "credentials": { "url": "db.sqlite" }
            }
        }
    }
}
</syntaxhighlight>For more explainations see for SQLite see https://cap.cloud.sap/docs/guides/databases-sqlite
  cds deploy --to sqlite          # Deploys to sqlite.db
  cds deploy --to sqlite          # Deploys to sqlite.db
  cds deploy --to sqlite:my.db    # Deploys to my.db
  cds deploy --to sqlite:my.db    # Deploys to my.db
Zeile 53: Zeile 77:
                                 # (Requires Cloud Foundry login)     
                                 # (Requires Cloud Foundry login)     


This also updates the ''package.json'' secion ''cds.requires.db''.
This does not update the ''package.json'' secion ''cds.requires.db'' any more as opposed to older cds versions.


In order to see the actual created SQL statements:
In order to see the actual created SQL statements:
Zeile 63: Zeile 87:


  sqlite3 my.db -cmd .dump
  sqlite3 my.db -cmd .dump
Create CSV header files in db location (by default db/data) for modeled entities:
cds add data


== Deployment to SAP Business Technology Platform (BTP) ==
== Deployment to SAP Business Technology Platform (BTP) ==
Zeile 107: Zeile 133:


  cds build/all
  cds build/all
cds build --production        # Only production profile?


Create a hana service for the hdi-container. The stated hdi-container name must correlate to the services-name in ''/gen/db/src/manifest.yaml''.
Create a hana service for the hdi-container. The stated hdi-container name must correlate to the services-name in ''/gen/db/src/manifest.yaml''.
Zeile 138: Zeile 165:
  cf logs <appname>
  cf logs <appname>


== CDS Commands Cheatsheet ==
=== Noteworthy Commands ===
{| class="wikitable"
|+
!Command
!Description
|-
|cds env
|Displays the effective configuration...
|-
|cds env ls
|... in .properties format
|-
|cds compile services.cds
|Compile JSON-like database structure
|-
|<nowiki>cds compile services.cds | jq</nowiki>
|dto, but in actual JSON
|-
|cds compile services.cds --to sql
|Compile SQL statements from CDS
|-
|cds compile services.cds --to edmx
|Compile EDMX file (metadata) from CDS
|-
|cds compile services.cds --to csn
|Output CSN = Internal CDS Schema Notation...
|-
|<nowiki>cds compile services.cds --to csn | jq '.definitions | keys'</nowiki>
|... and process output with JSON processor by extracting keys of definition nodes
|-
|cds add data
|Create CSV header files in db location (by default db/data) for modeled entities
|}
=== Using CDS REPL & JavaScript APIs ===
cds r
cds repl
This launches an read-eval-print-loop which can be used as an interactive playground to experiment with CDS' JavaScript APIs.
{| class="wikitable"
|+
!API
!Description
|-
|cds.utils.uuid()
|Returns an UUID
|}
[[Category:SAP]]
[[Category:SAP]]
[[Category:HANA]]
[[Category:HANA]]
[[Kategorie:JavaScript]]

Version vom 13. April 2024, 12:11 Uhr

This article describes how to get started with building Cloud Application Programming Model (CAP) projects and according artefacts with Core Data Services (CDS).

For local native development see SAP HANA Local Native Development

Sources and Further Reading

Description URL Comment
All-in-one Quick Start https://github.com/SAP-samples/cloud-cap-walkthroughs/blob/master/exercises-node/intro/README.md
SAP CAP Sample Repositories https://github.com/SAP-samples/cloud-cap-samples Use opensap*-Branches
ABAP Freak Show Ep. 1 - HANA Cloud and the Business Application Studio https://www.youtube.com/watch?v=a3WPQwmpbvI&list=PLoc6uc3ML1JR38-V46qhmGIKG07nXwO6X&index=71

Installation of Prerequisites

Relevant Tools from SAP

npm i -g @sap/cds
npm i -g @sap/cds-dk

Additional 3rd Party Tools1

npm i -g hana-cli

Create CDS Project

cds init bookshop

or

cds init MyCDSProject --add hana, mta

Download and install dependencies:

npm install

Start Service

cds watch

This also monitors changes to the underlying files and restarts when a file has changed.

Add Persistency to CDS

In case of SQLite first install SQLite3 packages by executing in the root of the project folder:

npm i sqlite3 -D

Deploy data model to different database types:

cds deploy

This deploys the cds entity models and csv files to the database specified in package.json in section cds.requires.db. This should look like this:

{ "cds": 
    { "requires": {
       "db": {
          "kind": "sqlite",
        "credentials": { "url": "db.sqlite" } 
            }
        }
    }
}

For more explainations see for SQLite see https://cap.cloud.sap/docs/guides/databases-sqlite

cds deploy --to sqlite          # Deploys to sqlite.db
cds deploy --to sqlite:my.db    # Deploys to my.db
cds deploy --to hana            # Deploys to HDI container on HANA
                                # (Requires Cloud Foundry login)    

This does not update the package.json secion cds.requires.db any more as opposed to older cds versions.

In order to see the actual created SQL statements:

cds compile srv/cat-service.cds --to sql     # Creates SQL statements
cds compile srv/cat-service.cds --to hana    # Creates hdbcds or hdbtable/hdbview artefacts

When deployed to SQLite database use this statement to view the database:

sqlite3 my.db -cmd .dump

Create CSV header files in db location (by default db/data) for modeled entities:

cds add data

Deployment to SAP Business Technology Platform (BTP)

Login to CF space:

cf login

Build Deployment Package

cds add hana

package.json needs to contain "kind": "hana". (really? - for which CF / HANA Cloud Version?)

Also when deploying to BTP which is internally HANA 4.0 "deploy-format": "hdbtable" has to be set and hdi-deploy should be at least version 4. Example:

{
    ...
    "devDependencies": {
        "@sap/hdi-deploy": "^4"
    },
    ...
    "cds": {
        "hana": {
            "deploy-format": "hdbtable"
        },
        "requires": {
            "db": {
                "model": [
                    "db",
                    "srv"
                ],
                "kind": "hana"
            }
        }
    }
}

Deploy via Cloud Foundry CLI

Build the deployment artifacts:

cds build/all
cds build --production         # Only production profile?

Create a hana service for the hdi-container. The stated hdi-container name must correlate to the services-name in /gen/db/src/manifest.yaml.

cf create-service hana hdi-shared <app-db-hdi-container>

Now push the DB deployer application and also the actual service application:

cf push -f gen/db
cf push -f gen/srv --random-route

Deploy via MTA

Install MTA Build Tool

npm install -g mbt

Generate MTA project descriptor file mta.yaml and build MTA archive:

cds add mta
mbt build

Deploy MTA archive to CF space:

cf deploy mta_archives/<buildmta>.mtar

Troubleshooting

Real-time output of CF services can be displayed in BAS terminal with

cf logs <appname>

CDS Commands Cheatsheet

Noteworthy Commands

Command Description
cds env Displays the effective configuration...
cds env ls ... in .properties format
cds compile services.cds Compile JSON-like database structure
cds compile services.cds | jq dto, but in actual JSON
cds compile services.cds --to sql Compile SQL statements from CDS
cds compile services.cds --to edmx Compile EDMX file (metadata) from CDS
cds compile services.cds --to csn Output CSN = Internal CDS Schema Notation...
cds compile services.cds --to csn | jq '.definitions | keys' ... and process output with JSON processor by extracting keys of definition nodes
cds add data Create CSV header files in db location (by default db/data) for modeled entities

Using CDS REPL & JavaScript APIs

cds r
cds repl

This launches an read-eval-print-loop which can be used as an interactive playground to experiment with CDS' JavaScript APIs.

API Description
cds.utils.uuid() Returns an UUID