2022 Aug 25 5:14 AM
Hi,
I have requirement to perform some validation which will trigger error message and send notification email if the requirement is not met. the step will be like this :
PERFORM VALIDATION CHANGING subrc.
IF subrc <> 0. "condition is not met
- Send notification email
- throw error message to stop/prevent save
ENDIF
I am fully aware that commit statement is not allowed inside user exit. meanwhile sending email through FM or class CL_BCS required commit work statement.
I was thinking to wrap the email logic in RFC function module and call it with DESTINATION 'NONE' or STARTING NEW TASK. but based on SAP documentation, calling RFC will cause implicit commit in the calling program.
Is it save to wrap the email logic in separate program and call the program from user exit using SUBMIT statement?
any ideas will be appreciated 🙂 thanks
2022 Aug 25 7:16 AM
As a rule-of-thumb, doing a commit work inside a user exit could break the LUW (short dump if update task, etc.), it's why it's highly not recommended to use it.
You can send the email during the update task i.e. which runs when COMMIT WORK is done by standard program (either in a user exit whose description states that it runs during the update task, or use CALL FUNCTION ... IN UPDATE TASK).
2022 Aug 25 9:32 AM
Hi Sandra,
the requirement is to send email after triggering error message to prevent save/posting. means commit work in SAP LUW will not happen.
2022 Aug 25 10:53 AM
Please use the COMMENT button for comments, questions, adding details, replying to a comment or a proposed solution or to the OP question, etc., ANSWER is only to propose a solution, dixit SAP text at the right of the answer area.
2022 Aug 25 10:54 AM
Do you confirm that you want to trigger a mail whenever a PAI special check fails, just before sending an error message (after is too late, the PAI/PBO cycle is already triggered?)
You could export some data to a shared data cluster and raise a batch event (cl_batch_event=>raise) this event would trigger execution of a periodic on event background job (or any more up-to-date tool) that would read the data cluster and send the mail
2022 Aug 25 11:01 AM
As you say that "the requirement is to send email after triggering error message to prevent save/posting", it means that the update task won't run, so it can't be used to send the email.
Instead, you could use the Enhancement Framework to find a suitable place to send the email.
Another solution, which is non-official ("for internal use only", "if used incorrectly, the worst-case scenario is a system shutdown"), is to use CALL FUNCTION ... DESTINATION 'NONE' KEEPING LOGICAL UNIT OF WORK