| Home • Tips • Tutorials • Forums • Certification Q's • Interview Q's • Jobs • Testimonials • Contact Us | ||||||||||||||||||||||||||||||||||||||||||||||
Document Categories:
What's New?
Contribute?Sample SpecsWhat's Hot? |
Using Sorted table and Index while processing Internal tablesBy Suresh Kumar Parvathaneni There
would have been many instances where we would have to process large entries in
an internal table with a WHERE condition. This article is intended to
demonstrate the comparison between three different methods in handling this
situation. First
Method:
The normal method used by most of us. Standard internal table processing using
WHERE condition Second
Method:
Same as above, but here we would be using the Sorted table Third
Method:
Sorted table and using the Index Following is the demo program illustrating the above three methods: REPORT ZINTERNAL_TABLE_OPERATIONS. * Program to find the best method in reading the internal tables * Author: Suresh Kumar Parvathaneni * Type declaration
TYPES:
BEGIN OF TY_MARA,
MATNR LIKE MARA-MATNR,
MTART LIKE MARA-MTART,
END OF TY_MARA.
* Internal table declaration
DATA:
T_MARA TYPE STANDARD TABLE OF TY_MARA,
T_MARA1 TYPE SORTED TABLE OF TY_MARA
WITH NON-UNIQUE KEY MTART.
* Variable declaration DATA: W_COUNTER TYPE I, W_RUNTIME1 TYPE I, W_RUNTIME2 TYPE I, W_TABIX LIKE SY-TABIX. * Table workarea definition DATA: WA_MARA TYPE TY_MARA. SELECT MATNR " Material Number
MTART " Material Type
FROM MARA
INTO TABLE T_MARA.
T_MARA1[] = T_MARA[]. * CASE 1: Processing internal table using LOOP..WHERE Condition GET RUN TIME FIELD W_RUNTIME1. LOOP AT T_MARA INTO WA_MARA WHERE MTART EQ 'FHMI'. ADD 1 TO W_COUNTER. ENDLOOP. GET RUN TIME FIELD W_RUNTIME2. * Calculate Runtime W_RUNTIME2 = W_RUNTIME2 - W_RUNTIME1. WRITE W_RUNTIME2. CLEAR W_COUNTER. * CASE 2: Using a Sorted table GET RUN TIME FIELD W_RUNTIME1. LOOP AT T_MARA1 INTO WA_MARA WHERE MTART EQ 'FHMI'. ADD 1 TO W_COUNTER. ENDLOOP. GET RUN TIME FIELD W_RUNTIME2. * Calculate Runtime W_RUNTIME2 = W_RUNTIME2 - W_RUNTIME1. WRITE W_RUNTIME2. CLEAR W_COUNTER. * CASE 3: Using INDEX on a sorted table GET RUN TIME FIELD W_RUNTIME1.
READ TABLE T_MARA1 INTO WA_MARA WITH KEY MTART = 'FHMI'.
IF SY-SUBRC EQ 0.
W_TABIX = SY-TABIX + 1.
ADD 1 TO W_COUNTER.
LOOP AT T_MARA1 INTO WA_MARA FROM W_TABIX.
IF WA_MARA-MTART NE 'FHMI'.
EXIT.
ENDIF.
ADD 1 TO W_COUNTER.
ENDLOOP.
ENDIF.
GET RUN TIME FIELD W_RUNTIME2.
* Calculate Runtime
W_RUNTIME2 = W_RUNTIME2 - W_RUNTIME1.
WRITE W_RUNTIME2.
Following
is the analysis report in microseconds, as per the data volume: Records:
21,390
Records:
132,693
|
|||||||||||||||||||||||||||||||||||||||||||||
|
Please send us your feedback/suggestions at webmaster@SAPTechnical.COM Home • Contribute • About Us • Privacy • Terms Of Use • Disclaimer • Safe • Companies: Advertise on SAPTechnical.COM | Post Job • Contact Us ©2006-2007 SAPTechnical.COM. All rights reserved. All
product names are trademarks of their respective companies. SAPTechnical.COM
is in no way affiliated with SAP AG. Graphic Design by Round the Bend Wizards |
||||||||||||||||||||||||||||||||||||||||||||||