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

Performance Issue with Internal Tables

Former Member
0 Likes
430

Hi,

I'm confronted with the following problem. The source table containing datafield Product-Count (/B99/S_BWPRDTANZ) is incorrectly filled i.e. if there are two rows containing the same Product (/B99/S_BWPRDT) and Product-Group (/B99/S_BWPRDGRP) both rows have value 1 entered for Product-Count. It should actually be 1 in the first row and 0 in the second row.
I am basically sorting the source and filling Table IT_XX_TAB1 with the first record with CRM-Object-ID (CRM_OBJ_ID) as the key. The rest of the records are filled into Table IT_XX_TAB2. Both tables are compared for a particular CRM-Object-ID and the result is updated accordingly.
The code below works fine for the few sample records I took while testing my logic. But for the entire set of records it ran for around 11 hours until I got the result. Any suggestions as to how I could improvise on the code and performance of the routine? It is an APD routine with a total of 9972295 Records.

  DATA: ls_source TYPE y_source_fields,

        ls_target TYPE y_target_fields.

  DATA: INDEX TYPE i VALUE 0,

            FLAG TYPE i.

  DATA: IT_XX_TAB1 TYPE STANDARD TABLE OF y_target_fields

        WITH NON-UNIQUE KEY CRM_OBJ_ID,

        IT_XX_TAB2 TYPE SORTED TABLE OF y_target_fields

        WITH NON-UNIQUE KEY CRM_OBJ_ID.

  DATA: WA_XX_TAB1 TYPE y_target_fields.

  SORT it_source DESCENDING BY CRM_OBJ_ID

                               /B99/S_BWAZLVL1

                               /B99/S_BWAZLVL2

                               /B99/S_BWAZLVL3

                               /B99/S_BWAZLVL4.

  CLEAR FLAG.

  CLEAR INDEX.

  LOOP AT it_source INTO ls_source.

    IF ls_target-CRM_OBJ_ID = ls_source-CRM_OBJ_ID.

      INDEX = INDEX + 1.

      FLAG = INDEX.

    ELSE.

      INDEX = 1.

      FLAG = INDEX.

    ENDIF.

    MOVE-CORRESPONDING ls_source TO ls_target.

    IF FLAG EQ 1.

      APPEND ls_target TO IT_XX_TAB1.

    ELSE.

      INSERT ls_target INTO TABLE IT_XX_TAB2.

    ENDIF.

  ENDLOOP.

  et_target = IT_XX_TAB1.

  LOOP AT IT_XX_TAB2 INTO ls_target.

    READ TABLE IT_XX_TAB1 INTO WA_XX_TAB1

    WITH TABLE KEY CRM_OBJ_ID = ls_target-CRM_OBJ_ID.

    IF sy-subrc = 0.

      IF ( ls_target-/B99/S_BWPRDGRP = WA_XX_TAB1-/B99/S_BWPRDGRP

         AND ls_target-/B99/S_BWPRDT = WA_XX_TAB1-/B99/S_BWPRDT ).

        FLAG = '0'.

      ELSE.

        FLAG = '1'.

      ENDIF.

      IF FLAG = 0.

        ls_target-/B99/S_BWPRDTANZ = '0'.

      ENDIF.

      APPEND ls_target TO et_target.

      CLEAR ls_target.

    ENDIF.

  ENDLOOP.

Thanks,

SD

2 REPLIES 2
Read only

former_member184455
Active Participant
0 Likes
391

Hi SD,

you defined IT_XX_TAB1 as STANDARD table and IT_XX_TAB2 as SORTED table, but you do a LOOP w/o WHERE clause on IT_XX_TAB2 (no optimized access needed) and a READ TABLE ... WITH TABLE KEY on IT_XX_TAB1 (optimized access desperately needed).

So the definition should be the other way round.

Best Regards,

Randolf

Read only

Former Member
0 Likes
391

Hi,

are you sure that this is where the performance problem lies?

I think looping on 10 million records shouldn't take that long.

Maybe something is wrong with your memory sizing.

You can use Get timestamp statements to find out exactly how long a statement or loop takes.

Kind regards, Rob Dielemans