Application Development 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: 

Send e-mail without commiting LUW

Tomas_Buryanek
Active Contributor

Hello,

I am having problem with sending e-mail in user exit (EXIT_SAPLV60B_008). E-mail is not sent without commit.

Steps in user exit:

IF problem_exist.

     - send e-mail (wrapped in simple Z RFC module)

     - MESSAGE TYPE 'E'

ENDIF.

NOTE: "send e-mail" logic (tried both CL_BCS and SO_NEW_DOCUMENT_ATT_SEND_API1) works OK if it is commited.

What I tried:

a) CALL FUNCTION func DESTINATION 'NONE' - synchronous RFC triggers a database commit in the calling program

b) CALL FUNCTION func IN BACKGROUND TASK - transactional RFC needs commit in calling program to start

c) CALL FUNCTION func STARTING NEW TASK task - asynchronous RFC triggers a database commit in the calling program

d) CL_BCS_MESSAGE - has 2 ways:

     - DESTINATION 'NONE' = same as a)

     - IN UPDATE TASK = update is not completed because of MESSAGE TYPE 'E'


Any ideas are welcome 🙂


-- Tomas --
1 ACCEPTED SOLUTION

ŁukaszPęgiel
Contributor
0 Kudos

Maybe keep data in shared memory and run job to send a mails from it every 5 minutes?

23 REPLIES 23

Former Member
0 Kudos

What is your question if it is working okay with SO_NEW_DOCUMENT_ATT_SEND_API1?

0 Kudos

It works ok only if it is commited.

Question is - how to send e-mail and NOT commit user uxit "LUW" ?

-- Tomas --

0 Kudos

There should already be a job setp up to trigger email via program RSCONN01 if not you can ask BASIS to run it at regular intervals.


You already mentioned calling function module in background task but there is a addition to it AS SEPARATE UNIT , since you mentioned the function module is a RFC , you can try with this option.



0 Kudos

It wont create "Send request" in spool without commit.

I do not see how "AS SEPARATE UNIT" might help.

-- Tomas --

ŁukaszPęgiel
Contributor
0 Kudos

Maybe keep data in shared memory and run job to send a mails from it every 5 minutes?

0 Kudos

have you also  checked if exporting data to cluster tables also commits current LUW ?

0 Kudos

Thank you. This might be the option.

But I would like to keep a job as last option (for now only one).

-- Tomas --

0 Kudos

Other way could be to create a web service and call it from user-exit. But I do not know if calling web service will not trigger commit as well. This is just a thought.

Former Member
0 Kudos

your question: how to send e-mail and NOT commit user uxit "LUW"


you are within Billing Document Save exit.


IF problem_exist.

     - send e-mail (wrapped in simple Z RFC module)

     - MESSAGE TYPE 'E'

ENDIF.


If you don't want to use the RSCONN* JObs, you might need to some how trigger an implicit commit. Does your functionality allow for it?

Sandra_Rossi
Active Contributor
0 Kudos

If you just want to send an email, then send an error message, why is it an issue that there's some database commit? Why don't you just rollback before sending the message?

0 Kudos

I am afraid doing commit (and rollback) in user exit.

But I will try it:

IF problem_exist.

     ROLLBACK WORK.

     SEND_EMAIL

     COMMIT WORK.

     MESSAGE 'E'.

ENDIF.

-- Tomas --

Sandra_Rossi
Active Contributor
0 Kudos

To avoid the database commit, maybe you can try the internal statement:

CALL FUNCTION '...' DESTINATION 'NONE' KEEPING LOGICAL UNIT OF WORK.

As explained in the ABAP doc, you only risk a system shut down :).

I know, there's no fully-satisfying solution. Remember to retain the KISS principle for exceptional/complex situations.

0 Kudos

I would rather not experiment with this : )

Yes, KISS solution is the one I search for.

-- Tomas --

Clemenss
Active Contributor
0 Kudos

Hi Thomas,

you want to send an email in certain situations when creating an accounting document. If you want to send the email if the document is posted successfully, then the calling program will do the COMMIT WORK - which is, indeed, needed to send the email.

If you want to send the email when the posting fails, I do not see the necessity to do it in the userexit. You should have the results in the calling program. Here you can send via CL_BCS and issue COMMIT WORK preferredly through function BAPI_TRANSACTION_COMMIT.

Please note that there is a fundamantal difference between (implicit) database commit and an ABAP COMMIT WORK (as issued by function BAPI_TRANSACTION_COMMIT).

The (implicit) database commit as triggered by any interruption a there are screen displays or RFC calls or end of current transaction or program run will commit all pending (done in current LUW process) to the database. It will not affect any update tasks registered by call function in update task or perform on commit.

The ABAP COMMIT WORK (as issued by function BAPI_TRANSACTION_COMMIT) will release all update tasks registered by call function in update task or perform on commit for processing. This will also send you mail.

If you want to send your mail in any case from the userexit, you may call function starting new task. In the called function you can send the mail and do the COMMIT WORK. But here you do not know if the calling transation is completed successfully and thus commited to database or if it has failed and thus been rolled back.


Hope my explanation can be understood - feel free to ask.

Regards Clemens

0 Kudos

I understand your explanation thank you.

My scenario is that I stop creating document in user exit with MESSAGE 'E', which works OK. Right before this message I need send e-mail. But there is no implicit commit after that, which would commit e-mail. I think there is "implicit rollback" caused by error message.

As for STARTING NEW TASK:

"Asynchronous RFC triggers a database commit in the calling program." (quote from ABAP keyword help)

***

So far I will stick with this approach:

ROLLBACK

MAIL

COMMIT

MESSAGE

But I hoped that there is some nice and simple way to send mail and not doing commits/rollbacks in user exit.

-- Tomas --

Clemenss
Active Contributor
0 Kudos

Right before the message (knowing it will cancel the transaction) call function starting new task. The implicit commit does no harm.

In the called function send bcs mail and commit work (for the own LUW).

Regards Clemens

Ryan-Crosby
Active Contributor
0 Kudos

Hi Tomas,

Have you tried using SUBMIT with AND RETURN to handle the email logic?

Regards,

Ryan Crosby

0 Kudos

I have no. I was afraid of similar thing like in other solutions. Quote from ABAP keyword help on SUBMIT:


Note

The statement SUBMIT with the addition AND RETURN opens a new SAP-LUW, but it does not open a new database LUW. This means that a database rollback in this SAP LUW can roll back all registration entries made by the statements CALL FUNCTION IN UPDATE TASK or CALL FUNCTION IN BACKGROUND TASK in the tables VB... or ARFCSSTATE and ARFCSDATA. Under certain circumstances, the statement ROLLBACK WORK in the called program can also affect the interrupted SAP LUW. To prevent this, an explicit database commit must be executed before the program is called. This problem does not occur in local updates.

-- Tomas --

0 Kudos

Hi Tomas,

How about using PERFORM ... ON ROLLBACK?  Will the system allow you to execute your desired logic when an error is encountered in the transaction using this option?

Regards,

Ryan Crosby

rajad
Participant
0 Kudos

Hi Tomas,

Why don't you trigger workflow from your error message, through which you can send an email?

Use transaction SWUY to achieve the same.

Cheers,

Raja

Clemenss
Active Contributor
0 Kudos

Hi Tomas,

and there my be even more ways .

Like write a file on the application server, run a recurring job to frequently read the file and raise an event to start another job to process a unix script on a remote server that can send unix mails.

Be sure, you willnever have any maintenance problems

Regards Clemens

0 Kudos

It is good idea. I did not know about this possibility.

But I need to display some data from user exit in e-mail, and that would have to be done by some other workarounds like EXPORT/IMPORT MEMORY...

-- Tomas --

0 Kudos

Hi Tomas,

If you need to send data from user exit to email, then create a workflow and call it after your message using SAP_WAPI_START_WORKFLOW function. You can create container elements to hold your user exit values and pass them while calling the function.

Cheers,

Raja