1.拼接字段(注意不能和 FOR ALL ENTRTIES IN 一起使用)
第一种: concat( A , 字段 ) AS 别名 — A 可以为自定义字段
第二种: ( C && B ) AS 别名 ---- 注意,B与C都是需要为char 类型才能使用这个
2.截取字段
substring( fldate,1,4 ) AS fldate,
SELECT carrid, "航线
connid, "航班号
fldate, "日期
planetype "飞机类型
FROM sflight
WHERE connid = '1'
INTO TABLE @DATA(lt_sflight).
cl_demo_output=>display( lt_sflight ).
SELECT carrid, "航线
connid, "航班号
substring( fldate,1,4 ) AS fldate, "日期截取年份
( 'CHAR类型拼接' && planetype ) AS con,
concat( 'CONCAT拼接' , planetype ) AS planetype
FROM sflight
WHERE connid = '1'
INTO TABLE @DATA(lt_sflight_contrast).
cl_demo_output=>display( lt_sflight_contrast ).
字符串截取案例
IF cb_01 EQ 'X' .
LOOP AT gt_out INTO gs_out .
SELECT SINGLE belnr
FROM bkpf AS t1
WHERE substring( t1~awkey , 1, 10 ) = @gs_out-mblnr
AND substring( t1~awkey , 11, 4 ) = @gs_out-mjahr
INTO @gs_out-belnr .
MODIFY gt_out from gs_out .
ENDLOOP .
ENDIF .
"1.截取字符
select t1~matnr,
werks,
charg,
cuobj
from mchb as t1
left outer join inob as t2
on substring( t2~objek , 1, 18 ) = t1~matnr "1-18位 是物料号
and substring( t2~objek, 41,10 ) = t1~charg "41~50位 是批次
where t2~klart = '023'
into corresponding fields of table @lt_mchb.
注意: into corresponding fields of table @lt_mchb. 必须放在最后面
2 replace ,但是B不能为空白 语法和1一样
REPLACE( bseg~zuonr , 'A','B' ) 替换成B
3 取掉字符(其他语言是去空格,这个可以去掉去空格,去a都可以)
where LTRIM( RTRIM( bseg~zuonr,' ' ),' ' ) = '暂存'
另外:新增或者强转类型CAST
SELECT carrid, "航线
connid, "航班号
substring( fldate,1,4 ) AS fldate, "日期截取年份
CAST( planetype AS CHAR( 20 ) ) AS con, "把planetype的值取出来,放在 con字段中。con字段为 CHAR 类型,长度为20
CAST( @space AS CHAR( 13 ) ) AS zchar "新增为char 13的字段
FROM sflight
WHERE connid = '1'
INTO TABLE @DATA(lt_sflight_contrast).
**select 语句中字段的加减乘除(case when语句)
SELECT
a~hkont,
a~lkorr,
CASE WHEN a~hkont = a~lkorr THEN @abap_true ELSE @abap_false
END AS del_flag
FROM t030h AS a
INTO TABLE @DATA(gt_tab).