Wednesday, 24 May 2023

How to Configure Dynamic Email in Output Parameter Determination App

Following what we have learned from other blogs for the Output Parameter Determination app, I came across something which seemed impossible at the beginning but what’s not possible with SAP?

I had a requirement to setup dynamic Sender and Receiver email address in Output Parameter Determination app for Item Interest Calculation rule. As we know that the app generally presents a decision table for each Determination Setting such as – Output Type, Email Settings, Email Recipient, Form Template etc. And the decision table has endless possibilities for nesting with data objects and expressions. I took advantage of the expression assignment and achieved fetching email of Sender and Receiver dynamically.

Let’s get started.

Sender Email Configuration: Email Settings


For Sender Email, we will be picking data from a custom decision table created in our custom BRF+ application.

SAP S/4HANA, SAP ABAP Development, SAP ABAP Environment, SAP Business Technology Platform, SAP ABAP Career, SAP ABAP Skills, SAP ABAP Jobs, SAP ABAP Prep, SAP ABAP Preparation, SAP ABAP Tutorial and Materials, SAP ABAP Guides, SAP ABAP Learning, SAP ABAP Prep, SAP ABAP Preparation

Based on input parameters – Company Code, Output Type as Mandatory and Free Parameter1, Free Parameter2 as Optional Parameter, we determine Email Body Text, Email Subject text, Logo, Sender E-mail and Sender Name.

To fetch data from the decision table, we created a Function ZFI_TEXT_DETERMINE_FM with the same importing and exporting parameter as the Decision Table –

SAP S/4HANA, SAP ABAP Development, SAP ABAP Environment, SAP Business Technology Platform, SAP ABAP Career, SAP ABAP Skills, SAP ABAP Jobs, SAP ABAP Prep, SAP ABAP Preparation, SAP ABAP Tutorial and Materials, SAP ABAP Guides, SAP ABAP Learning, SAP ABAP Prep, SAP ABAP Preparation

For Result Data Object, we created a structure. If you need a single data object as result, you can assign an Element as Data Object as well.

SAP S/4HANA, SAP ABAP Development, SAP ABAP Environment, SAP Business Technology Platform, SAP ABAP Career, SAP ABAP Skills, SAP ABAP Jobs, SAP ABAP Prep, SAP ABAP Preparation, SAP ABAP Tutorial and Materials, SAP ABAP Guides, SAP ABAP Learning, SAP ABAP Prep, SAP ABAP Preparation

Once the Decision Table and Function is ready, we move to the Output Parameter Determination (OPD) app.

Open the rule – Item Interest Calculation.

When we edit the decision table and click on Table Settings button, we get option to insert column in Condition Columns and in Result Columns. In insert column button, if we select “From Context Data Objects, we get below list with possible data objects to pick –

SAP S/4HANA, SAP ABAP Development, SAP ABAP Environment, SAP Business Technology Platform, SAP ABAP Career, SAP ABAP Skills, SAP ABAP Jobs, SAP ABAP Prep, SAP ABAP Preparation, SAP ABAP Tutorial and Materials, SAP ABAP Guides, SAP ABAP Learning, SAP ABAP Prep, SAP ABAP Preparation

If we use the Sender Email data object, it will always return a static email as per standard functionality and we will not have capability to write any logic or to pick the email from any other place.

So, we will be selecting from the Expressions, but then we must have an expression available which can take something as input and return us expected email. For that, we will create a procedure call expression and assign a function module to it which will have the logic written for email.

Here, I created a FM – ZFI_FETCH_SENDER_EMAIL with two importing parameters which I can expect from the OPD’s decision table – DT_EMAIL_SETTINGS.

SAP S/4HANA, SAP ABAP Development, SAP ABAP Environment, SAP Business Technology Platform, SAP ABAP Career, SAP ABAP Skills, SAP ABAP Jobs, SAP ABAP Prep, SAP ABAP Preparation, SAP ABAP Tutorial and Materials, SAP ABAP Guides, SAP ABAP Learning, SAP ABAP Prep, SAP ABAP Preparation

If we notice the available context data objects once again, we have Document ID, Output Type, Recipient, and Role as condition parameters, to which we can expect Email Template and Sender Email as resulting parameter.

So, while creating the Procedure Call expression and corresponding FM, we can use either of the condition parameter as importing parameter and resulting parameters as exporting parameters.

In my case, I needed Company Code and Output Type as importing parameter to determine the email address. So, I needed a Procedure Call expression.

The pre-requisite is that the custom BRF+ application – ZFI_TEXT_DETERMINATION must be of Storage Type: System.

SAP S/4HANA, SAP ABAP Development, SAP ABAP Environment, SAP Business Technology Platform, SAP ABAP Career, SAP ABAP Skills, SAP ABAP Jobs, SAP ABAP Prep, SAP ABAP Preparation, SAP ABAP Tutorial and Materials, SAP ABAP Guides, SAP ABAP Learning, SAP ABAP Prep, SAP ABAP Preparation

The Procedure Call: GET_SENDER_EMAIL must have Access Level: Global so that it can be access outside the scope of our custom BRF+ application.

SAP S/4HANA, SAP ABAP Development, SAP ABAP Environment, SAP Business Technology Platform, SAP ABAP Career, SAP ABAP Skills, SAP ABAP Jobs, SAP ABAP Prep, SAP ABAP Preparation, SAP ABAP Tutorial and Materials, SAP ABAP Guides, SAP ABAP Learning, SAP ABAP Prep, SAP ABAP Preparation

We map our FM to the Procedure Call –

SAP S/4HANA, SAP ABAP Development, SAP ABAP Environment, SAP Business Technology Platform, SAP ABAP Career, SAP ABAP Skills, SAP ABAP Jobs, SAP ABAP Prep, SAP ABAP Preparation, SAP ABAP Tutorial and Materials, SAP ABAP Guides, SAP ABAP Learning, SAP ABAP Prep, SAP ABAP Preparation

And also map the importing and exporting parameters with the context data objects –

SAP S/4HANA, SAP ABAP Development, SAP ABAP Environment, SAP Business Technology Platform, SAP ABAP Career, SAP ABAP Skills, SAP ABAP Jobs, SAP ABAP Prep, SAP ABAP Preparation, SAP ABAP Tutorial and Materials, SAP ABAP Guides, SAP ABAP Learning, SAP ABAP Prep, SAP ABAP Preparation

Once this is done, we can look for our custom procedure call in the Table Settings Insert Column option and we can assign it to the Sender Email column –

SAP S/4HANA, SAP ABAP Development, SAP ABAP Environment, SAP Business Technology Platform, SAP ABAP Career, SAP ABAP Skills, SAP ABAP Jobs, SAP ABAP Prep, SAP ABAP Preparation, SAP ABAP Tutorial and Materials, SAP ABAP Guides, SAP ABAP Learning, SAP ABAP Prep, SAP ABAP Preparation

In each of the step, I would recommend to simulate the expressions to validate if you are doing it right.

Receiver Email Configuration: Email Recipient


In case of Receiver’s email address, we are fetching the email from customer master data. So, I created a FM – ZFI_FETCH_RECEIVER_EMAIL and from the available context, I used Recipient as IV_RECEIVER.

SAP S/4HANA, SAP ABAP Development, SAP ABAP Environment, SAP Business Technology Platform, SAP ABAP Career, SAP ABAP Skills, SAP ABAP Jobs, SAP ABAP Prep, SAP ABAP Preparation, SAP ABAP Tutorial and Materials, SAP ABAP Guides, SAP ABAP Learning, SAP ABAP Prep, SAP ABAP Preparation

A Procedure Call with Access Level: Global with same importing and exporting parameter and mapping of parameters with the available context data objects –

SAP S/4HANA, SAP ABAP Development, SAP ABAP Environment, SAP Business Technology Platform, SAP ABAP Career, SAP ABAP Skills, SAP ABAP Jobs, SAP ABAP Prep, SAP ABAP Preparation, SAP ABAP Tutorial and Materials, SAP ABAP Guides, SAP ABAP Learning, SAP ABAP Prep, SAP ABAP Preparation

Once this is done, assign the procedure call expression to the Email Address column in the OPD’s decision table – DT_EMAIL_RECEIVER and tada! We are done.

SAP S/4HANA, SAP ABAP Development, SAP ABAP Environment, SAP Business Technology Platform, SAP ABAP Career, SAP ABAP Skills, SAP ABAP Jobs, SAP ABAP Prep, SAP ABAP Preparation, SAP ABAP Tutorial and Materials, SAP ABAP Guides, SAP ABAP Learning, SAP ABAP Prep, SAP ABAP Preparation

If we do not hardcode the Recipient in the OPD’s decision table, it automatically picks up for the receiver for which the invoice has triggered.

No comments:

Post a Comment