‎2013 Nov 11 2:50 PM
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.
‎2013 Nov 11 3:01 PM
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
‎2013 Nov 11 3:00 PM
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.
‎2013 Nov 11 3:01 PM
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
‎2013 Nov 11 3:02 PM
Hi,
Clear the valiables between Loop endlop..
From whic DB table you are filling the t_tab.
Thanks,
Kiran
‎2013 Nov 11 3:08 PM
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
‎2013 Nov 11 3:10 PM
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.
‎2013 Nov 11 3:20 PM
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