How to Email Smartform as PDF Attachment to Multiple Users?


Sending Smartform output as PDF in an e-mail is a topic which has been queried and answered multiple times in numerous forums. But, whenever we get this requirement, we need to scramble for our previous notes or hit the search engine. Recently, when I received this request from my business, it was nothing different to me as well. 🙂

After delivering this development, I was looking for a repository where I can put my code so that if I have the same requirement in my future Projects, I know, exactly where to look. At this point, which repository is better than SAPYard for SAP Technical stuff. (just kidding) 🙂

Apart from the motive of saving my snippet in the web, the other better objective was to reveal to all freshers in SAP ABAP that, you just have to follow 4 steps for this requirement.

  1. Get the Smartform output in OTF (Other Text Format).
  2. Convert the OTF to Hexa decimal string format.
  3. Convert the Hexa decimal string format to Binary format.
  4. Build the email body and attach the Binary table as an attachment using CL_DOCUMENT_BCS-ADD_ATTACHMENT and send the email using CL_BCS class.

If you understand these four steps, you need not look the search engine in future for such developments. 🙂 .

Let me be little more specific with the technicalities of the four steps.

1. Smartform Output in OTF

When you call your smartform, you would get the Smart Forms OTF Table in IMPORTING parameter  JOB_OUTPUT_INFO component OTFDATA which is the structure for Smart Forms: Table OTF.

For the below snippet, the OTF data would be in w_return-otfdata.

2. Convert the OTF to Hexa decimal string format.

The below snippet is to convert the OTF to XSTRING format.

3. Convert the Hexa decimal string format to Binary format.

Just a thought. If you are able to find any function to convert OTF directly to Binary Format then you can skip the 2nd step of converting OTF to Hexa. 🙂

4. Use CL_DOCUMENT_BCS class and method ADD_ATTACHMENT to attach the document and use CL_BCS class to email the document.

If you want to read more about CL_BCS class usage, then please check this useful post ‘Send an e-mail with subject line greater than 50 characters‘.

If you have a deadline, I can understand, you do not want more Gyan (Sanskrit work which roughly translates to Preaching). 🙂 You are more interested in getting a working code which you can fit into your system. Do not worry, I will not disappoint you. Please find a working snippet which converts the Smartform to PDF and emails it as a PDF attachment.

Are you new to SAPUI5? Check the issues faced by fresher in SAPUI5.

For our test, we created a simple smartform with just a logo and one text line.

Hit the test icon to test the smartform stand alone.

You would see the function module linked to this smartform. Hit the test icon again. Now you see the parameters of the function, hit test icon again.

This is our smartform output.

Are you HANA ABAP ready? Check how you can write your first Program in HANA.

Now, our program should attach this smartform output as PDF and email it to multiple users.

Let’s execute our program. Give the smartform name and the email ids. For the test, we are sending just to two users. You might enter as many users you want.

Execute and you would get this message (if you are testing our program).

Go to t-code SOST to see if email really went out. Yes!! it did.

Let us check what this email has for us.

Cool, we have the email body and an attachment.

Let us check if the attachment is the same smartform we checked above in stand alone mode.

Bingo!! It is in deed the smartform in the PDF format.

I am planning to refer to this page for my future use case where I have a similar requirement. What do you think?

I want to hear now from you now. Do you have a better approach?

If you have or not, in either case, please leave your comments and let us start a healthy debate.


    • Hello Ram,
      Thank you for appreciation. Let me know what kind of learning material you’re looking for in future.

    • Hello Feleciano,
      Thank you for appreciation. Let me know what kind of learning material you’re looking for in future.

Leave a Reply to Ram Daruru Cancel reply

Please enter your comment!
Please enter your name here