05-04-2016 12:08 PM
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 🙂
05-04-2016 7:58 PM
Maybe keep data in shared memory and run job to send a mails from it every 5 minutes?
05-04-2016 2:53 PM
What is your question if it is working okay with SO_NEW_DOCUMENT_ATT_SEND_API1?
05-04-2016 3:11 PM
It works ok only if it is commited.
Question is - how to send e-mail and NOT commit user uxit "LUW" ?
05-04-2016 7:07 PM
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.
05-05-2016 6:33 AM
It wont create "Send request" in spool without commit.
I do not see how "AS SEPARATE UNIT" might help.
05-04-2016 7:58 PM
Maybe keep data in shared memory and run job to send a mails from it every 5 minutes?
05-04-2016 7:59 PM
have you also checked if exporting data to cluster tables also commits current LUW ?
05-05-2016 7:06 AM
Thank you. This might be the option.
But I would like to keep a job as last option (for now only one).
05-05-2016 7:29 AM
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.
05-05-2016 7:34 AM
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?
05-05-2016 8:55 AM
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?
05-05-2016 9:22 AM
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.
05-05-2016 11:09 AM
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.
05-05-2016 12:12 PM
I would rather not experiment with this : )
Yes, KISS solution is the one I search for.
05-05-2016 11:14 AM
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
05-05-2016 12:08 PM
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
COMMIT
MESSAGE
But I hoped that there is some nice and simple way to send mail and not doing commits/rollbacks in user exit.
05-05-2016 1:19 PM
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
05-05-2016 1:12 PM
Hi Tomas,
Have you tried using SUBMIT with AND RETURN to handle the email logic?
Regards,
Ryan Crosby
05-06-2016 6:52 AM
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.
05-06-2016 1:18 PM
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
05-05-2016 1:35 PM
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
05-05-2016 5:45 PM
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
05-06-2016 6:46 AM
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...
05-06-2016 7:17 AM
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