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

Former Member
0 Likes
438

Hi Gurus,

SELECT * FROM mbew WHERE matnr IN s_matnr

AND bwkey IN s_werks

AND bwtty EQ space.

SELECT SINGLE * FROM mara WHERE matnr = mbew-matnr

AND mtart = 'FERT'.

IF sy-subrc NE 0.

CONTINUE.

ENDIF.

SELECT * FROM mcha WHERE matnr = mbew-matnr

AND werks = mbew-bwkey.

SELECT * FROM mchb WHERE matnr = mcha-matnr

AND werks = mcha-werks

AND charg = mcha-charg.

MOVE mchb-matnr TO itab-matnr.

MOVE mchb-werks TO itab-werks.

MOVE mchb-lgort TO itab-lgort.

MOVE mchb-charg TO itab-charg.

MOVE mchb-clabs TO itab-clabs.

APPEND itab.

ENDSELECT.

ENDSELECT.

ENDSELECT.

I need to replace the above code with for all entries by avoiding select endselect and for improving the performance with out affecting the result.

If possible please send me the better code to do this.

Thanks a lot for your help.

2 REPLIES 2
Read only

JozsefSzikszai
Active Contributor
0 Likes
398

hi Babji,

try this:

SELECT ... fields here ! ...

INTO TABLE itab

FROM mbew AS MBEW

INNER JOIN mara AS MARA

ON mbewmatnr EQ maramatnr

INNER JOIN mcha AS mcha

ON mchamatnr EQ mbewmatnr

AND mchawerks EQ mbewbwkey

INNER JOIN mchb AS mchb

ON mchbmatnr EQ mchamatnr

AND mchbwerks EQ mchawerks

AND mchbcharg EQ mchacharg

WHERE mara~MTART EQ 'FERT'.

Pls. note I was typng it without system, so tere could be syntax errors.

hope this helps.

ec

Read only

Former Member
0 Likes
398

HI,

data:I_mbew type standard table of mbew,

I_mara TYpe standard table of MARA,

i_mcha type standard table of mcha,

i_mcnb type standard table of mcnb.

Select * into table i_mbew from MBEW WHERE matnr IN s_matnr

AND bwkey IN s_werks

AND bwtty EQ space.

IF NOT i_MBEW[] is initial.

SELECT * INTO TABLE i_MARA FROM mara

FOR ALL ENTRIES IN i_MBEW

WHERE matnr = i_mbew-matnr

AND mtart = 'FERT'.

ENDIF.

IF NOT I_MBEW[] IS INITIAL.

SELECT * into table i_mcha FROM mcha

FOR ALL ENTRIES IN i_MBEW

WHERE matnr = i_mbew-matnr

AND werks = i_mbew-bwkey.

ENDIF.

IF NOT I_mcha[] IS INITIAL

SELECT * iNTO TABLE i_mchb FROM mchb

FOR ALL ENTRIES IN I_MCHA

WHERE matnr = i_mcha-matnr

AND werks = i_mcha-werks

AND charg = i_mcha-charg.

ENDIF.

LOOP AT i_MCHB INTO wa_mchb.

READ TABLE I_MARC INTO WA_MARC with key matnr = wa_mchb-matnr

werks = wa_mchb-werks

binary search.

check the conditions and then move the data to another internal table.

ENDLOOP.