JOIN 查询中选定列的条件字段
Conditional field by selected column in JOIN query
目前我的查询看起来像这样
SELECT CSKS~KOSTL CSKS~DATBI CSKS~NAME1 CSKS~KOSAR CSKS~VERAK CEPC~PRCTR CEPC~NAME3 CEPC~NAME4 UP TO X ROWS
FROM CSKS INNER JOIN CEPC ON ( CSKS~PRCTR = CEPC~PRCTR AND CSKS~KOKRS = CEPC~KOKRS )
INTO gwa_itab
WHERE CSKS~BUKRS = cocode AND
CSKS~KOKRS = cntrarea AND
CSKS~DATBI > d1.
APPEND gwa_itab TO it_itab.
ENDSELECT.
我如何修改它,以便它可以看到成本中心以什么数字开头,例如,如果它们以 1 开头,则将给定字符串 EG 插入已经在内部 table 中的位置列: 华盛顿
SELECT CSKS~KOSTL CSKS~DATBI CSKS~NAME1 CSKS~KOSAR CSKS~VERAK CEPC~PRCTR CEPC~NAME3 CEPC~NAME4 UP TO X ROWS
FROM CSKS INNER JOIN CEPC ON ( CSKS~PRCTR = CEPC~PRCTR AND CSKS~KOKRS = CEPC~KOKRS )
INTO gwa_itab
WHERE CSKS~BUKRS = cocode AND
CSKS~KOKRS = cntrarea AND
CSKS~DATBI > d1.
SHIFT gwa_itab-kostl LEFT DELETING LEADING '0'.
IF gwa_itab-kostl(1) = 1.
gwa_itab-location = 'Washington'.
ENDIF.
APPEND gwa_itab TO it_itab.
CLEAR: gwa_itab.
ENDSELECT.
在最近的 7.50+ 版本中,您可以在没有 SELECT 循环的情况下以单个 select 结尾:
SELECT ks~kostl, ks~datbi, ks~name1, ks~kosar, ks~verak, pc~prctr, pc~name3, pc~name4,
CASE SUBSTRING( ks~kostl, 1, 1 )
WHEN '1' THEN 'Washington'
END AS location
FROM csks AS ks
INNER JOIN cepc AS pc
ON ks~prctr = pc~prctr AND ks~kokrs = pc~kokrs
WHERE ks~bukrs = cocode AND
ks~kokrs = cntrarea AND
ks~datbi > d1
INTO TABLE @DATA(it_itab)
UP TO 100 ROWS.
目前我的查询看起来像这样
SELECT CSKS~KOSTL CSKS~DATBI CSKS~NAME1 CSKS~KOSAR CSKS~VERAK CEPC~PRCTR CEPC~NAME3 CEPC~NAME4 UP TO X ROWS
FROM CSKS INNER JOIN CEPC ON ( CSKS~PRCTR = CEPC~PRCTR AND CSKS~KOKRS = CEPC~KOKRS )
INTO gwa_itab
WHERE CSKS~BUKRS = cocode AND
CSKS~KOKRS = cntrarea AND
CSKS~DATBI > d1.
APPEND gwa_itab TO it_itab.
ENDSELECT.
我如何修改它,以便它可以看到成本中心以什么数字开头,例如,如果它们以 1 开头,则将给定字符串 EG 插入已经在内部 table 中的位置列: 华盛顿
SELECT CSKS~KOSTL CSKS~DATBI CSKS~NAME1 CSKS~KOSAR CSKS~VERAK CEPC~PRCTR CEPC~NAME3 CEPC~NAME4 UP TO X ROWS
FROM CSKS INNER JOIN CEPC ON ( CSKS~PRCTR = CEPC~PRCTR AND CSKS~KOKRS = CEPC~KOKRS )
INTO gwa_itab
WHERE CSKS~BUKRS = cocode AND
CSKS~KOKRS = cntrarea AND
CSKS~DATBI > d1.
SHIFT gwa_itab-kostl LEFT DELETING LEADING '0'.
IF gwa_itab-kostl(1) = 1.
gwa_itab-location = 'Washington'.
ENDIF.
APPEND gwa_itab TO it_itab.
CLEAR: gwa_itab.
ENDSELECT.
在最近的 7.50+ 版本中,您可以在没有 SELECT 循环的情况下以单个 select 结尾:
SELECT ks~kostl, ks~datbi, ks~name1, ks~kosar, ks~verak, pc~prctr, pc~name3, pc~name4,
CASE SUBSTRING( ks~kostl, 1, 1 )
WHEN '1' THEN 'Washington'
END AS location
FROM csks AS ks
INNER JOIN cepc AS pc
ON ks~prctr = pc~prctr AND ks~kokrs = pc~kokrs
WHERE ks~bukrs = cocode AND
ks~kokrs = cntrarea AND
ks~datbi > d1
INTO TABLE @DATA(it_itab)
UP TO 100 ROWS.