Ansicht
Dokumentation

ABENABAP_SQL_TYPED_LITERALS - ABAP SQL TYPED LITERALS

ABENABAP_SQL_TYPED_LITERALS - ABAP SQL TYPED LITERALS

ABAP Short Reference   General Material Data  
This documentation is copyright by SAP AG.
SAP E-Book

- Typed Literals

... dtype`...`

Effect

Typed literals can be created for all built-in ABAP Dictionary types with the exception of LCHR, LRAW, GEOM_EWKB, PREC, ACCP, DF16_SCL, and DF34_SCL. A typed literal can be used in read positions of statements where host variables are possible and where it is always handled as an elementary SQL expression of the specified data type. It is passed without an ABAP-specific type conversion to the database and evaluated there.

dtype is the name of a built-in dictionary type and it is followed by the character-like representation of the value in single backquotes (`). Only those values can be specified that are accepted by the data type of the literal.

When using the literal operator for concatenating two typed literals of the same type as a single character literal, the data type dtype is specified only once before the first subliteral. The syntax is, for example: INT8`123` & `456`.

Notes

  • Typed literals should be used instead of untyped literals. They offer many advantages, such as more flexibility with regard to the data type they can have, explicit type declaration, and checking type compatibility of the value specified.
  • The maximum length of the content of a typed literal is 255 and can be restricted further by the value range of the data type. The maximum line length in the ABAP Editor is 255 characters, which means that a literal with 255 characters cannot be specified within a single row of a program due to the type name and the backquotes. The maximum length of 255 characters can be achieved only by using the literal operator &.

Typed literals can be split into the following categories:

Typed Numeric Literals

The following table describes the typed numeric literals:

Syntax Name Possible Characters
INT1`...`\lbrINT2`...`\lbrINT4`...`\lbr INT8`...` Integer literal Uninterrupted string of digits, with an optional sign + or - as a prefix. At least one digit must be specified. The value of the number must be in the value range of the respective dictionary type. An empty literal `` is not allowed.
DEC`...` Packed number literal String of digits with a maximum of one decimal point (.). This point can be located in front of, between, or after the digits. The string can be prefixed with an optional sign + or -. At least one and no more than 31 digits can be specified. The maximum number of decimal places is 14. The length used in the memory and the number of decimal places are determined by the number of digits specified. An empty literal `` is not allowed.
DECFLOAT16`...`\lbr $| D16N`...`\lbrDF16_RAW`...`\lbr $| D16R`...` \lbrDECFLOAT34`...`\lbr $| D34N`...`\lbrDF34_RAW`...`\lbr $| D34R`...` Decimal floating point literal Mantissa followed by an optional exponent. The mantissa is a string of digits with a maximum of one decimal point (.). This point can be located in front of, between, or after the digits. The string can be prefixed with an optional sign + or -. Length restrictions, typing conventions, and scaling rules of the respective dictionary type apply. An empty literal `` is not allowed.
DF16_DEC`...`\lbr $| D16D`...`\lbrDF34_DEC`...`\lbr $| D34D`...` Decimal floating point literal The rules for packed number literals (see above) apply. Furthermore, DF16_DEC can have a maximum length of 16 digits. An empty literal `` is not allowed.
FLTP`...` Binary floating point literal Mantissa followed by an optional exponent. The mantissa is a string of digits with a maximum of one decimal point (.). This point can be located in front of, between, or after the digits. The string can be prefixed with an optional sign + or -. The maximum number of valid places is 16. An empty literal `` is not allowed.

Notes

  • For all numeric literals, the rule applies that not more than one zero is allowed on the left side of the decimal point. Thus, DEC`00.00` is not allowed and INT1`00` as integer literal is not allowed either. This rule is verified by the syntax check.

Example

Use of a typed numeric literal in a WHERE condition.

Typed Character Literals

The following table describes the typed character literals:

Syntax Name Possible Characters
CHAR`...` Text field literal String of any alphanumeric characters. The length of a text field literal must lie between 1 and 255 characters. An empty text field literal CHAR`` is allowed and denotes the initial value of one blank. To represent a quotation mark in a text field literal, two consecutive quotation marks must be specified.
STRING`...`\lbrSSTRING`...` Text string literal String of any alphanumeric characters. A typed text string literal can have a maximum of 255 characters. A typed text string literal can be empty and the typed text string literal STRING`` represents an empty string with length 0. To represent a backquote in a text string literal, two consecutive backquotes must be specified.

Example

Use of a typed character literal in a WHERE condition.

Typed Byte Literals

The following table describes the typed byte literals:

Syntax Name Possible Characters
RAW`...` Byte field literal String including the characters 0-9 and A-F. No other characters are allowed. The number of characters must be even. At least two characters must be specified. An empty literal RAW`` is not allowed.
RAWSTRING`...` Byte string literal String including the characters 0-9 and A-F. No other characters are allowed. The number of characters must be even. The empty byte string literal RAWSTRING`` represents an empty byte string.

Notes

  • The specified characters are used to represent byte values in a hexadecimal format.
  • The letters A-F must be in uppercase.

Example

Use of a typed byte field literal in a WHERE condition.



Typed Literals for Character-Like Types with Special Semantics

The following table describes the typed literals for character-like types with special semantics:

Syntax Name Possible Characters
NUMC`...` Numeric text literal Character string consisting of the digits 0 to 9. The length of a numeric text literal must lie between 1 and 255 characters. Empty numeric text literals NUMC`` or blanks within numeric text literals are not allowed.
CLNT`...` Client literal String of any alphanumeric characters with a length of exactly 3 characters. Trailing blanks are not allowed. An empty literal CLNT`` is allowed and denotes the initial value of three blanks.
LANG`...` Language key literal A language key literal can contain any alphanumeric character and it consists of exactly one character. A blank space is not allowed. An empty literal LANG`` is allowed and denotes a blank.

Example

Use of a typed numeric text literal in a WHERE condition.

Typed Date and Time Literals

The following table describes the typed date and time literals:

Syntax Name Possible Characters
DATS`...`\lbrDATN`...` Date literal Character string that represents a date in the format YYYYMMDD. Must contain a valid date according to the rules for valid dates described for time stamp literals below. An empty string `` is not allowed.
TIMS`...`\lbrTIMN`...` Time literal Character string that represents a time in the format HHMMSS. Must contain a valid time according to the rules for valid times described for time stamp literals below. An empty literal `` is not allowed.
UTCLONG`...` Time stamp literal Character string that represents a time stamp in the format YYYY-MM-DDTHH:MM:SS,SSSSSSS, precise to 100 nanoseconds. YYYY-MM-DD consists of eight digits separated by hyphens. They must represent dates that are valid in accordance with the calendar rules: YYYY (year): 0001 to 9999, mm (month): 01 to 12, DD (day): 01 to 31. "1582-10-05" to "1582-10-14" are skipped due to the conversion from the Julian to the Gregorian calendar. The letter "T" between the date and the time must be specified exactly as it is here. HH:MM:SS,SSSSSSS consists of digits separated by colons and a comma. They must represent a time in a 24-hour range in the format HHMMSS: 00 to 23 for HH (hours) and 00 to 59 for MM (minutes) and 00 to 59 for SS,SSSSSSS (seconds with a maximum of seven decimal places). More than seven decimal places can be specified, however the digits after the seventh decimal place must be "0". The comma does not have to be specified. No other characters are allowed. An empty literal UTCLONG`` is allowed and denotes the initial value.

Note

60 cannot be specified in a time, either as minutes or as seconds. In particular, this means that leap seconds cannot be specified.

Example

Use of typed literals as operands in SQL date and time functions.

Typed Currency and Quantity Literals

The following table describes the typed currency and quantity literals:

Syntax Name Possible Characters
CURR`...` Currency field literal Uninterrupted string of digits with an optional sign + or - as a prefix. Cannot contain more than one decimal point (.). At least one and no more than 31 digits can be specified. The maximum number of decimal places is 14. Not more than one zero is allowed on the left side of the decimal point. A zero with a sign + or - is not allowed. An empty literal CURR`` is not allowed.
CUKY`...` Currency key literal String of any alphanumeric characters with a maximum of 5 characters. Trailing blanks are not allowed. An empty literal CUKY`` is allowed and denotes five blanks.
QUAN`...` Quantity field literal Uninterrupted string of digits with an optional sign + or - as a prefix. Cannot contain more than one decimal point (.). At least one and no more than 31 digits can be specified. The maximum number of decimal places is 14. Not more than one zero is allowed on the left side of the decimal point. A zero with a sign + or - is not allowed. An empty literal QUAN`` is not allowed.
UNIT`...` Unit key literal String of any alphanumeric characters with a maximum of 3 characters. An empty literal UNIT`` is allowed and denotes two blanks.

Example

Use of a typed currency field literal in a WHERE condition.






General Data in Customer Master   PERFORM Short Reference  
This documentation is copyright by SAP AG.

Length: 20494 Date: 20240328 Time: 235425     sap01-206 ( 270 ms )