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: 

Better performance for program

former_member184029
Participant
0 Kudos

Hi

I have a program which its execution is 'ok' if there are few record (for example 250), otherwise, system show a message of time out.

In this case, what I should do to get better performance for program?

These are code lines for data selection


SELECT ZLOTE BUKRS ANLN1 INVNR ORD41 ORD42 ORD43 ORD44 FROM zanla1
         INTO TABLE ti_zanla1
         WHERE INVNR IN p_invnr.

 SORT ti_zanla1 BY INVNR.

  LOOP AT ti_zanla1 INTO wa_zanla1.

    READ TABLE ti_zinvnr WITH KEY BUKRS = wa_zanla1-bukrs
                                   INVNR = wa_zanla1-invnr
                          ASSIGNING <zinvnr>.

    IF SY-SUBRC = 0.

      READ TABLE it_invnr_control WITH KEY ZLOTE = <zinvnr>-ZLOTE ASSIGNING <zcontrol_serial>.
      IF sy-subrc = 0.
        it_output-ZFECHAEC  = <zcontrol_serial>-ZFECHAEC.
        it_output-ZHORAEC   = <zcontrol_serial>-ZHORAEC.
      ENDIF.

      it_output-EBELN    = <zinvnr>-EBELN.
      it_output-BISMT    = <zinvnr>-BISMT.

      READ TABLE ti_zcontrol_anla1 WITH KEY ZLOTE = wa_zanla1-ZLOTE ASSIGNING <zcontrol_anla1>.
      IF sy-subrc = 0.
        it_output-FECHAREC = <zcontrol_anla1>-ZFECHAEC.
      ENDIF.

      it_output-ZLOTE   = wa_zanla1-ZLOTE.
*        it_output-BUKRS   = wa_zanla1-BUKRS.
      it_output-ANLN1   = wa_zanla1-ANLN1.
      it_output-INVNR   = wa_zanla1-INVNR.

      IF wa_zanla1-INVNR = ZINVNR.
        it_output-TOTIN01 = 0.
      ELSE.
        it_output-TOTIN01 = 1.
      ENDIF.


      it_output-ORD41   = wa_zanla1-ORD41.

      READ TABLE ti_t087t WITH KEY ordnr = '1' ord4x = ti_salida-ord41.
      it_output-T_ORD41 = ti_t087t-ordtx.

      it_output-ORD42   = wa_zanla1-ORD42.
      READ TABLE ti_t087t WITH KEY ordnr = '2' ord4x = ti_salida-ord42.
      it_output-T_ORD42 = ti_t087t-ordtx.

      it_output-ORD43   = wa_zanla1-ORD43.
      READ TABLE ti_t087t WITH KEY ordnr = '3' ord4x = ti_salida-ord43.
      it_output-T_ORD43 = ti_t087t-ordtx.

      it_output-ORD44   = wa_zanla1-ORD44.
      READ TABLE ti_t087t WITH KEY ordnr = '4' ord4x = ti_salida-ord44.
      it_output-T_ORD44 =  ti_t087t-ordtx.
*        it_output-STATUS  = wa_zanla1-STATUS.
      APPEND it_output.
      CLEAR it_output.
    ENDIF.  

  ENDLOOP.

Thanks in advance.

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Sort the internal tables and then use the BINARY SEARCH option of the READ statement.

Rob

7 REPLIES 7

Former Member
0 Kudos

Sort the internal tables and then use the BINARY SEARCH option of the READ statement.

Rob

0 Kudos

Thanks Rob, I'll test and let you know.

0 Kudos

Every time you do a READ without the BINARY SEARCH option, it's like doing:

LOOP AT itab WHERE ...
  EXIT.
ENDLOOP.

Adding the BINARY SEARCH will definitely help.

Rob

ThomasZloch
Active Contributor
0 Kudos

How large is table zanla1?

Is INVNR the primary or a secondary key of that table?

Thomas

0 Kudos

Hi Thomas

How large is table zanla1?

397.312 in DEV, 437.905 PRD

Is INVNR the primary or a secondary key of that table?

INVNR is the primary

0 Kudos

sounds good, so stick with Rob's suggestions.

A small additional gain might be possible by replacing

LOOP AT ti_zanla1 INTO wa_zanla1.

with

LOOP AT ti_zanla1 ASSIGNING <zanla1>.

and dependent statements of course.

Thomas

former_member194613
Active Contributor
0 Kudos

SORT ti_zanla1 BY INVNR.
 
  LOOP AT ti_zanla1 INTO wa_zanla1.
 
    READ TABLE ti_zinvnr WITH KEY BUKRS = wa_zanla1-bukrs
                                   INVNR = wa_zanla1-invnr
                          ASSIGNING <zinvnr>.

I would recommend you to use Sorted tables for all tables which are used with the READs inside the LOOP.

If this is not possible, then sort the standard table before the LOOP starts and use BINARY SEARCH.

There is no real advantage that the large table ti_zanla1 is sorted, the LOOP processes anyway the complete LOOP.

Maybe there is some other logic, which profits of the sort. The APPEND could be such a logic, if the result-table should also be sorted then it makes sense to have

the sort on the LOOP-table.

Siegfried