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

Code Performance.

ronaldo_aparecido
Contributor
0 Likes
876

HI Gurus.

This code its correct?The performance it´s ok?

LOOP AT t_tab INTO e_tab.

     l_tabix = sy-tabix.

     SELECT SINGLE bismt

              INTO mara-bismt

              FROM mara

              WHERE matnr = e_tab-matnr.

     IF  mara-bismt NE c_s.

       DELETE t_tab[] INDEX l_tabix.

     ENDIF.

   ENDLOOP.

Its possible make improvements.

Thanks For suggestions.

1 ACCEPTED SOLUTION
Read only

aferngas
Active Participant
0 Likes
843

Try with this.

TYPES:

  BEGIN OF type_s_bismt,

    matnr TYPE mara-matnr,

    bismt TYPE mara-bismt,

  END OF type_s_bismt,

  type_t_bismt TYPE STANDARD TABLE OF type_s_bismt

               WITH NON-UNIQUE DEFAULT KEY.

DATA lt_bismt_aux TYPE type_t_bismt.

FIELD-SYMBOLS <wa_bismt_aux> TYPE type_s_bismt.

IF t_tab[] IS NOT INITIAL.


  SORT t_tab[] BY matnr.

  SELECT matnr bismt

    FROM mara

    INTO TABLE lt_bismt_aux

     FOR ALL ENTRIES OF t_tab[]

   WHERE matnr EQ t_tab-matnr AND

         bismt NE c_s.


  LOOP lt_bismt_aux ASSIGNING <wa_bismt_aux>.

    DELETE t_tab[] WHERE matnr EQ <wa_bismt_aux>-matnr.

  ENDLOOP.


ENDIF.

Still the best option would be to filter the results from the start of the selection.

Regards,

Alex

6 REPLIES 6
Read only

Former Member
0 Likes
843

Hi Ronaldo,

Use Read Table instead of Select inside the loops for better performance.

Step 1:

Retrieve BISMT from MARA by using FOR ALL ENTRIES in T_TAB-MATNR.

sort T_MARA by MATNR.

Step 2:

LOOP AT t_tab INTO e_tab.

     l_tabix = sy-tabix.

  Read Table T_MARA into E_MARA with key MATNR = e_tab-matnr binary search.

   If sy-subrc eq 0 and  E_MARA-BISMT NE c_s.

       DELETE t_tab[] INDEX l_tabix.

    ENDIF.


ENDLOOP.

Credit point if you are OK

Thanks

Mohammed.

Read only

aferngas
Active Participant
0 Likes
844

Try with this.

TYPES:

  BEGIN OF type_s_bismt,

    matnr TYPE mara-matnr,

    bismt TYPE mara-bismt,

  END OF type_s_bismt,

  type_t_bismt TYPE STANDARD TABLE OF type_s_bismt

               WITH NON-UNIQUE DEFAULT KEY.

DATA lt_bismt_aux TYPE type_t_bismt.

FIELD-SYMBOLS <wa_bismt_aux> TYPE type_s_bismt.

IF t_tab[] IS NOT INITIAL.


  SORT t_tab[] BY matnr.

  SELECT matnr bismt

    FROM mara

    INTO TABLE lt_bismt_aux

     FOR ALL ENTRIES OF t_tab[]

   WHERE matnr EQ t_tab-matnr AND

         bismt NE c_s.


  LOOP lt_bismt_aux ASSIGNING <wa_bismt_aux>.

    DELETE t_tab[] WHERE matnr EQ <wa_bismt_aux>-matnr.

  ENDLOOP.


ENDIF.

Still the best option would be to filter the results from the start of the selection.

Regards,

Alex

Read only

Former Member
0 Likes
843

Hi,

Clear the valiables between Loop endlop..

From whic DB table you are filling the t_tab.

Thanks,

Kiran

Read only

hendrik_brandes
Contributor
0 Likes
843

Hello Ronald,

think about following steps:

1) Try to bring a lot of logic to the database

2) reduce the kind of checks within a loop

3) Use efficient table access methods like hashed or sorted access

I would suggest a kind of this:

1) SELECT DISTINCT BISMT FROM MARA with FOR ALL ENTRIES in T_TAB-MATNR and ( additional to Mahammeds answer ) use the condition BISMT <> C_S also:

SELECT DISTINCT BISMT

    INTO lt_tab

  FROM MARA

     FOR ALL ENTRIES IN T_TAB

WHERE MATNR = T_TAB-MATNR

  AND BISMT = C_S.

This will lead to the matching set of BISMTs from MAMA.

2) Use this knowledge for a performant access within your loop:

LOOP AT t_tab ASSIGNING <tab>.

  READ TABLE lt_tab TRANSPORTING NO FIELDS

     WITH KEY matnr = <tab>-matnr.

  IF SY-SUBRC <> 0. "Because we know, that there are only valid entries in lt_tab

    DELETE t_tab FROM <tab>.

  ENDIF.

ENDLOOP.

Have fun.

Kind regards,

Hendrik

Read only

former_member202771
Contributor
0 Likes
843

Hi Ronaldo,

Use select outside the loop and use read inside the loop in place of select.

    SELECT bismt

              INTO int_bismt

              FROM mara

          for all entries in t_tab

              WHERE matnr = t_tab-matnr.

LOOP AT t_tab INTO e_tab.

     l_tabix = sy-tabix.

sort int_bismt.

   READ TABLE int_bismt INTO ws_bismt

                       WITH KEY matnr = ws_bismt-matnr BINARY SEARCH.

     IF  ws_bismt NE c_s.

       DELETE t_tab[] INDEX l_tabix.

     ENDIF.

   ENDLOOP.

Read only

anupam_anand
Participant
0 Likes
843

Hi Ronaldo,

Try this code. It should improve the performance:

TYPES: begin of ty_bismt,

        matnr TYPE mara-matnr,

        bismt TYPE mara-bismt,

       END OF ty_bismt.      

DATA: i_bismt TYPE TABLE OF ty_bismt,

      wa_bismt TYPE ty_bismt.

RANGES: r_matnr FOR mara-matnr.

SELECT matnr bismt FROM mara INTO TABLE i_bismt FOR ALL ENTRIES IN e_tab

  WHERE matnr = e_tab-matnr

    AND bismt eq 'S'.

  IF sy-subrc eq 0.

    SORT i_bismt.

  ENDIF.

  r_matnr-sign = 'I'.

  r_matnr-option = 'EQ'.

  LOOP AT i_bismt INTO wa_bismt.

    r_matnr-low = wa_bismt-matnr.

    APPEND r_matnr. CLEAR: r_matnr-low.

  ENDLOOP.

 

  DELETE e_tab WHERE matnr NOT IN r_matnr.

Please let me know if it helps

Thanks,

Anupam