‎2005 Dec 08 4:07 PM
Hi,
I thought of impelementing loop at ITAB using read statements, Here it goes.
REPORT Z_LOOP_IMPROVE.
DATA : T_OUTPUT TYPE STANDARD TABLE OF MARC WITH HEADER LINE,
L_TABIX TYPE SY-TABIX.
DEFINE ILOOP.
DO.
IF SY-INDEX EQ '1'.
READ TABLE &1 WITH KEY &2 = &3 BINARY SEARCH.
IF SY-SUBRC <> 0.
EXIT.
ENDIF.
ELSE.
L_TABIX = SY-TABIX + 1.
READ TABLE &1 INDEX L_TABIX.
IF SY-SUBRC NE 0 OR &1-&2 NE &3.
EXIT.
ENDIF.
ENDIF.
END-OF-DEFINITION.
DEFINE IENDLOOP.
ENDDO.
END-OF-DEFINITION.
DATA : T1 TYPE I, T2 TYPE I.
SELECT * FROM MARC INTO TABLE T_OUTPUT.
SORT T_OUTPUT BY WERKS.
GET RUN TIME FIELD T1.
ILOOP T_OUTPUT WERKS '0001'.
WRITE : / T_OUTPUT-MATNR, T_OUTPUT-WERKS.
IENDLOOP.
GET RUN TIME FIELD T2.
T2 = T2 - T1.
WRITE : / T2.
*C----
But sadly it takes more time than a normal loop with
where condition.
can anyone suggest some ideas to improve execution speed?
‎2005 Dec 08 4:20 PM
Hi!
As long as a sorted table is out of scope, that is the correct way.
But maybe the macro-handling adds more time then simple loop where.
Instead of second read, you can also use a loop at itab from sy-index (in explicit programming). Personally I would avoid macros anyway, but making a function module will need extra time, too.
Regards,
Christian
‎2005 Dec 08 4:16 PM
‎2005 Dec 08 4:18 PM
You can use a binary read to get the first record. Then read each record sequentially until you have proccessed all the records that meet your critera. You will have to have the internal table sorted so that the binary search and subsequent reads will work:
READ TABLE itab WITH KEY
field = whatever
BINARY SEARCH.
IF sy-subrc = 0.
itab_index = sy-tabix.
DO.
IF sy-subrc = 0.
IF itab_data-field = whatever
itab_index = itab_index + 1.
READ TABLE itab_data INDEX itab_index.
ELSE.
EXIT.
ENDIF.
ELSE.
EXIT.
ENDIF.
ENDDO.
ENDIF.Rob
‎2005 Dec 08 7:48 PM
Note that this is useful only if both tables are large; otherwise, it's not worth the extra programming aggravation.
Rob
‎2005 Dec 08 4:20 PM
Hi!
As long as a sorted table is out of scope, that is the correct way.
But maybe the macro-handling adds more time then simple loop where.
Instead of second read, you can also use a loop at itab from sy-index (in explicit programming). Personally I would avoid macros anyway, but making a function module will need extra time, too.
Regards,
Christian
‎2005 Dec 08 4:24 PM
instead directly use loop...endloop & read statements with index.
loop at <inttable>.
read <inttable2> index <integer>.
endloop.
‎2005 Dec 08 4:35 PM