SAP TM – Auto populate Email Receiver for PPF Action / PPF Output/ PDF Forms
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 . WHEN 'ZCUSTOM_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 ASSIGNING FIELD-SYMBOL(<fs_rec>). lv_email = <fs_rec>-e_mail. TRY. DATA(lo_rec) = cl_cam_address_bcs=>create_internet_address( i_address_string = lv_email ). CATCH cx_address_bcs. ENDTRY. io_send->add_recipient( EXPORTING i_recipient = lo_rec " Recipient of Message ). CLEAR lo_rec. ENDLOOP. WHEN OTHERS. ENDCASE.
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. lo_facade ?= /bofu/cl_ppf_badi_facade=>get_instance( ). CALL METHOD lo_facade->if_ex_complete_proc_ppf~complete_send EXPORTING io_context = io_context ip_protocol = ip_protocol ip_no_protocol = ip_no_protocol io_send = io_send io_medium = io_medium flt_val = flt_val.
Save , Activate, and Now Try Again.
The recipients are now fetched and updated in the Recipients Tables.
This can be a very common requirement during the output management of SAP TM. I hope this blog helps.
thanks for sharing!!! Excelent.
Great blog. Is it possible to fetch the list of recipients using BRF+ or this is the only way to do it?
You can use BRF+ and call the class to evaluate the BRF condition to get the recipients , it depends on your requirements
How to perform the document attached. In IO_SEND, providing the document but not able to view in the output. Please provide some insight into it.
You can use the document create method of BCS class by passing the document type and content and try that . Should work ideally .