Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Commit Work In Badi, ME_PROCESS_PO_CUST~CLOSE

Former Member
0 Likes
2,924

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.

7 REPLIES 7
Read only

SimonRotherham
Explorer
0 Likes
1,924

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'

Read only

former_member188827
Active Contributor
0 Likes
1,924

try sending email at an event of BUS2012. Also check BTE 01000730.

Regards

Read only

0 Likes
1,924

But do above COMMIT will give any issue ?? What are the possibilities because there is no COMMIT WORK in system code ?

Read only

Former Member
0 Likes
1,924

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.

Read only

0 Likes
1,924

But my email functionality is linked with PO creation , I cannot put it in some external program and run background job .

Read only

Former Member
0 Likes
1,924

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.

Read only

RaymondGiuseppi
Active Contributor
0 Likes
1,924

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