本文主要介绍SAP ABAP中OPEN SQL的FOR ALL ENTRIES IN语句
语句介绍
使用FOR ALL ENTRIES IN语句将不能使用join的聚集表(例如BSEG)或者需要使用select的内表与内表串联。
代码示例
SELECT...FOR ALL ENTRIES IN <itab> WHERE <condition>
案例代码演示
案例简介:由于BESG不能和BSIS做内联,所以先将BSIS要获取的内容放到内表中,然后用FOR ALL ENTRIES IN来串联
REPORT ZWYZTEST_FOR_MANGO. DATA:GT_BSEG TYPE TABLE OF BSEG. DATA:GT_BSIS TYPE TABLE OF BSIS. DATA:GS_BSIS TYPE BSIS. SELECT * FROM BSEG INTO CORRESPONDING FIELDS OF TABLE GT_BSEG UP TO 10 ROWS. SELECT * FROM BSIS INTO CORRESPONDING FIELDS OF TABLE GT_BSIS FOR ALL ENTRIES IN GT_BSEG WHERE BUKRS = GT_BSEG-BUKRS AND BELNR = GT_BSEG-BELNR AND GJAHR = GT_BSEG-GJAHR AND BUZEI = GT_BSEG-BUZEI. LOOP AT GT_BSIS INTO GS_BSIS. WRITE:/ GS_BSIS-BUKRS,GS_BSIS-BELNR,GS_BSIS-GJAHR,GS_BSIS-BUZEI. ENDLOOP.
代码效果展示
1. BSEG数据库表数据
2. BSIS数据库表数据
从上面图片中可以看出,成功的将两个表中相同数据的数据项取出来并且输出了!