You are on page 1of 2

*&---------------------------------------------------------------------*

*& Report ZTEST_MATNR40


*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT ZTEST_MATNR40.

TYPES: BEGIN OF y_msta,


matnr TYPE msta-matnr,
ersda TYPE msta-ersda,
END OF y_msta.
data: t_msta TYPE STANDARD TABLE OF y_msta.

DATA: i_intern type y_msta OCCURS 0 WITH HEADER LINE.


DATA: i_internl type y_msta OCCURS 0 WITH HEADER LINE.
data: count type i.
data: lv_MaxI type i.
data: lv_MinI type i.
data: lv_RndI type i.

* How to get a more accurate clock time


DATA rtime TYPE I.
SET RUN TIME CLOCK RESOLUTION HIGH.
GET RUN TIME FIELD rtime.

FIELD-SYMBOLS: <fs_msta> TYPE y_msta.

count = 0.

* Range of random numbers


lv_MinI = 30000000.
lv_MaxI = 39999999.

write:/ sy-uzeit.

* Fill two internal tables with random numbers


do.
count = count + 1.

CALL FUNCTION 'QF05_RANDOM_INTEGER'


EXPORTING
ran_int_max = lv_MaxI
ran_int_min = lv_MinI
IMPORTING
ran_int = lv_RndI
EXCEPTIONS
invalid_input = 1
OTHERS = 2.

* Put data into internal table 1


i_intern-matnr = lv_RndI.
append i_intern.

* Put data into internal table 2


i_internl-matnr = lv_RndI.
append i_internl.

* Do we have enough data?


if count > 100000.
exit.
endif.
enddo.

write:/ sy-uzeit.

sort i_intern by matnr.


sort i_internl by matnr.

write:/ sy-uzeit.

* Loop on one internal table while reading the other


loop at i_internl.
READ TABLE i_intern ASSIGNING <fs_msta>
WITH KEY matnr = i_internl-matnr.
endloop.

write:/ sy-uzeit.

* Loop on one internal table while reading the other - Now with Binary Search
loop at i_internl.
READ TABLE i_intern ASSIGNING <fs_msta>
WITH KEY matnr = i_internl-matnr BINARY SEARCH.
endloop.

write:/ sy-uzeit.

DESCRIBE TABLE I_INTERN.


WRITE:/ 'Table Key Length: ', SY-TLENG.

You might also like