REPORT ZDELETE_COMPARE.
* Jerry 2016-12-4 20:28PM - what is result ? :( on Aircraft from Frankfort to Beijing
PARAMETERS: num type i OBLIGATORY DEFAULT 100.
types: begin of ty_product,
id type comm_product-product_id,
text type string,
end of ty_product.
data: lt_product type STANDARD TABLE OF ty_product,
lt_product1 LIKE lt_product,
lt_compare type STANDARD TABLE OF comm_product-product_id,
lt_range type RANGE OF comm_product-product_id,
lv_start TYPE i,
lv_end TYPE i.
FIELD-SYMBOLS: TYPE ty_product,
LIKE LINE OF lt_range.
START-OF-SELECTION.
PERFORM generate_main_tab.
PERFORM solution1.
PERFORM solution2.
ASSERT lt_product = lt_product1.
FORM generate_main_tab.
DO num TIMES.
APPEND INITIAL LINE TO lt_product ASSIGNING .
-id = sy-index.
-text = sy-index.
APPEND INITIAL LINE TO lt_product1 ASSIGNING .
IF ( sy-index MOD 2 = 0 ).
APPEND sy-index TO lt_compare.
ENDIF.
ENDDO.
ENDFORM.
FORM solution1.
GET RUN TIME FIELD lv_start.
LOOP AT lt_product ASSIGNING FIELD-SYMBOL().
READ TABLE lt_compare WITH KEY table_line = -id TRANSPORTING NO FIELDS.
IF sy-subrc <> 0.
DELETE TABLE lt_product FROM .
ENDLOOP.
GET RUN TIME FIELD lv_end.
lv_end = lv_end - lv_start.
WRITE: / 'Solution1: ' , lv_end COLOR COL_NEGATIVE.
FORM solution2.
LOOP AT lt_compare ASSIGNING FIELD-SYMBOL().
APPEND INITIAL LINE TO lt_range ASSIGNING .
-low = .
-option = 'EQ'.
-sign = 'I'.
DELETE lt_product1 WHERE id NOT IN lt_range.
WRITE: / 'Solution2: ' , lv_end COLOR COL_NEGATIVE.