ABAP常用小技巧-SQL语句

1.8 FOR ALL ENTRIES IN使用,保证内表非空,查询时需要查出表的主键,否则查询出来的数据可能会重复
如果指定的是内表中的重复键,则是不允许的,此处不确定,应该是没有影响,重复记录会自动删除.

尽量避免

SELECT UMLMC
INTO TABLE TD_MARC
FROM MARC
FOR ALL ENTRIES IN TD_MARA
WHERE MATNR = TD_MARA-MATNR.

推荐用法

SELECT MATNR WERKS UMLMC
INTO TABLE TD_MARC
FROM MARC
FOR ALL ENTRIES IN TD_MARA
WHERE MATNR = TD_MARA-MATNR.

 

1.8.1 主数据取得后,再取关联数据时,可以使用SELECT SINGLE,UP TO 1 ROWS等
尽量避免

SELECT MATNR
SPRAS
MAKTX
INTO TABLE TD_MAKT
FROM MAKT
FOR ALL ENTRIES IN LTD_VBAP
WHERE MATNR = LTD_VBAP-MATNR.

SORT TD_MAKT BY MATNR
SPRAS.

LOOP AT TD_VBAP INTO TH_VBAP.

READ TABLE TD_MAKT INTO TH_MAKT
WITH KEY MATNR = TH_VBAP-MATNR
SPRAS = SY-LANGU
BINARY SEARCH.

ENDLOOP.
推荐用法

LOOP AT TD_VBAP INTO TH_VBAP.

SELECT SINGLE MAKTX
INTO LW_MAKTX
FROM MAKT
WHERE MATNR = TH_VBAP-MATNR
AND SPRAS = SY-LANGU.

ENDLOOP

相关新闻

联系我们

联系我们

130-0752-1773

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

邮件:info@sapzx.com

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

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