SAP CDS COND EXPR TYPES V2



Get Example source ABAP code based on a different SAP table
  



ABAP_CDS_DDL - CDS View Entity, cds_cond, Comparable Types
The following tables show which built-in data types in ABAP Dictionary can be compared with each other in a condition of a CDS view entity.
ITOC

Comparisons with Fields of Data Sources
The following table shows the possible combinations of data source fields on the left side (lhs) with data source fields on the right side (rhs) of comparisons. lhs/rhsINT1INT2INT4 INT8DECCURR QUANDECFLOAT16DECFLOAT34 FLTPCHARSSTRINGNUMC CLNTLANGDATS TIMSDATNTIMNUTCLONG ACCPUNITCUKY RAW
INT1xxxxx-axxx-------- ------
INT2xxxxx-axxx-------- ------
INT4xxxxx-axxx-------- ------
INT8xxxxx-axxx-------- ------
DECxxxxx-axxx-------- ------
CURR-----d------------ ------
QUANaaa-a-aaaa-------- ------
DECFLOAT16xxxxx-axxx------ --------
DECFLOAT34xxxxx-axxx------ --------
FLTPxxxxx-axxx-------- ------
CHAR----------xxmlxxx- --xxx-
SSTRING----------xx--x-- ---xxx-
NUMC----------m-ll-ll- ------
CLNT----------l-lx---- ------
LANG----------xx--x--- ------
DATS----------x-l--x-- ------
TIMS----------x-l---x- ------
DATN-----------------x ------
TIMN------------------ x-----
UTCLONG----------------- --x----
ACCP----------xx------ --x---
UNIT----------xx------ ---x--
CUKY----------xx------ ----x-
RAW------------------ -----l
There are no restrictions for combinations using x.
In combinations using l, the lengths of the compared columns must match exactly.
For combinations using m, the length is relevant: the field of type NUMC can have the same lengths or fewer characters than the field of type CHAR. If the field of type NUMC is longer than the field of type CHAR , a syntax error occurs.
For combinations using d, the number of decimal places must match exactly.
ABAP_NOTE Operands of data type CURR can be cast to data type DECFLOAT34 using the conversion function CURR_TO_DECFLOAT_AMOUNT to avoid length requirements.
For combinations using a, both operands must be specified as ABAP CDS quantity fields by adding a reference to a unit of measurement key using the annotation @Semantics.quantity.unitOfMeasure. Otherwise, a syntax check warning occurs.
ABAP_NOTE You can use the conversion function GET_NUMERIC_VALUE to turn quantity fields into regular fields of data type DECFLOAT34.

Comparisons with Parameters
The following table shows the possible combinations of data source fields on the left side (lhs) with parameters on the right side (rhs) of comparisons. lhs/rhsINT1INT2INT4 INT8DECCURR QUANDECFLOAT16DECFLOAT34 FLTPCHARSSTRINGNUMC CLNTLANGDATS TIMSDATNTIMNUTCLONG ACCPUNITCUKY RAW
INT1xxxxx-xxxx-------- ------
INT2xxxxx-xxxx-------- ------
INT4xxxxx-xxxx-------- ------
INT8xxxxx-xxxx-------- ------
DECxxxxx-xxxx-------- ------
CURR-----d------------ ------
QUAN------x----------- ------
DECFLOAT16xxxxx-xxxx------ --------
DECFLOAT34xxxxx-xxxx------ --------
FLTPxxxxx-xxxx-------- ------
CHAR----------xxmlxxx- ---xx-
SSTRING----------xx--x-- ----xx-
NUMC----------m-ll-ll- ------
CLNT----------l-lx---- ------
LANG----------xx--x--- ------
DATS----------x-l--x-- ------
TIMS----------x-l---x- ------
DATN-----------------x ------
TIMN------------------ x-----
UTCLONG----------------- --x----
ACCP----------xx------ ------
UNIT----------xx------ ---x--
CUKY----------xx----- -----x-
RAW------------------ -----l
There are no restrictions for combinations using x.
In combinations using l, the lengths of the compared operands must match exactly.
For combinations using m, the length is relevant: the field of type NUMC can have the same lengths or less characters than the field of type CHAR. If the field of type NUMC is longer than the field of type CHAR , a syntax error occurs.
For combinations using d, the number of decimal places must match exactly.
ABAP_NOTE Operands of data type CURR can be cast to data type DECFLOAT34 using the conversion function CURR_TO_DECFLOAT_AMOUNT to avoid this length requirement.

Comparisons with Literals
The following table shows the possible combinations of data source fields on the left side (lhs) with literals on the right side ( rhs) of comparisons. The literals can be typed or untyped. It is recommended that only typed literals are used, because they offer more data types. With typed literals, the data types shown in the table are possible. lhs/rhsINT1INT2INT4 INT8 DECCURR QUAN FLTPCHAR NUMCRAWDATS TIMS DATNTIMN UTCL DECFLOAT16DECFLOAT34
INT1yyyyy-yy------- - y y
INT2xyyyy-yy------ --yy
INT4xxyyy-yy------ --yy
INT8xxxyy-yy------ --yy
DECxxxxd-dd------- -mm
CURRmmmmdddd------ --mm
QUANmmmmd-dd------ --mm
DECFLOAT16xxxxx-xx---- ---- xx
DECFLOAT34xxxxx-xx---- ----xx
FLTPxxxxx-xx------ --xx
CHAR--------mm---- ----
SSTRING--------m---- -----
NUMC--------ll---- ----
CLNT--------ll---- ----
LANG--------ll---- ----
DATS---------l-x-- ----
TIMS---------l--x- ----
DATN-------------x ----
TIMN-------------- x---
UTCL-------------- -x--
ACCP---------l---- ----
UNIT--------m----- ----
CUKY--------m----- ----
RAW----------l---- ---
There are no restrictions for combinations using x.
For combinations using y, the literal value must be within the value range of the respective type. That means:
For a comparison with INT1, the literal value must be between 0 and 255.
For a comparison with INT2, the literal value must be between -32 ,768 and +32,767.
For a comparison with INT4, the literal value must be between -2 ,147,483,648 and +2,147,483,647.
For a comparison with INT8, the literal value must be between -9 ,223,372,036,854,775,808 and +9,223,372,036,854,775,807.
For combinations using m, the length of the literal cannot be greater than the column.
For combinations using d, the length of the literal and the number of decimal places cannot be greater than the length and number for the column.
For combinations using l, the length of the literal must be equal to the length of the column.
If the literal on the right side (rhs) is of data type CURR , it must have exactly two decimal places. Since the number of decimal places of rhs and lhs must match exactly, lhs must also have exactly two decimal places. The conversion functions CURR_TO_DECFLOAT_AMOUNT and GET_NUMERIC_VALUE can be used to avoid this length requirement.

Comparisons with CDS Amount Fields and CDS Quantity Fields
If one of the operands lhs or rhs of a comparison is a CDS amount field , a CDS quantity field, or a CDS calculated quantity, special rules apply:
Both operands lhs and rhs must have the same reference type. Both must be either amounts, or quantities, or calculated quantities. Comparing operands with references of different types ( currency key, unit key, or calculated unit) results in a syntax check warning.
An operand of type CURR can only be compared with another operand of type CURR. The number of decimal places of both operands must match exactly.
ABAP_EXCEPTION If lhs has data type CURR and rhs is specified as literal, the following data types are possible for rhs: INT1 , INT2, INT4, INT8, DEC, CURR, QUAN, FLTP, DECFLOAT16, DECFLOAT34.
Two conversion functions are available to circumvent limitations:
CURR_TO_DECFLOAT_AMOUNT converts an amount field of type CURR to an amount field of type DECFLOAT34.
GET_NUMERIC_VALUE convert amounts and quantities into regular fields. ABAP_CAUTION In the ON condition of a CDS association, these two conversion functions are not available, since functions in general are not supported in the ON condition of a CDS association.
The following table shows the possible combinations of operands in comparisons. Number refers to an operand of a numeric data type without reference annotation that turns it into an amount or quantity field. Type of OperandComment
amount, number syntax check warning lbr ABAP_EXCEPTION : If number is specified as literal, no syntax check warning occurs.
amount, amountOK. Elements of data type CURR must have exactly the same number of decimal places.
quantity, number syntax check warning lbr ABAP_EXCEPTION If number is specified as literal, no syntax check warning occurs.
quantity, quantityOK
amount, quantitysyntax check warning
amount, calculated quantitysyntax check warning
quantity, calculated quantitysyntax check warning
calculated quantity, number syntax check warning lbr ABAP_EXCEPTION If number is specified as literal, no syntax check warning occurs.
calculated quantity, calculated quantityOK
Undesirable comparisons of operands with references of different types result in a syntax check warning. There is no syntax check error to ensure downward compatibility.
The exception that amounts, quantities, and calculated quantities can be compared with a number if the number is specified as literal is in place to ensure downward compatibility.