‎2007 Jun 05 1:47 PM
Hi Experts,
pl. help us for following abap. I have fetched nearly 40,000 materials in itab and when i am executing it is taking long time 10-20 minutes or it is giving dump.
**************************
DATA: iwmdvsx TYPE TABLE OF bapiwmdvs WITH HEADER LINE,
iwmdvex TYPE TABLE OF bapiwmdve WITH HEADER LINE.
***********
DATA: r TYPE bapireturn, " Check it once.
FQty TYPE MENGV13.
***********
jtab[] = itab[].
LOOP AT itab.
CALL FUNCTION 'BAPI_MATERIAL_AVAILABILITY'
EXPORTING
plant = 'HIP' "p_werks
material = itab-matnr "p_matnr
unit = 'EA' "p_meins
stge_loc = 'BSR'
IMPORTING
return = r
TABLES
wmdvsx = iwmdvsx
wmdvex = iwmdvex.
IF r-type is initial OR r-type = 'S'.
LOOP AT iwmdvex.
FQty = FQty + iwmdvex-com_qty.
ENDLOOP.
jtab-free_qty = FQty.
MODIFY jtab TRANSPORTING free_qty WHERE matnr = itab-matnr.
FQty = 0.
ENDIF.
REFRESH iwmdvex.
CLEAR: itab.
REFRESH iwmdvsx.
ENDLOOP.
‎2007 Jun 05 7:57 PM
‎2007 Jun 05 7:57 PM
‎2007 Jun 05 8:36 PM
Actually, now that I look at it more carefully. I think your problem is an implied nested loop. The MODIFY...FROM... causes a full table scan. So try:
DATA: iwmdvsx TYPE TABLE OF bapiwmdvs WITH HEADER LINE,
iwmdvex TYPE TABLE OF bapiwmdve WITH HEADER LINE.
***********
DATA: r TYPE bapireturn, " Check it once.
fqty TYPE mengv13.
***********
SORT jtab BY matnr.
DELETE ADJACENT DUPLICATES FROM itab COMPARING matnr.
jtab[] = itab[].
LOOP AT itab.
CALL FUNCTION 'BAPI_MATERIAL_AVAILABILITY'
EXPORTING
plant = 'HIP' "p_werks
material = itab-matnr "p_matnr
unit = 'EA' "p_meins
stge_loc = 'BSR'
IMPORTING
return = r
TABLES
wmdvsx = iwmdvsx
wmdvex = iwmdvex.
IF r-type IS INITIAL OR r-type = 'S'.
LOOP AT iwmdvex.
fqty = fqty + iwmdvex-com_qty.
ENDLOOP.
jtab-free_qty = fqty.
READ TABLE jtab WITH KEY
matnr = itab-matnr
BINARY SEARCH.
jtab-free_qty = itab-free_qty.
MODIFY jtab index sy-tabix.
fqty = 0.
ENDIF.
REFRESH iwmdvex.
CLEAR: itab.
REFRESH iwmdvsx.
ENDLOOP.
If you have to keep itab and jtab intact, create two new temporary tables and use these instead.
Rob
‎2007 Jun 05 8:02 PM
Hi,
Try to run your report in "background" mode . I think the dump is due to system timeout.
aRs.
‎2007 Jun 05 8:11 PM
This is the way i do it. See if it helps:
LOOP AT I_WERKS.
refresh: return.
CALL FUNCTION 'BAPI_MATERIAL_AVAILABILITY'
EXPORTING
plant = I_WERKS-LOW
material = I_MARA-MATNR
unit = 'EA'
IMPORTING
av_qty_plt = bapi_onhand
return = return
TABLES
wmdvsx = atp1
wmdvex = atp2.
IF return IS INITIAL.
READ TABLE atp2 WITH TABLE KEY bdcnt = 0
req_date = sy-datum
com_date = sy-datum.
IF atp2-com_qty <> '9999999999.000'.
ONHAND = ONHAND + atp2-com_qty.
ELSE.
ONHAND = ONHAND + bapi_onhand.
ENDIF.
ENDIF.
‎2007 Jun 05 8:41 PM
Hi,
Incase if the FM has any select statements, in such case inside a loop statement, if any selects exists then it will definetly take lot of time. if it is unavoidable since you are calling a function module then the best option is execute in background mode.
thanks,
sksingh
‎2007 Jun 06 11:36 AM
Hi Srinivas,
How to execute in background mode ? through which transaction ?
And also how to see output after background processing ?
pl. give detail.
Yusuf.
Message was edited by:
YUSUF BHORI
‎2007 Jun 06 12:05 PM