Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

issue with performance

Former Member
0 Likes
554

Hi all,

can anyone tell me whats the issue

types : begin of t_TABLE.

include structure zTABLE.

types : TABLE like mara-matnr.

types: end of t_table.

data: i_table type standard table of t_table.

data: wa_table like line of i_table.

types : begin of t_table1.

include structure zTABLE1.

types : TABLE like mara-matnr.

types: end of t_table1.

data: i_table1 type standard table of t_table1.

data: wa_table1 like line of i_table1.

select * from zTABLE into table i_ztable where werks = 'ABC'.

select * from zTABLE1 into table i_ztable1 where werks = 'ABC'.

1) LOOP AT I_Ztable INTO WA_Ztable1.

READ TABLE I_Ztable1 WITH KEY -


.

IF SY-SUBRC EQ 0.

DELETE TABLE i_ztable FROM wa_zTABLE.

WA_ZTABLE-TABLE = 'TABLE'.

insert wa_zTABLE into table i_zTABLE.

ENDIF.

ENDLOOP.

2) LOOP AT I_ZTABLE INTO WA_ZTABLE.

READ TABLE I_ZTABLE1 WITH KEY -


.

IF SY-SUBRC EQ 0.

WA_ZTABLE-TABLE = 'TABLE'.

modify i_zTABLE from wa_zTABLE transporting TABLE

where zNO = wa_zTABLE-zNO.

ENDIF.

ENDLOOP.

3)

data: i_final type standard table of t_table.

data: wa_final like line of i_table.

LOOP AT I_ZTABLE INTO WA_ZTABLE.

READ TABLE I_ZTABLE1 WITH KEY -


.

IF SY-SUBRC EQ 0.

WA_ZTABLE-TABLE = 'TABLE'.

insert wa_zTABLE into table i_zFINAL.

ENDIF.

ENDLOOP.

The first and second ar very slow it's taking minutes and the 3 takes just a sec or two

let me know if iam missed anything

Thanks

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
537

You should be adding the binary search option to your read statement; otherwise, there's not a lot of difference with a loop.

Rob

5 REPLIES 5
Read only

Former Member
0 Likes
538

You should be adding the binary search option to your read statement; otherwise, there's not a lot of difference with a loop.

Rob

Read only

0 Likes
537

HI rOB,

IAM USING THE EXACT SAME CODE FOR THE READ STATEMNT.

JUST FIND TEH DIFFERENCES

IN THE FIRST METHOD

1)IAM DELETING AND ADDING THE RECORD WITHIN THE SAME INTERNAL TABLE

2) IAM MODIFYING THE RECORD WITHIN THE SAME INTERNAL TABLE

3)INSERTING IN A DIFFERENT TABLE--THIS IS VERY FAST

PLEAE LET ME KNOW

Thanks

Read only

0 Likes
537

Results can be unpredictable when modifying tables that you are looping through. Since it's also faster, stick with #3.

Rob

Read only

0 Likes
537

Hi,

If you want to change several rows in a table, the fastest option is to use field-symbols. Something like this:

FIELD-SYMBOL <line> TYPE line_of_table.

LOOP AT table ASSIGNING <line>.

<line>-value = 'value'.

ENDLOOP.

The difference is: the line from the table is not copied to your work-area. Instead the field-symbol has a pointer directly to the line in the table. That also means that when you change a field in the field-symbol, it's actually changed in the table.

This always has the best performance for that type of task. Have fun racing !

best regards,

Peter Glas

Read only

Former Member
0 Likes
537

> 3)

> data: i_final type standard table of t_table.

> data: wa_final like line of i_table.

>

> LOOP AT I_ZTABLE INTO WA_ZTABLE.

>

> READ TABLE I_ZTABLE1 WITH KEY -


.

> IF SY-SUBRC EQ 0.

>

>

> WA_ZTABLE-TABLE = 'TABLE'.

> insert wa_zTABLE into table i_zFINAL.

>

>

> ENDIF.

> ENDLOOP.

>

>

Your 3 options are not functionally equivalent.

IF sy-subrc is not 0 for any entry, then the table in option 3 will not contain all entries from the original table.

This is not the case with the first 2 options.

This can be fixed with a trivial change, however.

  DATA: i_final TYPE STANDARD TABLE OF t_table.
  DATA: wa_final LIKE LINE OF i_table.

  LOOP AT i_ztable INTO wa_ztable.

    READ TABLE i_ztable1 WITH KEY -----.
    IF sy-subrc EQ 0.

      wa_ztable-table = 'TABLE'.

    ENDIF.
    
    INSERT wa_ztable INTO TABLE i_zfinal.  " insert outside of IF ensures that full table is in final table
  ENDLOOP.

The third option is fastest because the size of the table starts out small, and each insert takes very little processing time. The repeated inserts, deletes and modifies in the other versions require more processing, since the table alread has entries.

If you correct the logic flaw in optoin 3, it is a useful way to go, but the previous poster's suggestion to use a field symbol may be best.

-


The point of my post is that you are not necessarily comparing apples to apples, since your option 3 is flawed.

Good luck