A common functionality in SAP TM can be to send the email with the attachment to a particular receiver or a set of them when an action is executed in Output Management. This can be achieved manually by adding the email id into the Communication Tab and executing the action but checking the email checkbox.
But the requirements can be like, the receiver should be auto-populated based on certain conditions and add into the receiver table in the Output Management tab whenever the action is executed.
This blog will show the steps needed to achieve this functionality.
Assuming, the reader has an idea about the PPF output functionality and SAP TM, moving forward with the explanation.
Let us see first the problem and then proceed to the solutions.
Open a Freight Order
2. Generate an action using the Generate button under the Output Management Tab. When an action is generated, the PDF associated with the form can be displayed in the preview mode. And when you execute the Action , the PDF can be sent as an email, or printed .
3. If you want to send an email of the PDF, you need to provide the recipient information in the recipient table under the Communication tab of the specified action. The recipient can be an email address, an SAP user, a FAX number, or a Business Partner.
This is the manual way to add the Email Address into the recipient and when the Action is generated, the email is sent to the added recipients here.
Now, the requirement is, whenever the action is generated, we should populate the recipients based on some logic and the recipients are prefilled so the user need not do the manual step.
Output Management in SAP TM is done using PPF (Post Processing Framework) which provides print class and print service class to add custom logic to call a custom form.
The print service class is derived from the class /BOFU/CL_PPF_SERV_FOR_BO and has a method /BOFU/IF_PPF_SERV_FOR_BO~COMPLETE_SEND which can be used to add the recipient information. Redefine this method and add the below code to create an internet address/email and add it to the recipient's table. This method has an instance of the BCS communication class which is used to send the email. We need to use this instance object and add the recipients into it.
"Print Service Class logic should segregate for action specific logic
CASE is_ppf_act-ppf_action .
** Add your custom logic to get all recipients
** Loop at your recipients and a create a recipient object for each and add to the BCS class instance
** Available in the method signature.
LOOP AT lt_rec
i_recipient = lo_rec " Recipient of Message
Save, activate, and open the freight order and try testing.
Did it work? No, right, that's because there is another step to it, which is needed for this method to be executed in the framework.
SAP's Output Management Guide gives a BADI COMPLETE_PROC_PPF which needs to be implemented for the PPF print service class method COMPLETE_SEND to work.
Go-To Se18 - Create an implementation of the BADI COMPLETE_PROC_PPF. This BADI is a filter dependent BADI. The filter needed here is your Action profile and Action that was created for sending the PDF.
In the resultant Implementation Class of the BADI, Implement the method IF_EX_COMPLETE_PROC_PPF~COMPLETE_SEND and add the below code. This code calls the PPF service class COMLETE_SEND method by the framework.
DATA: lo_facade TYPE REF TO /bofu/cl_ppf_badi_facade.