‎2008 Sep 05 7:23 AM
Hi All,
I am updating the reason for rejection code for multiple sales orders using BAPI_SALESORDER_CHANGE.
Iam using the folowing code to update the sales orders.
but it is taking a long time to process.
Please can anybody look into this and let me know how to improve the performance.
Can anybody tell me can we call this bapi outside the loop? If we can how to pass the parameters?
LOOP AT I_SELECTED_SO.
I_ITEM-ITM_NUMBER = I_SELECTED_SO-POSNR.
I_ITEM-REASON_REJ = I_SELECTED_SO-ABGRU.
APPEND I_ITEM. CLEAR I_ITEM.
I_ITEMX-ITM_NUMBER = I_SELECTED_SO-POSNR.
I_ITEMX-UPDATEFLAG = 'U'.
I_ITEMX-REASON_REJ = 'X'.
APPEND I_ITEMX. CLEAR I_ITEMX.
Save rejection reason text
I_TEXT-DOC_NUMBER = I_SELECTED_SO-VBELN.
I_TEXT-ITM_NUMBER = I_SELECTED_SO-POSNR.
I_TEXT-LANGU = SY-LANGU.
APPEND I_TEXT.
I_BAPISDH1X-UPDATEFLAG = 'U'.
CALL FUNCTION 'BAPI_SALESORDER_CHANGE'
EXPORTING
SALESDOCUMENT = I_SELECTED_SO-VBELN
ORDER_HEADER_IN = I_BAPISDH1
ORDER_HEADER_INX = I_BAPISDH1X
TABLES
RETURN = I_RETURN
ORDER_ITEM_IN = I_ITEM
ORDER_ITEM_INX = I_ITEMX
ORDER_TEXT = I_TEXT.
READ TABLE I_RETURN WITH KEY TYPE = 'S'.
IF SY-SUBRC = 0.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
WAIT = 'X'
IMPORTING
RETURN = I_BAPIRETURN.
IF NOT I_SELECTED_SO IS INITIAL.
MOVE I_SELECTED_SO-ABGRU TO I_REJECTED_SO-ABGRU.
MODIFY I_REJECTED_SO TRANSPORTING ABGRU
WHERE VBELN = I_SELECTED_SO-VBELN
AND POSNR = I_SELECTED_SO-POSNR.
I_REJECTED_SO-MESSAGE = 'REJECTED SUCESSFULLY'.
MODIFY I_REJECTED_SO TRANSPORTING MESSAGE
WHERE VBELN = I_SELECTED_SO-VBELN
AND POSNR = I_SELECTED_SO-POSNR.
ENDIF.
ELSE.
CALL FUNCTION 'FORMAT_MESSAGE'
EXPORTING
ID = I_RETURN-ID
LANG = 'EN'
NO = I_RETURN-NUMBER
V1 = I_RETURN-MESSAGE_V1
V2 = I_RETURN-MESSAGE_V2
V3 = I_RETURN-MESSAGE_V3
V4 = I_RETURN-MESSAGE_V4
IMPORTING
MSG = V_MSGTXT
EXCEPTIONS
NOT_FOUND = 1
OTHERS = 2.
I_REJECTED_SO-MESSAGE = V_MSGTXT.
MODIFY I_REJECTED_SO TRANSPORTING MESSAGE
WHERE VBELN = I_SELECTED_SO-VBELN
AND POSNR = I_SELECTED_SO-POSNR.
ENDIF.
ENDLOOP.
ENDFORM. " UPDATE_SO
Thanks & Regards
Sudheer Kumar
‎2008 Sep 05 10:52 AM
Hi
Following are my suggestions
(1) You are not refreshing / clearing the internal table, else your internal table will get added up and you
may not get desired result
Pls modify your code
LOOP AT I_SELECTED_SO.
Referesh : I_ITEM,
I_ITEMX,
I_TEXT.
CLEAR : I_BAPISDH1,
I_BAPISDH1X.
(2) I am not sure, whether you are passing right value to I_BAPISDH1.
(3) Instead of modiying the I_REJECTED table twice, i think you can do the same with single
modify statement
MODIFY I_REJECTED_SO TRANSPORTING ABGRU
MESSAGE.
(4) I think you can do more optimizing by combining all the lines of same sales order and call BAPI at once, if your requirement is not to check for every line item.
Regards
MD
‎2008 Sep 05 7:26 AM
Sudheer
Remove WAIT = 'X' in the BAPI Commit Call... Just do "COMMIT WORK" as there is no dependency in updates to different sales orders in this case.
Thanks
Amol Lohade
‎2008 Sep 05 7:45 AM
Hi Amol,
I tried this but still it is taking long time.But it is not improved the performance.
Thanks & Regards,
Sudheer Kumar
‎2008 Sep 05 7:59 AM
Sudheer
Try doing commit work only once after ENDLOOP and remove BAPI Commit work from the Loop... Endloop...
Thanks
Amol Lohade
‎2008 Sep 05 7:40 AM
Hi Sudhir,
BAPI doesn't commit. You need to commit explicitly
using FM BAPI_TRANSACTION_COMMIT.
Regards,
Hemant
‎2008 Sep 05 7:48 AM
Hi Hemanth,
Thanks for immediately reply.
I used BAPI_TRANSACTION_COMMIT already,
the actual problem is performance.
Please let me know how to improve the performance.
Thanks & Regards,
Sudheer Kumar
‎2008 Sep 05 10:52 AM
Hi
Following are my suggestions
(1) You are not refreshing / clearing the internal table, else your internal table will get added up and you
may not get desired result
Pls modify your code
LOOP AT I_SELECTED_SO.
Referesh : I_ITEM,
I_ITEMX,
I_TEXT.
CLEAR : I_BAPISDH1,
I_BAPISDH1X.
(2) I am not sure, whether you are passing right value to I_BAPISDH1.
(3) Instead of modiying the I_REJECTED table twice, i think you can do the same with single
modify statement
MODIFY I_REJECTED_SO TRANSPORTING ABGRU
MESSAGE.
(4) I think you can do more optimizing by combining all the lines of same sales order and call BAPI at once, if your requirement is not to check for every line item.
Regards
MD
‎2008 Sep 05 11:04 AM
Hi Madhan,
Thanks for your reply.
I have declared as shown below.
DATA: I_ITEM TYPE BAPISDITM OCCURS 0 WITH HEADER LINE,
I_ITEMX TYPE BAPISDITMX OCCURS 0 WITH HEADER LINE,
I_TEXT TYPE BAPISDTEXT OCCURS 0 WITH HEADER LINE.
DATA : ST_ITEM LIKE I_ITEM,
ST_ITEMX LIKE I_ITEMX,
ST_TEXT LIKE I_TEXT.
DATA: I_BAPISDH1 LIKE BAPISDH1 OCCURS 0 WITH HEADER LINE,
I_BAPISDH1X LIKE BAPISDH1X OCCURS 0 WITH HEADER LINE,
V_MSGTXT(100) TYPE C. "Variable for message text.
DATA: BEGIN OF I_RETURN OCCURS 0.
INCLUDE STRUCTURE BAPIRET2.
DATA: END OF I_RETURN.
DATA: BEGIN OF I_BAPIRETURN OCCURS 0.
INCLUDE STRUCTURE BAPIRET2.
DATA: END OF I_BAPIRETURN.
DATA : BEGIN OF I_SELECTED_SO occurs 0 ,
VBELN LIKE VBAP-VBELN, "Sales Doc No.
POSNR LIKE VBAP-POSNR, "Sales Doc Item No.
MATNR LIKE VBAP-MATNR, "Material No.
WERKS LIKE VBAP-WERKS, "Plant
KWMENG LIKE VBAP-KWMENG, "Ordered Quantity
AUART LIKE VBAK-AUART, "Sales Document Type
ERDAT LIKE VBAK-ERDAT, "Created On
ERNAM LIKE VBAK-ERNAM, "Created By
VKORG LIKE VBAK-VKORG, "Sales Organisation
VTWEG LIKE VBAK-VTWEG, "Distribution Channel
SPART LIKE VBAK-SPART, "Division
KUNNR LIKE VBAK-KUNNR, "Sold To Party
VSTEL LIKE VBAP-VSTEL, "Shipping Point
ABGRU LIKE VBAP-ABGRU, "Reason for Rejection Code
END OF I_SELECTED_SO.
DATA : BEGIN OF I_REJECTED_SO OCCURS 0,
VBELN LIKE VBAP-VBELN, "Sales Doc No.
POSNR LIKE VBAP-POSNR, "Sales Doc Item No.
MATNR LIKE VBAP-MATNR, "Material No.
WERKS LIKE VBAP-WERKS, "Plant
KWMENG LIKE VBAP-KWMENG, "Ordered Quantity
AUART LIKE VBAK-AUART, "Sales Document Type
ERDAT LIKE VBAK-ERDAT, "Created On
ERNAM LIKE VBAK-ERNAM, "Created By
VKORG LIKE VBAK-VKORG, "Sales Organisation
VTWEG LIKE VBAK-VTWEG, "Distribution Channel
SPART LIKE VBAK-SPART, "Division
KUNNR LIKE VBAK-KUNNR, "Sold To Party
VSTEL LIKE VBAP-VSTEL, "Shipping Point
ABGRU LIKE VBAP-ABGRU, "Reason for Rejection Code
MESSAGE(100) TYPE C, "SUCCESS OR ERROR MESSAGE
END OF I_REJECTED_SO.
and passing these to the BAPI.and no other code
Please let me know what we have to pass to I_BAPISDH1
and I_BAPISDH1X.
Thanks & Regards,
Sudheer Kumar.
‎2008 Sep 05 11:08 AM
Hi Madhan,
Please let me know can we call the BAPI_SALESORDER_CHANGE outside the loop?
or we have to call it only in a loop?
I tried it but only last record is updating when i called outside the loop.
Thanks & Regards,
Sudheer Kumar.
‎2008 Sep 05 11:11 AM
Hi
No you need to call with in loop only.
Try refereshing the internal tables and see, whether it works
Regards
MD
‎2008 Sep 05 11:12 AM
Hi
Try to clear / referesh the values
LOOP AT I_SELECTED_SO.
Referesh : I_ITEM,
I_ITEMX,
I_TEXT.
CLEAR : I_BAPISDH1,
I_BAPISDH1X
Regards
MD
‎2008 Sep 05 11:25 AM
Hi Madhan,
I tried this but still it is updating only one last record outside the loop.
Please can you tell me how to call this bapi outside the loop.
Thanks & Regards,
Sudheer Kumar.
‎2008 Sep 05 11:37 AM
Hi Madhan,
If we call the bapi within a loop it is working fine but
it is taking a long time.
Please let me know is there any other solution to improve the performance?
Thanks & Regards,
Sudheer Kumar.
‎2008 Sep 05 11:38 AM
Hi
You have call BAPI inside loop only.
The below method, can improve the performance, since you are grouping all theline items of same sales order and processing to-gether.
You declare one more internal table like I_SELECTED_SO, say I_SELECTED_SO_TEMP.
I_SELECTED_SO_TEMP [ ] = I_SELECTED_SO [ ].
SORT I_SELECTED_SO_TEMP BY VBELN.
DELETE ADJACENT DUPLICATES FROM I_SELECTED_SO_TEMP COMPARING VBELN.
LOOP AT I_SELECTED_SO_TEMP.
Referesh : I_ITEM,
I_ITEMX,
I_TEXT.
CLEAR : I_BAPISDH1,
I_BAPISDH1X.
LOOP AT I_SELECTED_SO WHERE VBELN = I_SELECTED_SO_TEMP-VBELN.
I_ITEM-ITM_NUMBER = I_SELECTED_SO-POSNR.
I_ITEM-REASON_REJ = I_SELECTED_SO-ABGRU.
APPEND I_ITEM. CLEAR I_ITEM.
I_ITEMX-ITM_NUMBER = I_SELECTED_SO-POSNR.
I_ITEMX-UPDATEFLAG = 'U'.
I_ITEMX-REASON_REJ = 'X'.
APPEND I_ITEMX. CLEAR I_ITEMX.
I_TEXT-DOC_NUMBER = I_SELECTED_SO-VBELN.
I_TEXT-ITM_NUMBER = I_SELECTED_SO-POSNR.
I_TEXT-LANGU = SY-LANGU.
APPEND I_TEXT.
ENDLOOP.
I_BAPISDH1X-UPDATEFLAG = 'U'.
*****cALL YOUR BAPI HERE
If it is success here.Than
LOOP AT I_REJECTED WHERE VBELN = I_SELECTED_SO_TEMP-VBELN..
MODIFY ALL THE LINE ITEM RECORDS.
ENDLOOP.
let the remaining code be like that
ENDLOOP.
Edited by: Madhan Doraikannan on Sep 5, 2008 12:39 PM
‎2008 Sep 05 12:02 PM
Hi Madhan,
I have to reject the sales orders at item level.
If I selected one particular line item in the sales order only that line item should be rejected.
Thanks & Regards,
Sudheer Kumar.
‎2008 Sep 05 12:17 PM
Hi
Do you want to reject all the line items in the intenal table I_SELECTED_SO
Regards
MD
‎2008 Sep 05 12:31 PM
Hi Madhan,
Not all line items, whichever line item is selected only it should be updated in that particular sales order. remaining line items should not be updated.
Thanks & Regards,
Sudheer Kumar.
Edited by: sudheer kumar on Sep 5, 2008 1:31 PM
‎2008 Sep 05 12:36 PM
Hi
How are you selecting the line items to be set for rejection code.
Regards
MD
‎2008 Sep 05 12:39 PM
Create a internal table which requires the line items to be rejected for all the sales order and do the coding as metioned before.
I hope it should work
Regards
MD
‎2008 Sep 05 12:43 PM
Hi Madhan,
I am displaying the sales orders along with the line items individually for selection using REUSE_ALV_POPUP_TO_SELECT.
SELECT VBAP~VBELN
VBAP~POSNR
VBAP~MATNR
VBAP~WERKS
VBAP~KWMENG
VBAK~AUART
VBAK~ERDAT
VBAK~ERNAM
VBAK~VKORG
VBAK~VTWEG
VBAK~SPART
VBAK~KUNNR
VBAP~VSTEL
VBAP~ABGRU
INTO TABLE I_SALESORDERS
FROM VBAK
INNER JOIN VBAP
ON VBAPVBELN = VBAKVBELN
WHERE VBAP~VBELN IN S_VBELN
AND VBAP~POSNR IN S_POSNR.
and I am passing the selected orders to I_SELECTED_SO.
and after selecting the sales orders i am displaying a popup for reason for rejection codes using POPUP_GET_VALUES.
Once the reason for rejection code is selected i am calling the bapi to update the sales orders.
Thanks & Regards,
Sudheer Kumar.
Edited by: sudheer kumar on Sep 5, 2008 1:44 PM
‎2008 Sep 05 12:53 PM
Hi
Do you agree that all the records in the internal table I_SELECTED_SO. needs to be assigned with reject code.
Than you have call BAPI in loop.
Regards
Madhan Doraikannan
‎2008 Sep 05 1:00 PM
Hi
Even the BAPI_TRANSACTION_COMMIT should be called inside the loop
Regards
MD
‎2008 Sep 05 1:56 PM
Hi Madhan,
I am calling both BAPI_SALESORDER_CHANGE AND BAPI_TRANSACTION_COMMIT within the loop,
but it is taking long to process.
That's why I wanted to call the bapi outside the loop.
Thanks & Regards,
Sudheer Kumar
‎2008 Sep 05 9:06 PM
Sudheer,
I don't think the performance issue has anything to do with your code and I'm 99% sure it's not going to work differently whether you call BAPI inside the loop or not. Although you might want to use FREE command after the BAPI call to free the memory used by the tables, but I don't think it will improve the performance significantly.
The reason for this is that BAPI is practically calling VA02 transaction, which is taking its sweet time to process the change. When the rejection reason code is being changed, there are many other processes in the standard SAP that need to take place. For example, condition recalculation, changes in ATP, etc. All this is going to take a while regardless of how you call BAPI.
We had exactly the same issue with this BAPI and rejection reason, but there was not much we could do either. We ran SQL Trace (ST05) and got additional information from Basis and were able to change some code in the sales order user exits, but, unfortunately, it did't help significantly.
So start with ST05 to see where exactly the performance bottlenecks are, but I'm afraid there won't be much you can do.
‎2008 Sep 08 5:34 AM
Hi
If you call BAPI_TRANSACTION_COMMIT Outside loop, it will update only last record.
Regarding performance.
If i see your earlier code, i see you are calling BAPI for the same sales order for different line items in the loop.
For example
If Sales order 10 is having 3 line items and you want to update the rejection code for all the 3 line items.
You are calling BAPI 3 times in the loop.
Bascially you can collect all the 3 line items to ITEM internal table and call both the BAPI's once.
Similarly you can group and process the same for other sales orders and also begin of the loop, you need to refresh / free the internal tables used in BAPI's..
In the earlier post i have specified the sample code.
Regards
Madhan Doraikannan