ABAP常用小技巧-SQL语句
1.5 聚合函数的使用MAX、MIN、AVG、SUM、COUNT时
尽量避免
SELECT KWMENG
INTO TABLE TD_VBAP
FROM VBAP
WHERE VBELN IN S_VBELN.
CLEAR W_KWMENG.
LOOP AT TD_VBAP INTO TH_VBAP.
W_KWMENG = W_KWMENG + TH_VBAP-KWMENG.
ENDLOOP.
推荐用法
SELECT SUM( KWMENG )
INTO W_KWMENG
FROM VBAP
WHERE VBELN IN S_VBELN.
1.6 | WHERE 条件使用时的顺序 | |||||
优先级最高 | ‘=’ | |||||
‘≧’, ‘≦’, ‘>’, ‘<’ | ||||||
‘<>’ | ||||||
‘IN’ | ||||||
优先级最低 | ‘LIKE’ |
尽量避免
SELECT VKORG VTWEG SPART
INTO TABLE TD_VBAK
FROM VBAK
WHERE AUART <> ‘OR’
AND VKORG = P_VKORG
AND VBELN = 销售凭证.
推荐用法
SELECT VKORG VTWEG SPART
INTO TABLE TD_VBAK
FROM VBAK
WHERE VBELN = 销售凭证
AND VKORG = P_VKORG
AND AUART <> ‘OR’.