Saturday, December 5, 2020

SQL Function in CDS View :

 

 

 

@AbapCatalog.sqlViewName: 'ZSQL_FUNCTION'
@AbapCatalog.compiler.CompareFilter: true
@AbapCatalog.preserveKey: true
@AccessControl.authorizationCheck: #CHECK
@EndUserText.label: 'SQL Function in CDS'
define view ZSD_SQL_FUNC as select from kna1 {
    
    kna1.kunnr,
    kna1.name1,
    CONCAT( kna1.kunnr, kna1.name1) as CUST_DETAIL
}

 

 

 

 

@AbapCatalog.sqlViewName: 'ZSQL_FUNCTION'
@AbapCatalog.compiler.CompareFilter: true
@AbapCatalog.preserveKey: true
@AccessControl.authorizationCheck: #CHECK
@EndUserText.label: 'SQL Function in CDS'
define view ZSD_SQL_FUNC as select from kna1 {
    
    kna1.kunnr,
    kna1.name1,
    CONCAT( KNA1.STCD1 , kna1.name1) as CUST_DETAIL
}

 

 

String Function:

Function Valid Argument Types Result Type
CONCAT(arg1, arg2) See below SSTRING if an argument has the type SSTRING, else CHAR with the length of the result.
CONCAT_WITH_SPACE(arg1, arg2, spaces ) arg1, arg2: see below

spaces: positive numeric literal greater than 0 and less than or equal to 1331
SSTRING if an argument has the type SSTRING, else CHAR with the length of the result.
INSTR(arg, sub) arg: see below

sub: non-empty numeric literal
INT4
LEFT(arg, len) arg: see below

len: positive numeric literal greater than 0 and less than or equal to 1333
SSTRING if arg has the type SSTRING, else CHAR with length len
LENGTH(arg) See below INT4
LOWER( arg ) See below, with the exception of NUMC, DATS and TIMS Data type of arg in the length of arg
LPAD(arg, len, src) arg: see below

len: positive numeric literal greater than 0 and less than or equal to 1333

src: character Literal
SSTRING if arg has the type SSTRING, else CHAR with length len
LTRIM(arg, char) arg: see below

char: Character literal with length 1
SSTRING if arg has the type SSTRING, else CHAR with the length of arg.
REPLACE(arg1, arg2, arg3) See below SSTRING if arg1 or arg3 has the type SSTRING, else CHAR with the maximum possible length of the result.
RIGHT(arg,len) arg: see below

len: positive numeric literal greater than 0 and less than or equal to 1333
SSTRING if arg has the type SSTRING, else CHAR with length len
RPAD(arg, len, src) arg: see below

len: positive numeric literal greater than 0 and less than or equal to 1333

src: character literal
SSTRING if arg has the type SSTRING, else CHAR with length len
RTRIM(arg, char) arg: see below

char: Character literal with length 1
SSTRING if arg has the type SSTRING, else CHAR with the length of arg.
SUBSTRING(arg, pos, len) arg: see below

pos and len: positive numeric literal not equal to zero
SSTRING if arg has the type SSTRING, else CHAR or NUMCwith length of at lest len
UPPER( arg ) See below, with the exception of NUMC, DATS and TIMS Data types of arg in the lenght of arg

 

ABAP CDS - Numeric Functions

The following table shows the possible numerical SQL functions in a CDS view, plus the requirements made on the arguments. The meaning of the functions can be found under SQL Functions for Numeric Values.

Function Valid Argument Types Result Type
ABS(arg) INT1, INT2, INT4, INT8, DEC, CURR, QUAN, FLTP Data type of arg
CEIL(arg) INT1, INT2, INT4, INT8, DEC, CURR, QUAN, FLTP INT4, INT8 (if arg is of type INT8)
DIV(arg1, arg2) INT1, INT2, INT4, INT8, DEC, CURR, QUAN without decimal places. Data type arg1, where DEC, CURR and QUAN are implemented after INT4
DIVISION(arg1, arg2, dec) arg1, arg2: INT1, INT2, INT4, INT8, DEC, CURR, QUAN

dec: Integer numeric literal greater than or equal to 0 and not greater than the maximum value of 6 and the length of arg2 plus the number of decimal places of arg1 plus 1
DEC with dec decimal places. The length of the result is the length of arg1 minus the decimal places in arg1 plus the decimal places in arg2 plus dec. This value must not be greater than 31.
FLOOR(arg) INT1, INT2, INT4, INT8, DEC, CURR, QUAN Data type of arg for the integer types, else DEC without decimal places
MOD(arg1, arg2) INT1, INT2, INT4, INT8 Data type of arg1
ROUND(arg, pos)arg: INT1, INT2, INT4, INT8, DEC, CURR, QUAN

pos: Literal, field of a data source or input parameter of type INT1, INT2, INT4
Data type of arg, where INT1 and INT2 are transformed to INT4