Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

Need some input on comparision btw sorted and std table.

Hi,

Just a small comparision on using standard table, sorted table, and sorted table using index in a loop with where conditions.

I just ran this report to find out the time taken and it is quite surprising. Case 3 of the program is quite faster than case2 and of course very fast than case1. any inputs on how this is possible???

output value :

try 1: 674, 192, 147 for 100 entries.

try 2: 603, 53 , 6 for 20 entries.

*C-- Small report to compare sorted and standard table.

REPORT zloopcompare.

TYPES : BEGIN OF tp_marc,

werks TYPE marc-werks,

matnr TYPE marc-matnr,

END OF tp_marc.

DATA : t_marc TYPE STANDARD TABLE OF tp_marc.

DATA : t_marc1 TYPE SORTED TABLE OF tp_marc

WITH NON-UNIQUE KEY werks matnr.

DATA : wa_marc TYPE tp_marc.

DATA : p1 TYPE i,

p2 TYPE i.

DATA : l_tabix TYPE sy-tabix.

DATA : count TYPE i.

PARAMETERS : p_werks TYPE marc-werks OBLIGATORY.

SELECT werks matnr FROM marc

INTO TABLE t_marc1

UP TO 1000 ROWS.

t_marc[] = t_marc1[].

*----


*Case1 - standard table with where condition.

GET RUN TIME FIELD p1.

LOOP AT t_marc INTO wa_marc

WHERE werks EQ p_werks.

ENDLOOP.

GET RUN TIME FIELD p2.

p2 = p2 - p1.

WRITE : / p2.

*----


*Case2- sorted table sorted as per the where condition.

GET RUN TIME FIELD p1.

LOOP AT t_marc1 INTO wa_marc

WHERE werks EQ p_werks.

ENDLOOP.

GET RUN TIME FIELD p2.

p2 = p2 - p1.

WRITE : / p2.

*----


*Case3- using index to get faster access.

GET RUN TIME FIELD p1.

READ TABLE t_marc1 INTO wa_marc WITH KEY werks = p_werks.

IF sy-subrc EQ 0.

l_tabix = sy-tabix + 1.

LOOP AT t_marc1 INTO wa_marc FROM l_tabix.

IF wa_marc-werks NE p_werks.

EXIT.

ENDIF.

ENDLOOP.

ENDIF.

GET RUN TIME FIELD p2.

p2 = p2 - p1.

WRITE : / p2.

Tags:
Former Member
Not what you were looking for? View more on this topic or Ask a question