Created by Jerry Wang on May 06, 2014

For the read access of a large number of database tables, you can use SELECT to read all data into the internal table at one time or use OPEN CURSOR to read the data in blocks according to the package size.

When comm_product contains the number of records as shown below,

Using the following report tests, we found that whether package size is specified as 100,1000, or 10000, the two approaches are very close in terms of execution time.

Then compare memory consumption:

Create a memory snapshot before executing solution1:



Create a memory snapshot after executing solution2:

Compare two snapshots using the tcode S_MEMORY_INSPECTOR: Outside the chain picture archiving failure (img – pD0vympq – 1562038087646) (user-images.githubusercontent.com/5669954/272…)”

Comparison shows that the memory footprint of Solution2 is much smaller than that of Solution1, because Solution1 uses an internal table to store 3.78 million products, while solution2 processes in batches. Its internal table only needs to store information equal to package size of products.

PARAMETERS: pac type i OBLIGATORY DEFAULT 100. data: lt_product TYPE STANDARD TABLE OF comm_product, lt_name1 TYPE STANDARD TABLE OF comm_product-upname, lt_name2 TYPE STANDARD TABLE OF comm_product-upname, lv_start TYPE i, lv_end type i. data: ll type SORTED TABLE OF string WITH UNIQUE KEY table_line. FORM solution1. GET RUN TIME FIELD lv_start. SELECT * INTO TABLE lt_product FROM comm_product. LOOP AT lt_product ASSIGNING FIELD-SYMBOL(<product>). INSERT <product>-upname INTO TABLE lt_name1. ENDLOOP. GET RUN TIME FIELD lv_end. lv_end = lv_end - lv_start. WRITE: / 'Solution1: ' , lv_end COLOR COL_NEGATIVE. ENDFORM. FORM solution2. DATA:lv_cursor TYPE cursor, lt_selection TYPE STANDARD TABLE OF comm_product. GET RUN TIME FIELD lv_start. OPEN CURSOR lv_cursor FOR SELECT * FROM comm_product. DO. FETCH NEXT CURSOR lv_cursor INTO TABLE lt_selection PACKAGE SIZE pac. IF sy-subrc NE 0. CLOSE CURSOR lv_cursor. EXIT. ENDIF. LOOP AT lt_selection ASSIGNING FIELD-SYMBOL(<product2>). INSERT <product2>-upname INTO TABLE lt_name2. ENDLOOP. CLEAR: lt_selection. FREE: lt_selection. ENDDO. GET RUN TIME FIELD lv_end. lv_end = lv_end - lv_start. WRITE: / 'Solution2: ', lv_end COLOR COL_NEGATIVE. ENDFORM. START-OF-SELECTION. PERFORM solution1. PERFORM solution2. ASSERT lt_name1 = lt_name2.Copy the code