Application Development 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: 

Performance Issue in modifying a ITAB

former_member206396
Active Participant
0 Kudos

Hi SDNs.,

performance issue in modifying a internal table : code :

*-Modify LT_DOC with Object list number(OBKNR) from SER03

LOOP AT LT_SER03_HASH INTO LW_SER03.

IF ( LW_SER03-OBKNR IS NOT INITIAL ).

READ TABLE LT_DOC INTO LW_DOC WITH KEY MBLNR = LW_SER03-MBLNR

MJAHR = LW_SER03-MJAHR

ZEILE = LW_SER03-ZEILE BINARY SEARCH.

IF ( SY-SUBRC = 0 ). " AND ( LW_SER03-OBKNR IS NOT INITIAL ).

LW_DOC-OBKNR = LW_SER03-OBKNR.

LW_DOC-DATUM = LW_SER03-DATUM.

LW_DOC-UZEIT = LW_SER03-UZEIT.

MODIFY LT_DOC FROM LW_DOC INDEX SY-INDEX TRANSPORTING OBKNR DATUM UZEIT WHERE MBLNR = LW_SER03-MBLNR AND

MJAHR = LW_SER03-MJAHR AND

ZEILE = LW_SER03-ZEILE .

ENDIF.

ENDIF.

CLEAR: LW_DOC, LW_SER03.

ENDLOOP.

<b>could any one help me out in tuning this code...</b>

Thank you

RK S

6 REPLIES 6

christian_wohlfahrt
Active Contributor
0 Kudos

Hi!

I don't know, if the binary search could be faster - looks like it's already like a full (binary) key access. But for the rest: use field-symbols as work-area!


field-symbols: <ser03> type ..."like line of lt_ser03
                     <doc>    type .... "like line of lt_doc.
LOOP AT LT_SER03_HASH assinging <ser03>.
  IF ( <SER03>-OBKNR IS NOT INITIAL ).
    READ TABLE LT_DOC assigning <doc> WITH KEY MBLNR = <SER03>-MBLNR
                                             MJAHR =<SER03>-MJAHR
                                             ZEILE = <SER03>-ZEILE BINARY SEARCH.

IF SY-SUBRC = 0 . " AND ( LW_SER03-OBKNR IS NOT INITIAL ).
<DOC>-OBKNR = <SER03>-OBKNR.
<DOC>-DATUM = <SER03>-DATUM.
<DOC>-UZEIT = <SER03>-UZEIT.
ENDIF.
ENDIF.
ENDLOOP.

You don't need a modify any longer.

Regards,

Christian

0 Kudos

hi christain.,

Thank you for reply.,

field symbols not working for following case : could you pls check the following code and tel me how can i enhance the same...

could you pls help me out..

<b>Note : Without Modify stmt, the corresponding fields in following code are not updating. could any one pls help me out...</b>

LOOP AT LT_FINAL_HASH1 INTO LW_FINAL_TEMP.

IF LW_FINAL_TEMP-BWTAR IN R_BWTAR.

READ TABLE LT_FINAL ASSIGNING <FS_FINAL> WITH KEY

SERNR = LW_FINAL_TEMP-SERNR BINARY SEARCH.

TAB_INDEX = SY-TABIX.

WHILE SY-SUBRC = 0.

IF <FS_FINAL>-SERNR <> LW_FINAL_TEMP-SERNR.

SY-SUBRC = 9.

ELSE.

IF <FS_FINAL>-BWTAR IN R_BWTAR.

<FS_FINAL>-AG_DATE = <FS_FINAL>-BUDAT.

<FS_FINAL>-AG_MBLNR = <FS_FINAL>-MBLNR.

  • MODIFY LT_FINAL FROM LW_FINAL

  • TRANSPORTING AG_DATE AG_MBLNR WHERE SERNR EQ LW_FINAL_TEMP-SERNR.

  • CLEAR : LW_FINAL-AG_DATE,

  • LW_FINAL-BUDAT.

EXIT.

ENDIF.

TAB_INDEX = TAB_INDEX + 1.

READ TABLE LT_FINAL ASSIGNING <FS_FINAL> INDEX TAB_INDEX.

ENDIF.

ENDWHILE.

endloop.

Thank you .,

RK S

0 Kudos

Hi RKS!

Thanks for listening to the best solution

It wasn't easy to understand the coding without explanation, but so far I got:

you are making a fast version of a loop at lt_final where sernr = lt_final_hash1-sernr.

Your modify was changing all lines of the corresponding sernr - now you need to 'loop' some lines with the while-loop - this solution will be faster for standard tables, that's good.

You just loose the budat mblnr values. The field symbol is pointing to lines of the table body: the read table at the end of the while loop (index +1) is pointing to new budat / mblnr values, you don't have the values from previous loop any longer. You just assign two fields from one table line (ag_date = budat...).

I guess, you want to move budat from the first line of this sernr to all ag_date of this sernr. Then just make two local variables for budat, mblnr. Maybe fill this before the loop (if sy-subrc eq 0. filling... endif), at least be sure to do it only once. These fields you can use to fill ag_date and ag_mblnr of all lines inside the while-loop.

If this is what you want to do, then it should work - otherwise describe more detailed what is going wrong and what you would like to do.

Regards,

Christian

Former Member
0 Kudos

I don't know if it makes sense to:

MODIFY LT_DOC FROM LW_DOC

<b>INDEX SY-INDEX</b>

TRANSPORTING OBKNR DATUM UZEIT

<b>WHERE</b> MBLNR = LW_SER03-MBLNR AND

MJAHR = LW_SER03-MJAHR AND

ZEILE = LW_SER03-ZEILE .

I think the WHERE will cause a full table scan.

Rob

Former Member
0 Kudos

MODIFY LT_DOC FROM LW_DOC <b>INDEX SY-INDEX</b> TRANSPORTING OBKNR DATUM UZEIT WHERE MBLNR = LW_SER03-MBLNR AND

MJAHR = LW_SER03-MJAHR AND

ZEILE = LW_SER03-ZEILE .

I feel, It's more appropriate to use sy-tabix instead of sy-index.

Former Member
0 Kudos

LOOP AT LT_SER03_HASH.

IF ( LT_SER03-OBKNR IS NOT INITIAL ).

READ TABLE LT_DOC WITH KEY MBLNR = LT_SER03-MBLNR

MJAHR = LT_SER03-MJAHR

ZEILE = LT_SER03-ZEILE

BINARY SEARCH.

IF SY-SUBRC = 0.

LT_DOC-OBKNR = LW_SER03-OBKNR.

LT_DOC-DATUM = LW_SER03-DATUM.

LT_DOC-UZEIT = LW_SER03-UZEIT.

MODIFY LT_DOC INDEX SY-TABIX.

ENDIF.

ENDIF.

CLEAR: LW_DOC, LW_SER03.

ENDLOOP.