ABAP 新特性 - SELECT 语句非DB中字段创建(类型、长度、初始值等)和SQL函数使用
SELECT BELNR, RYEAR, RBUKRS, CAST( CONCAT( BELNR,RYEAR ) AS CHAR( 20 ) ) AS OBJ_KEY, CAST( @SPACE AS CHAR( 10 ) ) AS EXT_FD01 FROM ACDOCA WHERE RBUKRS IN @S_BUKRS AND RYEAR = '2018' INTO TABLE @DATA(LT_ACDOCA).
OBJ_KEY 和 EXT_FD01即为新增字段
CAST( CONCAT( BELNR,RYEAR ) AS CHAR( 20 ) ) AS OBJ_KEY,
CAST( @SPACE AS CHAR( 10 ) ) AS EXT_FD01
OBJ_KEY 类型CHAR 长度20 初始值= CONCAT( BELNR,RYEAR )
EXT_FD01 类型CHAR 长度10 初始值=SPACE 。
-----------------------------------------------------------------------------------------
此外
除了CAST、CONCAT之外,ROUND, LPAD(在ABAP中的语法格式分别为LPAD( arg, len, src );RPAD( arg, len, src ) ,三个参数分别指定了操作字段;填充后值的长度;填充字符), LENGTH, REPLACE, RIGHT, RTRIM, SUBSTRING等函数也可以使用。
杂项函数COALESCE 也可以使用,但是最多255个表达式
“示例: SELECT CONCAT( CONCAT( carrid, LPAD( carrname,21,’ ‘ ) ), LPAD( url,40,’ ‘ ) ) AS line FROM scarr INTO TABLE @DATA(result).