‎2013 Jun 25 3:51 PM
Hi,
I am using BADI ME_PROCESS_PO_CUST and I have written code in POST and CLOSE method inside to send mail on certain condition.
In ME_PROCESS_PO_CUST-POST method mail is going properly but in ME_PROCESS_PO_CUST-CLOSE mail is not going. It is because in POST method after execution of this method automatically COMMIT WORK is called somewhere in system code but after CLOSE method no COMMIT WORK gets called.
So when I have passed commit_work in FM, mail is going properly . It means after execution of CLOSE no COMMIT WORK gets called in system code.
I have read it at many places and right though we should not use COMMIT WORK inside BADI but what should you suggest of this scenario ?
Please advice ??
CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
EXPORTING
document_data = wa_mailsubject
put_in_outbox = 'X'
commit_work = 'X'
TABLES
packing_list = lt_packing_list
contents_txt = lt_mailtxt
receivers = lt_mailrecipients
EXCEPTIONS
too_many_receivers = 1
document_not_sent = 2
document_type_not_exist = 3
operation_no_authorization = 4
parameter_error = 5
x_error = 6
enqueue_error = 7
OTHERS = 8.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
‎2013 Jun 25 4:33 PM
Put your code within a function module with the commit work.
Call the new function module from the BADI method asynchronously. The commit will no longer be performed within the BADI
CALL FUNCTION 'Z_FMOD' starting new task '0001'
‎2013 Jun 25 4:59 PM
try sending email at an event of BUS2012. Also check BTE 01000730.
Regards
‎2013 Jun 25 5:05 PM
But do above COMMIT will give any issue ?? What are the possibilities because there is no COMMIT WORK in system code ?
‎2013 Jun 25 5:56 PM
Hi,
Create a wrapper report program to call the function module to send email too.
Call the email program as a background job i.e submit report and return.
This way your current program will need not wait for email processing to finish hence it will be faster.
No commit work used directly.
‎2013 Jun 25 6:40 PM
But my email functionality is linked with PO creation , I cannot put it in some external program and run background job .
‎2013 Jun 26 4:59 AM
Hi Ankesh,
you can use BAPI_TRANSACTION_COMMIT and pass the value WAIT = 'X'.
Let me know if any clarification/help required.
Thanks & Best Regards.
Pavan Neerukonda.
‎2013 Jun 26 7:13 AM
Execution of transaction :
- user press SAVE
- POST method called
- COMMIT-WORK
- CLOSE method
In POST method BP is don't use COMMIT, call your FM and it will be valuated by the COMMIT-WORK of the transaction. If you want to prevent trouble, you could wrap your mail sending in a RFC enabled FM and call this FM with option IN BACKGROUND TASK, so it will be executed after end of update task raised by the transaction COMMIT in another LUW, use a COMMIT WORK in this FM.
For the CLOSE method, you should be allowed to use COMMIT as it is executed after the COMMIT triggering he update task. But if the standard transaction don't use the WAIT option (usually the case) the database may not yet been updated.
Regards,
Raymond