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

Submit statement inside user exit for sending email

1,083

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

5 REPLIES 5
Read only

Sandra_Rossi
Active Contributor
957

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).

Read only

0 Kudos
957

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.

Read only

0 Kudos
957

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.

Read only

RaymondGiuseppi
Active Contributor
0 Kudos
957

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?)

  • there will be no commit/rollback handled by the application, only a PAI/PBO cycle with an error message
  • if a user performs a dozen of typos, a dozen of mails must be sent?

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

Read only

Sandra_Rossi
Active Contributor
957

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