ABAP常用小技巧-SQL语句

1.9 LOOP循环内尽量减少对数据库的访问操作(第一种情况会多次去TVKBT表中取相同的记录)
尽量避免

LOOP AT TD_VBAK INTO TH_VBAK.

CLEAR : TH_OUT.

SELECT SINGLE BEZEI
INTO TH_OUT-BEZEI
FROM TVKBT
WHERE SPRAS = SY-SPRAS
AND VKBUR = TH_VBAK-VKBUR.

TH_OUT-VBELN = TH_VBAK-VBELN.
APPEND TH_OUT TO TD_OUT.

ENDLOOP.

推荐用法

LOOP AT TD_VBAK INTO TH_VBAK.

CLEAR : TH_OUT.

CLEAR : TH_TVKBT.
READ TABLE TD_TVKBT INTO TH_TVKBT
WITH KEY VKBUR = TH_VBAK-VKBUR.

IF SY-SUBRC <> 0.

SELECT SINGLE BEZEI
INTO TH_TVKBT-BEZEI
FROM TVKBT
WHERE SPRAS = SY-SPRAS
AND VKBUR = TH_VBAK-VKBUR.

TH_TVKBT-VKBUR = TH_VBAK-VKBUR.
APPEND TH_TVKBT TO TD_TVKBT.

ELSE.

TH_OUT-BEZEI = TH_TVKBT-BEZEI.

ENDIF.

TH_OUT-VBELN = TH_VBAK-VBELN.
APPEND TH_OUT TO TD_OUT.

ENDLOOP.

相关新闻

联系我们

联系我们

130-0752-1773

在线咨询:点击这里给我发消息

邮件:info@sapzx.com

工作时间:周一至周五9:00-18:00,节假日正常休息

关注微信
关注微信
分享本页
返回顶部