Behavior of Data Types

Overview

The scripting language supports basic data types such as string, numeric and Boolean values. In addition, the existing metadata of the underlying SAP cloud platform for core data types (CDTs) and global data types (GDTs) is made available.

The implementation type of the particular data type is taken into account during the mapping of CDTs and GDTs to the basic types of the scripting language. In the studio, you can explore all SAP data types that are released with the public solution model (PSM) and their implementation type in the Repository Explorer on the Data Types tab. For more information, see Repository Explorer.

Basic Data Types

The basic data types that are supported by the studio are listed in the following table:

Basic Type

Implementation Type

Properties

XSD Data Type

SAP GDT or SAP CDT, For Example:

Boolean

xsd:boolean

Indicator

Numeric (FLTP)

INT1

1-byte integer (internal). Value range: 0 to 255. The MinimumValue attribute and the MaximumValue attribute define the business contract of the data type. These attributes do not limit the value range technically.

xsd: unsignedByte

SMALLNONNEGATIVEINTEGER_DecimalValue

INT4

4-byte integer (internal). Value range: -2 (MinimumValue ),147,483,648 to +2,147,483,647 (MaximumValue) .

xsd:int

  • NumberValue

  • IntegerValue

DEC

Decimal number with fixed length (MaximumDigits) and fixed number of fractions (MaximumFractions).

xsd:decimal

  • Amount.content

  • Quantity.content

  • Measure.content

  • DecimalValue

  • SMALLNONNEGATIVE_Ratio

  • Percent

DF34_DEC

Decimal floating point numbers of this type are represented internally with 34 decimal places in accordance with the IEEE-754-2008 standard (DF34_DEC). Value range: numbers between 1E6145(1E-34 - 1) and -1E-6143 for the negative range, 0 and +1E-6143 and 1E6145(1 - 1E-34) for the positive range. Values lying between these ranges are in the subnormal range and are rounded. Outside the subnormal range, each 34-digit decimal number can be represented precisely by such a decimal floating point number.

Numeric Character

NUMC

Character string containing the digits 0 to 9 only. Valid content of a numeric text field. The maxLength property specifies the maximum length of the string.

xsd:token

AccountingPeriodID FiscalYearID

String

CHAR, SSTR, and STRG

Character string containing any alphanumeric characters, including special characters. SAP cloud systems are Unicode systems with the system code page UTF-16. A character has a length of two bytes. The maxLength property specifies the maximum length of the string.

  • xsd:token

  • xsd: string

  • xsd:anyURI

  • Text.content

  • LANGUAGEINDEPENDENT_SHORT_Name

  • LONG_Description.content

  • BusinessTransactionDocumentID

  • ID

  • EmailURI

  • ApprovalStatusCode

  • Amount.currencyCode

Binary

RSTR, RAW

String of bytes

  • xsd:base

  • 64 Binary

BinaryObject. In particular: usage of AttachmentFolder dependent object

UUID

XSDUUID_RAW

Universally unique identifier

xsd:token

UUID

Date

DATS

Gregorian date “YYYY-MM-DD”

xsd:xsd:Date

Date

GlobalDateTime

XSDDATETIME_LONG_Z

Gregorian date and time “2011-12-25T02:30:00Z”

xsd:DateTime

GLOBAL_DateTime

Time

TIMS

Time “HH:MM:SS”

xsd:time

Time

Duration

XSDDURATION_ISO

Duration, for example “P12Y11M2DT4H12M40S”

xsd:duration

Duration

LanguageCode

XSDLANGUAGE

Language code, for example “E”

xsd:language

LanguageCode

For more information, see the data type definitions of the World Wide Web Consortium (W3C ) at http://www.w3.org/TR/xmlschema-2/.

Validation by the User Interface and Web Service Runtime

The user interface (UI) runtime of the SAP cloud solution validates the user input according to the data type definition. The following data type properties are checked in particular:

As a consequence, you do not need to implement validations in your script files to ensure that the user input matches the data type definition. The SAP web service runtime validates the service input according to the data type definition (XSD schema validation).

Internal Variables of the Scripting Language

Internal string variables defined in the scripting language are not restricted in length. “Not restricted” means that the variables are limited by the memory quota of a session, which is defined by the system administrator.

Internal numerical variables defined in the scripting language are of the DF34_DEC implementation type.

Example

var string = this.ShortText; // string is a unrestricted string

var i = this.IntegerValue; // i is of DF34_DEC type

In the following example, a very long text is used:

  • var string = "Lorem ipsum dolor sit amet, consectetur …"
  • // very long text, containing \"culpa\" at position 1000+ and \"augue\" at position 2000+
  • position = string.Find("\"culpa\"");
  • string.Substring(position); // result: ""culpa" …" (not restricted)
  • position = string.Find("\"augue\"");
  • this.ShortNote = string.Substring(position);// result: ""augue" duis …" (40 char)
>>> MISSING TARGET TEXT FOR TEXT-ID: 'XTXT_a11y_SPExampleEnd' <<<

Conversion

Syntax

If variables are typed with data types that belong to the same basic type in the scripting language, they are implicitly converted by the scripting language. For example:

this.ID = this.ShortName;

if ( this.Amount.content > this.IntegerValue) …

If variables are typed with data types that belong to different basic types in the scripting language, they need to be converted by using conversion functions, for example, ToString(), Numeric.ParseFromString(), GlobalDateTime.ConvertToDate()..

Behavior

If you perform operations on string variables in your script files, you need to ensure that the length of the result strings match the data type definition. For example:

  • // ShortName is typed with LANGUAGEINDEPENDENT_SHORT_Name -> length = 10
  • // LongName is typed with LANGUAGEINDEPENDENT_LONG_Name -> length = 40

this.ShortName = this.LongName.Substring(0, 10);

Note

The program terminates when saving if the length of the LongName field is greater than 10 characters and no check exists.

End of the note

If the content of a variable is outside the range that is specified by the data type definition, the following can occur as a consequence:

  • Program termination, for example, an overflow error

  • A system message

  • An implicit conversion, for example, a cutoff

Note

Variables of unrestricted length, for example, variables of the LANGUAGEINDEPENDENT_Text data type, are truncated at a length of 255 characters as soon as they are saved to the database. For texts that are longer than 255 characters, use the TextCollection dependent object.

End of the note

For variables that are typed with numerical data types, rounding is performed according to the definition of the target data type. While the scripting language uses decfloat34 internally, the values are rounded according to the definition of the data type as soon as the value is assigned to a business object element.

Example

Note: The Quantity.content data type is specified as a decimal value with 31 digits and 14 fractions.

  • this.IntegerValue1 = 1 / 3; // result: 0
  • this.IntegerValue2 = 2 / 3; // result: 1
  • var num = 1/3;
  • this.IntegerValue3 = num * 3; // result: 1
  • this.IntegerValue4 = this.IntegerValue1 * 3; // result: 0
  • this.Quantity1.content = 1 / 3000000000; // result: 0.00000000033333
  • this.Quantity2.content = 2 / 3000000000; // result: 0.00000000066667
  • num = 1/3000000000;
  • this.Quantity3.content = num * 3000000000; // result: 1
  • this.Quantity4.content = this.Quantity1.content * 3000000000; // result: 0.99999
  • this.Quantity5.content = 1 / 3000000000000000000; // result: 0
  • num = 1/3000000000000000000;
  • this.Quantity6.content = num * 3000000000000000000; // result: 1
  • this.Quantity7.content = this.Quantity5.content * 3000000000000000000; // result: 0
  • num = this.Quantity5.content;
  • this.Quantity8.content = num * 3000000000000000000; // result: 0
>>> MISSING TARGET TEXT FOR TEXT-ID: 'XTXT_a11y_SPExampleEnd' <<<

Additional Properties for Identifier Data Types

For identifier data types, additional properties are specified in the GDT definition:

The UI runtime performs upper case conversion and alpha conversion automatically. The scripting language, however, does not perform these types of conversion automatically. Therefore you need to ensure this in your script files.

Example

ID data type (supporting upper case conversion and alpha conversion)

  • var string = "123456789a123456789b123456789C123456789D123456789E123456789F123456789G123456789H123456789G123456789I";
  • this.ID = string;
  • position = this.ID.Find("A"); // result: -1

The result is —1 because the content of the ID is not automatically converted to upper case. To convert to upper case, use the ToUpperCase built-in function, for example:

  • var string = "123456789a123456789b123456789C123456789D123456789E123456789F123456789G123456789H123456789G123456789I";
  • this.ID = string.ToUpperCase();
  • position = this.ID.Find("A"); // result: 9
>>> MISSING TARGET TEXT FOR TEXT-ID: 'XTXT_a11y_SPExampleEnd' <<<

Variables Typed with Code Data Types

Code data types can be mapped to the string basic type or the numeric character basic type. The behavior of a variable typed with a code data type, for example, PriorityCode, ApprovalStatusCode and Amount.currencyCode, is as follows:

The UI runtime performs a content check of the code list. The scripting language, however, does not perform this check automatically. Therefore you need to ensure this in your script files.

Example

  • var string = "123456789a123456789b123456789C123456789D";
  • this.ApprovalStatusCode = string; // result: "12"
  • // Note: "12" is not an allowed code value.
  • // Note: Assignment between IDs is not allowed.
  • this.ApprovalStatusCode = this.DeliveryPriorityCode;
>>> MISSING TARGET TEXT FOR TEXT-ID: 'XTXT_a11y_SPExampleEnd' <<<