TYPES:BEGIN OF TYP_DATA,
MATNR TYPE MATNR,
WERKS TYPE WERKS_D,
LGORT TYPE LGORT_D,
LABST TYPE LABST,
END OF TYP_DATA.
DATA: GT_DATA TYPE TABLE OF TYP_DATA,
LW_DATA TYPE TYP_DATA.
DATA:LV_TIME_BEG TYPE TIMESTAMPL,
LV_TIME_END TYPE TIMESTAMPL.
DATA L_TEXT TYPE TIMESTAMPL.
DATA L_MESSAGE TYPE CHAR100.
DATA LV_TABIX TYPE I.
SELECT MATNR FROM MARA
INTO TABLE @DATA(LT_MARA).
SELECT MATNR,WERKS,LGORT,LABST FROM MARD
INTO TABLE @DATA(LT_MARD).
GET TIME STAMP FIELD LV_TIME_BEG.
CLEAR GT_DATA.
LOOP AT LT_MARA INTO DATA(LS_MARA).
LOOP AT LT_MARD INTO DATA(LS_MARD) WHERE MATNR = LS_MARA-MATNR.
MOVE-CORRESPONDING LS_MARA TO LW_DATA.
MOVE-CORRESPONDING LS_MARD TO LW_DATA.
APPEND LW_DATA TO GT_DATA.
ENDLOOP.
ENDLOOP.
GET TIME STAMP FIELD LV_TIME_END.
L_TEXT = LV_TIME_END - LV_TIME_BEG .
DESCRIBE TABLE GT_DATA LINES DATA(L_TABIX).
L_MESSAGE = |优化前内表条目{ L_TABIX },执行时间{ L_TEXT }|.
WRITE: L_MESSAGE.
GET TIME STAMP FIELD LV_TIME_BEG.
SORT LT_MARD BY MATNR.
CLEAR GT_DATA.
LOOP AT LT_MARA INTO LS_MARA.
CLEAR LV_TABIX.
READ TABLE LT_MARD TRANSPORTING NO FIELDS WITH KEY MATNR = LS_MARA-MATNR BINARY SEARCH.
IF SY-SUBRC = 0.
LV_TABIX = SY-TABIX.
LOOP AT LT_MARD INTO LS_MARD FROM LV_TABIX.
IF LS_MARA-MATNR NE LS_MARD-MATNR.
EXIT.
ENDIF.
MOVE-CORRESPONDING LS_MARA TO LW_DATA.
MOVE-CORRESPONDING LS_MARD TO LW_DATA.
APPEND LW_DATA TO GT_DATA.
ENDLOOP.
ENDIF.
ENDLOOP.
GET TIME STAMP FIELD LV_TIME_END.
L_TEXT = LV_TIME_END - LV_TIME_BEG .
DESCRIBE TABLE GT_DATA LINES L_TABIX.
L_MESSAGE = |优化后内表条目{ L_TABIX },执行时间{ L_TEXT }|.
WRITE: / L_MESSAGE.
12-30
994
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)