SAP ABAP SQL TYPED LITERALS



Get Example source ABAP code based on a different SAP table
  


• INT1 ABAP_SQL_LITERAL
• INT2 ABAP_SQL_LITERAL
• INT4 ABAP_SQL_LITERAL
• INT8 ABAP_SQL_LITERAL
• DEC ABAP_SQL_LITERAL
• DECFLOAT16 ABAP_SQL_LITERAL
• DF16_DEC ABAP_SQL_LITERAL
• DF16_RAW ABAP_SQL_LITERAL
• DECFLOAT34 ABAP_SQL_LITERAL
• DF34_DEC ABAP_SQL_LITERAL
• DF34_RAW ABAP_SQL_LITERAL
• D16D ABAP_SQL_LITERAL
• D16R ABAP_SQL_LITERAL
• D34D ABAP_SQL_LITERAL
• D34R ABAP_SQL_LITERAL
• DECFLOAT16_DEC ABAP_SQL_LITERAL
• DECFLOAT34_DEC ABAP_SQL_LITERAL
• FLTP ABAP_SQL_LITERAL
• CHAR ABAP_SQL_LITERAL
• STRING ABAP_SQL_LITERAL
• SSTRING ABAP_SQL_LITERAL
• RAW ABAP_SQL_LITERAL
• RAWSTRING ABAP_SQL_LITERAL
• NUMC ABAP_SQL_LITERAL
• CLNT ABAP_SQL_LITERAL
• LANG ABAP_SQL_LITERAL
• DATS ABAP_SQL_LITERAL
• DATN ABAP_SQL_LITERAL
• TIMS ABAP_SQL_LITERAL
• TIMN ABAP_SQL_LITERAL
• UTCLONG ABAP_SQL_LITERAL

AB_SQL - Typed Literals


ABAP_SYNTAX
... dtype`...`

What does it do?
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 AB-SQL 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`.



Latest 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.
NON_V5_HINTS
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 .
ABAP_HINT_END
Typed literals can be split into the following categories:
ITOC

Typed Numeric Literals
The following table describes the typed numeric literals: SyntaxNamePossible 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`...` lbr DECFLOAT34`...` lbr $| D34N`...` lbr DF34_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`...` lbr DF34_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 literalMantissa 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.



Latest 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.
A zero with a sign + or - is not allowed for integer literals and packed number literals. For example, INT4`-0` is not allowed. This rule is verified by the syntax check.
For all decimal floating point literals , there are alternative notations for the data type. This is indicated in the table above by the $| sign.
NON_V5_HINTS
ABAP_HINT_END

ABAP_EXAMPLE_VX5
Use of a typed numeric literal in a WHERE condition.
ABEXA 01445
ABAP_EXAMPLE_END

Typed Character Literals
The following table describes the typed character literals: SyntaxNamePossible Characters CHAR`...` Text field literal String of any 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 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.

ABAP_EXAMPLE_VX5
Use of a typed character literal in a WHERE condition.
ABEXA 01446
ABAP_EXAMPLE_END

Typed Byte Literals
The following table describes the typed byte literals: SyntaxNamePossible 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.



Latest notes:

The specified characters are used to represent byte values in a hexadecimal format.
The letters A-F must be in uppercase.
If untyped character literals are used for hexadecimal values, the number of characters may be odd and the value is padded on the right with hexadecimal 0 in accordance with the conversion rules.
NON_V5_HINTS
ABAP_HINT_END

ABAP_EXAMPLE_VX5
Use of a typed byte field literal in a WHERE condition.
ABEXA 01449
ABAP_EXAMPLE_END

Typed Literals for Character-Like Types with Special Semantics
The following table describes the typed literals for character-like types with special semantics: SyntaxNamePossible 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 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 character and it consists of exactly one character. A blank space is not allowed. An empty literal LANG`` is allowed and denotes a blank.

ABAP_EXAMPLE_VX5
Use of a typed numeric text literal in a WHERE condition.
ABEXA 01447
ABAP_EXAMPLE_END

Typed Date and Time Literals
The following table describes the typed date and time literals: SyntaxNamePossible 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.



Latest notes:

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

ABAP_EXAMPLE_VX5
Use of typed literals as operands in SQL date and time functions.
ABEXA 01444
ABAP_EXAMPLE_END

Typed Currency and Quantity Literals
The following table describes the typed currency and quantity literals: SyntaxNamePossible 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 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 characters with a maximum of 3 characters . An empty literal UNIT`` is allowed and denotes two blanks.

ABAP_EXAMPLE_VX5
Use of a typed currency field literal in a WHERE condition.
ABEXA 01448
ABAP_EXAMPLE_END