cancel
Showing results for 
Search instead for 
Did you mean: 

Select distinct * issue

shaikhtabrez3
Explorer
0 Kudos

Can one help me how to resolve performance issue for below code

if it_vart04_art[] IS NOT INITIAL.

   SELECT DISTINCT * FROM  makt INTO TABLE p_it_xmaktx

             FOR ALL ENTRIES IN  it_vart04_art

           WHERE matnr  = it_vart04_art-matnr

             AND spras  = sy-langu.

   SORT p_it_xmaktx BY matnr.

   ENDIF.


Thanks in advance

Regards


Tabrez

Accepted Solutions (1)

Accepted Solutions (1)

arunsubbu
Explorer
0 Kudos

Hi Tabrez,

When you do select distinct, internally it has to sort the entries in the database. Instead you can pull all the record and then sort and delete adjacent duplicated comparing all fields.

But in your case even this is not required. Since you are fetching record from MAKT where the primary key is MATNR and SPRAS and you are passing both the key values, the result will be distinct. Hence it is enough to fetch using select * for all entries in the internal table passing both matnr and spras.

IF it_vart04_art[] IS NOT INITIAL.

   SELECT * FROM  makt INTO TABLE p_it_xmaktx

            FOR ALL ENTRIES IN  it_vart04_art

           WHERE matnr  = it_vart04_art-matnr

           AND spras  = sy-langu.

   SORT p_it_xmaktx BY matnr.  

ENDIF.

Answers (1)

Answers (1)

jaheer_hussain
Active Contributor
0 Kudos

Hi Tabrez,

what problem you are facing in the point of performance? Please try this code.

if it_vart04 _art[] IS NOT INITIAL.

loop at  it_vart04_art.

   SELECT DISTINCT * FROM  makt INTO TABLE p_it_xmaktx

             FOR ALL ENTRIES IN  it_vart04_art

           WHERE matnr  = it_vart04_art-matnr

             AND spras  = sy-langu.

endloop.

   SORT p_it_xmaktx BY matnr.

   ENDIF.

Regards,

Jaheer