Managing Modeling Objects via the Command Line

You can use the datasphere command line interface to list, read, create, update, and delete modeling objects. You can also organize objects in folders and manage sharing and metadata translation from the command line.

Prerequisites

To work with modeling objects on the command line, you must have a scoped role that grants you access to a space with the following privileges:
  • Data Warehouse General (-R------) - To access SAP Datasphere.

  • Space Files (CRUD----) - To create, read, update, and delete objects in your spaces.

  • Data Warehouse Data Builder (CRUD--S-) - To create, edit and delete Data Builder objects.

  • Data Warehouse Data Access Control (CRUD----) - To create, edit and delete these objects.

  • Data Warehouse Business Builder (CRUD----) - To create, edit and delete Business Builder objects.

  • Data Warehouse Business Entity (CRUD----) - To create, edit and delete these objects.

  • Data Warehouse Fact Model (CRUD----) - To create, edit and delete these objects.

  • Data Warehouse Consumption Model (CRUD----) - To create, edit and delete these objects.

  • Data Warehouse Authorization Scenario (CRUD----) - To create, edit and delete these objects.

The DW Modeler scoped role template, for example, grants these privileges.For more information, see Privileges and Permissions and Standard Roles Delivered with SAP Datasphere.
You must, in addition: To browse the available commands, enter the following and press Return:
datasphere objects <object-type>
The following object types are available:

Object Type

Object Documentation

remote-tables

Importing Tables and Views from Sources

local-tables

Creating a Local Table

views

Creating a Graphical View

Creating an SQL View

intelligent-lookups

Creating an Intelligent Lookup

er-models

Creating an Entity-Relationship Model

types

contexts

These objects cannot be created manually in SAP Datasphere, but may be imported as necessary along with remote tables or content packages.

data-flows

Creating a Data Flow

replication-flows

Creating a Replication Flow

transformation-flows

Creating a Transformation Flow

task-chains

Creating a Task Chain

analytic-models

Creating an Analytic Model

business-entities

Creating a Business Entity

fact-models

Creating a Fact Model

consumption-models

Creating a Consumption Model

data-access-controls

Securing Data with Data Access Controls

folders

Organizing Objects in Folders

packages

Creating Packages to Export

List Objects in a Space

You can list all the objects of a particular type in a space and optionally write the output to a file.

Enter the following command and press Return:
datasphere objects <object-type> list 
    --space <id>
    [--technical-names <name>[,...]]
    [--output <file>.json]
    [--select "<property[,...]>"]
    [--filter "<property operator value>[ and|or ...]"]
    [--top <n>]
    [--skip <n>]
Complete the parameters as follows:

Parameter

Description

--space <id>

Enter the Space ID of the space.

--technical-names <name>[,...]

[optional] Specify the objects to include in your list by technical name, separated by commas.

--output <file>.json

[optional] Enter a path to a .json file to write the output to.

If you do not include this option, the output will be printed to the command line.

--select "<property>[,...]"

[optional] Specify the properties to include in your list, separated by commas, from among the following:

  • technicalName

  • businessName

  • type

  • semanticUsage

  • status

  • createdOn

  • changedOn

  • deployedOn

  • createdBy

  • changedBy

  • defaultFileName - The .json filename is calculated by combining the technicalName and the type and has a maximum length of 250 characters.

Default: technicalName

--filter "<property operator value>[ and|or ...]"

[optional] Specify a filter condition using the standard OData filter syntax. You can use the following comparison operators:

  • eq - Equal to

  • ne - Not equal to

  • gt - Greater than

  • lt - Less than

  • ge - Greater than or equal to

  • le - Less than or equal to

Dates must be entered in the format 'YYYY-MM-DD'.

You can combine filter conditions using the and and or keywords and control priority by grouping conditions with parentheses.

For example, to list only objects that were deployed after 31 December 2022, and have a semantic usage of Fact or Dimension, enter
--filter "deployedOn gt '2022-12-31' and (semanticUsage eq Fact or semanticUsage eq Dimension)"

--top <n>

[optional] List only the first <n> objects, up to a maximum of 200.

Default: 25

--skip <n>

[optional] Skip the first <n> objects.

For example, to list all the views in space MySpace showing their technical and business names as well as their semantic usage and status and write them to a file, enter:
datasphere objects views list --space MySpace --select "technicalName,businessName,semanticUsage,status" --output MySpaceViews.json
You can filter lists on the following properties:

Property

Description

technicalName

businessName

Enter an object name. You must use single or double quotes if the name contains spaces.

For example, to list only the objects with technical name Table_1 and Table_2, enter:
--filter "technicalName eq Table_1 or technicalName eq Table_2"

type

Enter a valid object type:

  • LocalTable

  • RemoteTable

  • View

  • IntelligentLookup

  • ReplicationFlow

  • TransformationFlow

  • DataFlow

  • TaskChain

  • ERModel

  • AnalyticModel

  • DataAccessControl

  • BusinessEntity

  • FactModel

  • ConsumptionModel

  • Folder

  • Package

For example, to list only views, enter:
--filter "type eq View"

semanticUsage

Enter a valid semantic usage:

  • Fact

  • RelationalDataset

  • Dimension

  • Hierarchy

  • HierarchyWithDirectory

  • Text

  • AnalyticalDataset

For example, to list only objects with a semantic usage of Dimension, enter:
--filter "semanticUsage eq Dimension"

status

Enter a valid status:

  • NotDeployed

  • Deployed

  • ChangesToDeploy

  • DesignTimeError

  • DesignTimeError

  • PendingDeployment

For example, to list only objects with a status of Deployed, enter:
--filter "status eq Deployed"

createdOn

changedOn

deployedOn

Enter a date in the format 'YYYY-MM-DD'.

For example, to list only objects deployed after 31 December 2022, enter:
--filter "deployedOn gt '2022-12-31'"

createdBy

changedBy

Enter a valid username.

For example, to list only objects last changed by Lisa, enter:
--filter "changedBy eq Lisa"

Read Objects

You can read the CSN/JSON definition of an object and optionally write it to a file.

Enter the following command and press Return:
datasphere objects <object-type> read 
    --space <id> 
    --technical-name <name>
    [--output <file>.json]
    [--accept <format>]
Complete the parameters as follows:

Parameter

Description

--space <id>

Enter the Space ID of the space.

--technical-name <name>

Enter the Technical Name of the object.

--output <file>.json

[optional] Enter a path to a .json file to write the output to.

Enter the option without any value (--output) to write the output to a file with the defaultFileName for the object.

If you do not include this option, the output will be printed to the command line.

--accept <format>

[optional] Specify the format to return the object definition in. You can choose between:

  • application/vnd.sap.datasphere.object.content+json - [default] Returns the most complete definition of the object, which may include undeployed design-time changes and unresolved associations (following import of the object).

  • application/vnd.sap.datasphere.object.content.design-time+json - Returns the current design-time version of the object, which may include undeployed changes, but excludes any unresolved associations.

  • application/vnd.sap.datasphere.object.content.run-time+json - Returns the current run-time version of the object, which excludes any undeployed design-time changes.

For example, to read the definition of the remote table MyTable in space MySpace and write it to the default file name, enter:
datasphere objects remote-tables read --space MySpace --technical-name MyTable --output

Create Objects

You can create an object by providing a definition in a JSON file or an input string.
Enter the following command and press Return:
datasphere objects <object-type> create 
    --space <id>
    --technical-name <name>
    --file-path <name>.json|--input '<stringified-json>'
    [--custom-validation-options <option[,option]>]    [--save-anyway]
    [--no-deploy]
Complete the parameters as follows:

Parameter

Description

--space <id>

Enter the Space ID of the space.

--technical-name <name>

Enter the Technical Name of the object.

--file-path <name>

[optional] Enter a path to a file with a .json extension containing your object definition.

--input '<stringified-json>'

[optional] Provide your definition in stringified json format instead of via the --file-path option.
For example, to create a simple table, T1 in MySpace, you could enter:
datasphere objects local-tables create --space MySpace --technical-name T1 --input '{"definitions":{"T1":{"kind":"entity","@EndUserText.label":"T1","@ObjectModel.modelingPattern":{"#":"DATA_STRUCTURE"},"@ObjectModel.supportedCapabilities":[{"#":"DATA_STRUCTURE"}],"elements":{"ID":{"@EndUserText.label":"ID","type":"cds.String","length":100,"key":true,"notNull":true},"Name":{"@EndUserText.label":"Name","type":"cds.String","length":100}}}}}'

--custom-validation-options <option[,option]>

[optional] Provide a comma-separated list of custom validation options:

  • allowRevertReleaseState:true - Allows users with the Spaces.Update privilege (included in the DW Space Administrator role) to override warnings and import objects with invalid release states (see Releasing Stable Views for Consumption).

--save-anyway

[optional] Save the object, even if there are validation warnings.

--no-deploy

[optional] Do not deploy the object after saving.

For example, to create a new local table in space MySpace, enter:
datasphere objects local-tables create --space MySpace --technical-name MyTable --file-path MyTableDefn.json

Update Objects

You can update an object by providing a new definition in a JSON file or an input string.
Enter the following command and press Return:
datasphere objects <object-type> update 
    --space <id>
    --technical-name <name>
    --file-path <name>.json|--input '<stringified-json>'
    [--custom-validation-options <option[,option]>]
    [--save-anyway]
    [--no-deploy]
Complete the parameters as follows:

Parameter

Description

--space <id>

Enter the Space ID of the space.

--technical-name <name>

Enter the Technical Name of the object.

--file-path <name>

[optional] Enter a path to a file with a .json extension containing your object definition.

--input '<stringified-json>'

[optional] Provide your definition in stringified json format instead of via the --file-path option.
For example, to create a simple table, T1 in MySpace, you could enter:
datasphere objects local-tables create --space MySpace --technical-name T1 --input '{"definitions":{"T1":{"kind":"entity","@EndUserText.label":"T1","@ObjectModel.modelingPattern":{"#":"DATA_STRUCTURE"},"@ObjectModel.supportedCapabilities":[{"#":"DATA_STRUCTURE"}],"elements":{"ID":{"@EndUserText.label":"ID","type":"cds.String","length":100,"key":true,"notNull":true},"Name":{"@EndUserText.label":"Name","type":"cds.String","length":100}}}}}'

--custom-validation-options <option[,option]>

[optional] Provide a comma-separated list of custom validation options:

  • allowRevertReleaseState:true - Allows users with the Spaces.Update privilege (included in the DW Space Administrator role) to override warnings and import objects with invalid release states (see Releasing Stable Views for Consumption).

--save-anyway

[optional] Save the object, even if there are validation warnings.

--no-deploy

[optional] Do not deploy the object after saving.

For example, to update the MyTable local table, enter:
datasphere objects local-tables update --space MySpace --technical-name MyTable --file-path MyTableDefn.json

Organize Objects In Folders

You can create folders in the same way as any other object (see Create Objects), and then move objects into those folders to organize them.

For example, to create two folders Project A at the root of space MySpace, and Inbound as a child of Project A, enter:
datasphere objects folders create --space MySpace --technical-name Folder_PROJECTA  --input '{"Folder_PROJECTA": {"_kind": "sap.repo.folder","_folderProperties": {"name": "Project A"}}}'
 
And then enter:
datasphere objects folders create --space MySpace --technical-name Folder_INBOUNDX  --input '{"Folder_INBOUNDX": {"_kind": "sap.repo.folder","_folderProperties": {"name": "Inbound","parent": "Folder_PROJECTA"}}}'
 
To move an object into a folder, enter the following command and press Return:
datasphere objects <object-type> move-to-folder 
    --space <id> 
    --technical-name <name>
    --folder <folder-technical-name>
Complete the parameters as follows:

Parameter

Description

--space <id>

Enter the Space ID of the space.

--technical-name <name>

Enter the Technical Name of the object.

--folder <folder-technical-name>

Enter the Technical Name of the target folder. To move the object to the space root, leave the value empty.

For example, to move the remote table MyTable in space MySpace to folder Folder_INBOUNDX, enter:
datasphere objects remote-tables move-to-folder --space MySpace --technical-name MyTable --folder Folder_INBOUNDX

Delete Objects

You can delete an object.

Enter the following command and press Return:
datasphere objects <object-type> delete 
    --space <id> 
    --technical-name <name>
    [--delete-anyway]
    [--force]
Complete the parameters as follows:

Parameter

Description

--space <id>

Enter the Space ID of the space.

--technical-name <name>

Enter the Technical Name of the object.

--delete-anyway

[optional] Delete the object, even if other objects depend on it.

--force

[optional] Suppress the Confirm Deletion dialog and delete the object without confirmation.

For example, to delete the local table MyTable in space MySpace, and suppress the Confirm Deletion dialog, enter:
datasphere objects local-tables delete --space MySpace --technical-name MyTable --force

Object Dependencies

When creating (see Create Objects) or updating (Update Objects) objects, any sources or other objects that your object depends on must already be present in the space, or your action will fail.

For example, if View_A has two tables (Table_B and Table_C) and another view (View_D) as its sources, then these three objects must all be present in the space before you can create View_A.
The dependencies between object types are as follows:

Object Type

Dependencies

Remote Tables

See Import Remote Tables.

A remote table depends on its connection.

Local Tables

See Creating a Local Table.

A local table without delta capture does not have dependencies on any other objects. For local tables with delta capture enabled, you must use the --accept option when reading the object, in order to obtain all the delta capture objects in the output file:

datasphere objects local-tables read 
  --space MySpace 
  --technical-name MyDeltaTable 
  --accept application/vnd.sap.datasphere.object.content.design-time+json 
  --output MyDeltaTable.json

The file created can then be written back into a space in the normal way:

datasphere objects local-tables create
  --space MySpace2 
  --technical-name MyDeltaTable 
  --file-path MyDeltaTable.json

Flows

See Creating a Data Flow, Creating a Replication Flow, and Creating a Transformation Flow.

A data flow, replication flow, or transformation flow depends on all its sources and its target tables.

Views

See Creating a Graphical View and Creating an SQL View.

A view depends on all its sources and any used data access controls.

Intelligent Lookups

See Creating an Intelligent Lookup.

An intelligent lookup depends on its input and lookup entities.

Analytic Models

See Creating an Analytic Model.

An analytic model depends on its fact and dimension sources.

E/R Models

See Creating an Entity-Relationship Model.

An E/R model depends on the objects that it visualizes.

Data Access Controls

See Securing Data with Data Access Controls.

The definition of a data access control contains the definition of its permissions entity. When you export a data access control, the permissions entity is exported too.

Task Chains

See Creating a Task Chain.

A task chain depends on the objects that it automates.

Business Entities / Business Entity Versions

See Creating a Business Entity.

A business entity depends on its source data entity and any authorization scenarios.

Fact Models

See Creating a Fact Model.

A fact model depends on all its source fact models and business entities.

Consumption Models

See Creating a Consumption Model.

A consumption model depends on all its source fact models and business entities.

Authorization Scenarios

See Creating an Authorization Scenario.

An authorization scenario depends on its data access control.

Packages

See Creating Packages to Export.

A package depends on all its required packages and the objects it contains.

Object Definition Syntax

You can obtain detailed information about object syntax by reading an appropriate object from your space (see Read Objects). The principle sections are:

Section

Description

definitions

Contains the structure and core metadata of the object.

editorSettings

Contains information about the editor associated with the object including, in the case of graphical objects, a serialization of the diagram.

sharing

[tables and views] Contains a list of the spaces to which the object is shared (see Share Objects to Other Spaces).

i18n

Contains translations of metadata grouped by language (see Translate Model, Entity, and Column Names).

Share Objects to Other Spaces

Local tables, remote tables, and views can be shared from their space to other spaces, in which they can be used as sources for flows and views (see Sharing Entities and Task Chains to Other Spaces).

The sharing section lists the spaces to which the entity is shared. You can modify this section to add or remove spaces to which the table or viewed is shared.

In this example, the object, a local table, is shared to two spaces, SALES_EU and SALES_US:
"sharing": {
    "LocalTable":[
        "targetSpaces": [
            "SALES_EU",
            "SALES_US"
        ]
    ]
}

Translate Model, Entity, and Column Names

Business names in your exposed objects can be translated to support display languages in SAP Analytics Cloud (see Translating Metadata for SAP Analytics Cloud).

The i18n section contains translations of the model or entity business name, and the business names of its measures and attributes, grouped by language. You can modify this section to edit translations, or add or remove languages and their translations.

In this example, the local table's business name, and the business name of its two attributes are provided in English and French:
"i18n": {
	"en":[
		"LocalTable@ENDUSERTEXT.LABEL": "Departments",
		"LocalTable#ID@ENDUSERTEXT.LABEL": "Department ID",
		"LocalTable#ID@ENDUSERTEXT.LABEL": "Department Name"
	],
	"fr":[
	   "LocalTable@ENDUSERTEXT.LABEL": "Départements",
		"LocalTable#ID@ENDUSERTEXT.LABEL": "Numéro de département",
		"LocalTable#ID@ENDUSERTEXT.LABEL": "Nom du département"
	]
}

Modify Generated Objects

Certain objects can be generated in SAP Datasphere. These objects can be modified in only limited ways: