05-12-2010 12:30 PM
Hi,
The following code gives the Time_out run time error.
LOOP AT i_outtab.
IF p_cust = 'X'.
Select single kunnr from vbak into sales_cust
where kunnr = i_outtab-kunnr
and ERDAT GE date.
IF sy-subrc NE 0.
DELETE i_outtab INDEX sy-tabix.
CONTINUE.
ENDIF.
ENDIF.
i_outtab1-kunnr = i_outtab-kunnr.
i_outtab1-name1 = i_outtab-name1.
i_outtab1-land1 = i_outtab-land1.
i_outtab1-ernam = i_outtab-ernam.
i_outtab1-vkorg = i_outtab-vkorg.
i_outtab1-vtweg = i_outtab-vtweg.
i_outtab1-spart = i_outtab-spart.
APPEND i_outtab1.
CLEAR i_outtab1.
ENDLOOP.
However, if the select query is omitted when the condition fails, the performance of the program is fast. Only because of this select query, it goes to run time error.
What is the issue?
Thanks,
Ezhil
05-13-2010 3:16 PM
Hi Ezhilhrh,
Please see the code below. I have removed the select query from the loop.
IF p_cust = 'X'.
DATA: TEMP_ITAB LIKE TABLE OF I_OUTTAB OCCURS 0
WITH HEADERLINE.
Select single kunnr from vbak into table temp_itab
for all entries in i_outtab
where kunnr = i_outtab-kunnr
and ERDAT GE date.
IF sy-subrc EQ 0.
i_outtab[] = temp_itab[]
SORT I_OUTTAB BY KUNNR.
LOOP AT i_outtab.
READ TABLE TEMP_ITAB WITH KEY KUNNR = I_OUTTAB-KUNNR BINARY SEARCH.
IF SY-SUBRC EQ 0.
i_outtab1-kunnr = TEMP_ITAB -kunnr.
i_outtab1-name1 = i_outtab-name1.
i_outtab1-land1 = i_outtab-land1.
i_outtab1-ernam = i_outtab-ernam.
i_outtab1-vkorg = i_outtab-vkorg.
i_outtab1-vtweg = i_outtab-vtweg.
i_outtab1-spart = i_outtab-spart.
APPEND i_outtab1.
CLEAR i_outtab1.
ELSE.
DELETE i_outtab INDEX sy-tabix.
CONTINUE.
ENDIF.
ENDLOOP.
ENDIF.
This code will improve your performance as well.
Regards,
Md Ziauddin.
05-12-2010 12:34 PM
hi,
I would suggest as an developer to never use select query inside LOOP till there is no other option.
you can use read table .
Edited by: gaurav.singh on May 12, 2010 1:35 PM
Edited by: gaurav.singh on May 12, 2010 1:37 PM
05-12-2010 12:52 PM
Hi ,
Kindly Have an additional internal table for Storing the Customer(KUNNR) and Date (ERDAT) With respect to Salesorder Number ,
First with an " for all entries " fill ur internal table with respect to ur current Out_tab.
Instead of giving selct single (hitting the D.base each time ) have ur Second internal table to be read instead of that( reading from table using slect single)
this will obviously reduce ur Time taken and improve ur performance.
Thanks,
Muthu.
05-12-2010 1:12 PM
Hi,
don't read VBAK with kunnr. Instead read SAP note:
185530 Performance: Customer Developments in SD
in order to see which tables to read instead...
Kind regards,
Hermann
05-12-2010 1:26 PM
05-12-2010 1:39 PM
Quite fortunately he provided the primary key to the SAP note
05-13-2010 3:16 PM
Hi Ezhilhrh,
Please see the code below. I have removed the select query from the loop.
IF p_cust = 'X'.
DATA: TEMP_ITAB LIKE TABLE OF I_OUTTAB OCCURS 0
WITH HEADERLINE.
Select single kunnr from vbak into table temp_itab
for all entries in i_outtab
where kunnr = i_outtab-kunnr
and ERDAT GE date.
IF sy-subrc EQ 0.
i_outtab[] = temp_itab[]
SORT I_OUTTAB BY KUNNR.
LOOP AT i_outtab.
READ TABLE TEMP_ITAB WITH KEY KUNNR = I_OUTTAB-KUNNR BINARY SEARCH.
IF SY-SUBRC EQ 0.
i_outtab1-kunnr = TEMP_ITAB -kunnr.
i_outtab1-name1 = i_outtab-name1.
i_outtab1-land1 = i_outtab-land1.
i_outtab1-ernam = i_outtab-ernam.
i_outtab1-vkorg = i_outtab-vkorg.
i_outtab1-vtweg = i_outtab-vtweg.
i_outtab1-spart = i_outtab-spart.
APPEND i_outtab1.
CLEAR i_outtab1.
ELSE.
DELETE i_outtab INDEX sy-tabix.
CONTINUE.
ENDIF.
ENDLOOP.
ENDIF.
This code will improve your performance as well.
Regards,
Md Ziauddin.
05-13-2010 5:00 PM
Hi,
> Please see the code below. I have removed the select query from the loop.
>
>
> IF p_cust = 'X'.
>
> DATA: TEMP_ITAB LIKE TABLE OF I_OUTTAB OCCURS 0
> WITH HEADERLINE.
>
> Select single kunnr from vbak into table temp_itab
> for all entries in i_outtab
> where kunnr = i_outtab-kunnr
> and ERDAT GE date.
>
> IF sy-subrc EQ 0.
>
> i_outtab[] = temp_itab[]
>
> SORT I_OUTTAB BY KUNNR.
>
> LOOP AT i_outtab.
>
> READ TABLE TEMP_ITAB WITH KEY KUNNR = I_OUTTAB-KUNNR BINARY SEARCH.
> IF SY-SUBRC EQ 0.
> i_outtab1-kunnr = TEMP_ITAB -kunnr.
> i_outtab1-name1 = i_outtab-name1.
> i_outtab1-land1 = i_outtab-land1.
> i_outtab1-ernam = i_outtab-ernam.
> i_outtab1-vkorg = i_outtab-vkorg.
> i_outtab1-vtweg = i_outtab-vtweg.
> i_outtab1-spart = i_outtab-spart.
> APPEND i_outtab1.
> CLEAR i_outtab1.
> ELSE.
> DELETE i_outtab INDEX sy-tabix.
> CONTINUE.
> ENDIF.
> ENDLOOP.
> ENDIF.
>
> This code will improve your performance as well.
are you sure?
Kind regards,
Hermann
05-14-2010 10:28 AM
Hi Hermann,
Yes I am sure,
With one correction i.e., to remove single statement from the select query.
Regards,
Md Ziauddin.