ABAP顾问
分类:
2007-07-06 16:29:58
REPORT z_barry_test_loop .
TYPES: BEGIN OF t_tab1,
flag ,
vbeln TYPE vbap-vbeln,
posnr TYPE vbap-posnr,
netwr TYPE vbap-netwr,
END OF t_tab1.
TYPES: BEGIN OF t_tab2,
vbeln TYPE vbap-vbeln,
posnr TYPE vbap-posnr,
END OF t_tab2.
DATA : it_tab1 TYPE STANDARD TABLE OF t_tab1 INITIAL SIZE 0,
wa_tab1 TYPE t_tab1.
DATA : it_tab2 TYPE STANDARD TABLE OF t_tab2 INITIAL SIZE 0,
wa_tab2 TYPE t_tab2.
*DATA : it_tab2 TYPE SORTED TABLE OF t_tab2 WITH UNIQUE KEY vbeln posnr
* INITIAL SIZE 0,
* wa_tab2 TYPE t_tab2.
* 方法1
DATA : it_tab11 TYPE SORTED TABLE OF t_tab1 WITH UNIQUE KEY vbeln posnr
INITIAL SIZE 0,
wa_tab11 TYPE t_tab1.
DATA : it_tab2s TYPE SORTED TABLE OF t_tab2 WITH UNIQUE KEY vbeln posnr
INITIAL SIZE 0,
wa_tab2s TYPE t_tab2.
* 方法2
DATA : it_tab12 TYPE HASHED TABLE OF t_tab1 WITH UNIQUE KEY vbeln posnr
INITIAL SIZE 0,
wa_tab12 TYPE t_tab1.
DATA : it_tab2h TYPE HASHED TABLE OF t_tab2 WITH UNIQUE KEY vbeln posnr
INITIAL SIZE 0,
wa_tab2h TYPE t_tab2.
* 方法3
DATA : it_tab13 TYPE STANDARD TABLE OF t_tab1 INITIAL SIZE 0,
wa_tab13 TYPE t_tab1.
* 方法4
DATA : it_tab14 TYPE STANDARD TABLE OF t_tab1 INITIAL SIZE 0,
wa_tab14 TYPE t_tab1.
* 方法5
DATA : it_tab15 TYPE STANDARD TABLE OF t_tab1 INITIAL SIZE 0,
wa_tab15 TYPE t_tab1.
* 方法6
DATA : it_tab16 TYPE HASHED TABLE OF t_tab1 WITH UNIQUE KEY vbeln posnr
INITIAL SIZE 0,
wa_tab16 TYPE t_tab1.
* 方法7
DATA : it_tab17 TYPE HASHED TABLE OF t_tab1 WITH UNIQUE KEY vbeln posnr
INITIAL SIZE 0,
wa_tab17 TYPE t_tab1.
DATA :
v_t1 TYPE i,
v_t2 TYPE i,
v_time1 TYPE i,
v_time2 TYPE i,
v_time4 TYPE i,
v_time5 TYPE i,
v_time6 TYPE i,
v_time7 TYPE i,
v_time3 TYPE i.
START-OF-SELECTION.
PERFORM frm_set_data.
PERFORM frm_edit_data.
PERFORM frm_output_data.
*&---------------------------------------------------------------------*
*& Form FRM_SET_DATA
*&---------------------------------------------------------------------*
FORM frm_set_data.
SELECT vbeln posnr netwr INTO CORRESPONDING FIELDS OF TABLE it_tab1
FROM vbap
UP TO 4000 ROWS.
SELECT vbeln posnr INTO CORRESPONDING FIELDS OF TABLE it_tab2
FROM vbap
UP TO 3996 ROWS
where vbeln > '0005000000'.
ENDFORM. "FRM_SET_DATA
*---------------------------------------------------------------------*
* FORM FRM_EDIT_DATA *
*---------------------------------------------------------------------*
* ........ *
*---------------------------------------------------------------------*
FORM frm_edit_data.
SORT it_tab1 ASCENDING BY vbeln posnr.
SORT it_tab2 ASCENDING BY vbeln posnr.
DATA v_i TYPE i.
FIELD-SYMBOLS:
* 方法1
* SORT it_tab11 ASCENDING BY vbeln posnr.
GET RUN TIME FIELD v_t1.
it_tab2s = it_tab2.
it_tab11 = it_tab1.
v_i = 1.
LOOP AT it_tab2s ASSIGNING
LOOP AT it_tab11 ASSIGNING
IF
v_i = v_i + 1.
ELSE.
EXIT.
ENDIF.
ENDLOOP.
ENDLOOP.
DELETE it_tab11 WHERE flag = 'X'.
GET RUN TIME FIELD v_t2.
v_time1 = v_t2 - v_t1.
* 方法2
* SORT it_tab11 ASCENDING BY vbeln posnr.
GET RUN TIME FIELD v_t1.
it_tab12 = it_tab1.
it_tab2h = it_tab2.
LOOP AT it_tab2h ASSIGNING
LOOP AT it_tab12 ASSIGNING
IF
DELETE TABLE it_tab12 FROM
ELSE.
EXIT.
ENDIF.
ENDLOOP.
ENDLOOP.
GET RUN TIME FIELD v_t2.
v_time2 = v_t2 - v_t1.
* 方法3
GET RUN TIME FIELD v_t1.
it_tab13 = it_tab1.
SORT it_tab13 ASCENDING BY vbeln posnr.
v_i = 1.
LOOP AT it_tab2 INTO wa_tab2.
LOOP AT it_tab13 INTO wa_tab13 FROM v_i.
IF wa_tab13-vbeln = wa_tab2-vbeln AND
wa_tab13-posnr = wa_tab2-posnr.
wa_tab13-flag = 'X'.
MODIFY it_tab13 FROM wa_tab13.
v_i = v_i + 1.
ELSE.
EXIT.
ENDIF.
ENDLOOP.
ENDLOOP.
DELETE it_tab13 WHERE flag = 'X'.
GET RUN TIME FIELD v_t2.
v_time3 = v_t2 - v_t1.
** 方法4
* GET RUN TIME FIELD v_t1.
* it_tab14 = it_tab1.
* LOOP AT it_tab2 INTO wa_tab2.
* DELETE it_tab14 WHERE vbeln = wa_tab2-vbeln AND
* posnr = wa_tab2-posnr.
* ENDLOOP.
* GET RUN TIME FIELD v_t2.
* v_time4 = v_t2 - v_t1.
** 方法5
* GET RUN TIME FIELD v_t1.
* it_tab15 = it_tab1.
* LOOP AT it_tab15 INTO wa_tab1.
* READ TABLE it_tab2 WITH KEY vbeln = wa_tab1-vbeln
* posnr = wa_tab1-posnr
* TRANSPORTING NO FIELDS .
* IF sy-subrc = 0.
* DELETE it_tab15.
* ENDIF.
* ENDLOOP.
* GET RUN TIME FIELD v_t2.
* v_time5 = v_t2 - v_t1.
* 方法6
GET RUN TIME FIELD v_t1.
it_tab16 = it_tab1.
it_tab2h = it_tab2.
LOOP AT it_tab16 INTO wa_tab16.
READ TABLE it_tab2h WITH TABLE KEY vbeln = wa_tab16-vbeln
posnr = wa_tab16-posnr
TRANSPORTING NO FIELDS .
IF sy-subrc = 0.
DELETE TABLE it_tab16 FROM wa_tab16.
ENDIF.
ENDLOOP.
GET RUN TIME FIELD v_t2.
v_time6 = v_t2 - v_t1.
* 方法7
GET RUN TIME FIELD v_t1.
it_tab17 = it_tab1.
it_tab2h = it_tab2.
LOOP AT it_tab17 ASSIGNING
READ TABLE it_tab2h WITH TABLE KEY vbeln =
posnr =
TRANSPORTING NO FIELDS .
IF sy-subrc = 0.
DELETE TABLE it_tab17 FROM
ENDIF.
ENDLOOP.
GET RUN TIME FIELD v_t2.
v_time7 = v_t2 - v_t1.
ENDFORM. "FRM_EDIT_DATA
*---------------------------------------------------------------------*
* FORM FRM_OUTPUT_DATA *
*---------------------------------------------------------------------*
* ........ *
*---------------------------------------------------------------------*
FORM frm_output_data.
DATA n TYPE i.
WRITE : '方法1',
'RUNTIME:',
v_time1.
LOOP AT it_tab11 INTO wa_tab11.
WRITE : / wa_tab11-vbeln,
wa_tab11-posnr,
wa_tab11-netwr.
IF sy-tabix > 4.
WRITE / '...'.
EXIT.
ENDIF.
ENDLOOP.
ULINE.
WRITE : '方法2',
'RUNTIME:',
v_time2.
n = 0.
LOOP AT it_tab12 INTO wa_tab12.
WRITE : / wa_tab12-vbeln,
wa_tab12-posnr,
wa_tab12-netwr.
n = n + 1 .
IF n > 4.
WRITE / '...'.
EXIT.
ENDIF.
ENDLOOP.
ULINE.
WRITE : '方法3',
'RUNTIME:',
v_time3.
LOOP AT it_tab13 INTO wa_tab13.
WRITE : / wa_tab13-vbeln,
wa_tab13-posnr,
wa_tab13-netwr.
IF sy-tabix > 4.
WRITE / '...'.
EXIT.
ENDIF.
ENDLOOP.
ULINE.
WRITE : '方法4',
'RUNTIME:',
v_time4.
LOOP AT it_tab14 INTO wa_tab14.
WRITE : / wa_tab14-vbeln,
wa_tab14-posnr,
wa_tab14-netwr.
IF sy-tabix > 4.
WRITE / '...'.
EXIT.
ENDIF.
ENDLOOP.
ULINE.
WRITE : '方法5',
'RUNTIME:',
v_time5.
LOOP AT it_tab15 INTO wa_tab15.
WRITE : / wa_tab15-vbeln,
wa_tab15-posnr,
wa_tab15-netwr.
IF sy-tabix > 4.
WRITE / '...'.
EXIT.
ENDIF.
ENDLOOP.
ULINE.
WRITE : '方法6',
'RUNTIME:',
v_time6.
n = 0.
LOOP AT it_tab16 INTO wa_tab16.
WRITE : / wa_tab16-vbeln,
wa_tab16-posnr,
wa_tab16-netwr.
n = n + 1.
IF n > 4.
WRITE / '...'.
EXIT.
ENDIF.
ENDLOOP.
ULINE.
WRITE : '方法7',
'RUNTIME:',
v_time7.
n = 0.
LOOP AT it_tab17 INTO wa_tab17.
WRITE : / wa_tab17-vbeln,
wa_tab17-posnr,
wa_tab17-netwr.
n = n + 1.
IF n > 4.
WRITE / '...'.
EXIT.
ENDIF.
ENDLOOP.
ENDFORM. "FRM_OUTPUT_DATA