Additional Blogs by SAP
Showing results for 
Search instead for 
Did you mean: 
Community Manager
Community Manager

Have you ever heard the comment from someone, "Boy I sure would like to get this report as a PDF on my computer in order to send it to Bob over in accounting. He doesn't have a login for this BSP application and it'd be great to send him this data." Well I haven't either, OK, not exactly like it but similiar. It left me with two choices, 1, give "Bob" a login or 2, figure out how to output my report as PDF.
Being a frequent visitor to SDN I remembered reading a few things about PDF and outputing so I began my searching...

BSP Programming: Handling Of Non-HTML Documents

Generate file .doc or .pdf as from a text

Well after playing around with the information, and I mean really good information given in these posts/weblogs I realized that I still had a few questions left unanswered. Namely, "How do I get the data as OTF?".

This lead me to post a new topic in the BSP forum called PDF output and with the help my fellow SDNers I think we've come up with all the info needed to enlighten those stubmling around in the dark like myself.

Special thanks go out to...

So we came down to basically 3 major possibilities for doing this.

  • External Tools

To get started let's create our BSP page.

Page Layout

This is basically the code from Brian's weblog with a couple of new radio options.

Page Attributes

style="width:350px;border:thin inset;background:lightgrey;background-color:lightgrey">\ content\             TYPE\     STRING
display_type\     TYPE\     STRING
display_url\     TYPE\     STRING
file_content\     TYPE\     XSTRING
file_length\     TYPE\     STRING
file_mime_type\     TYPE\     STRING
file_name\     TYPE\     STRING


That there will get all of the normal stuff working that Brian describes in his weblog on dealing with NON-HTML documents.

Now let's go into each of these 3 possibilites and see which one works best for you...


This seems to be the best possible solution; to be honest with you, I like this one. Not sure why but I do. First things first is that you have to create a SmartForm (transaction SMARTFORMS) and once you create the SmartForm just in the menu click ENVIRONMENT - FUNCTION MODULE NAME. You see once you create the SmartForm and activate it it generates a function module.

Let's make a SmartForm

I started by calling transaction SMARTFORMS, there I gave my SmartForm a name and selected "CREATE"

Once created I started to edit the SmartForm, the first step was the Form Interface, I entered my table parameters there.

Then I defined my global variables for the table and the table structure.

Then on the Initalization tab of the Global section I was able to initialize my table.

Then simply click on your Page and you can then create a table element, which then under the data table you define your table LOOP.

Then for test purposes I simply added one cell of data and one text label to the cell, then dragged from my field list box the name of one cell to the new text box.

Once that was all complete I was able to "activate" the SmartForm and then get the function module name from the menu option.

So got your SmartForm? OK, then let's modify our code to add in for that. Go to your OnInputProcessing Event Handler and append this to the bottom of the existing code.


As you can see we give our now selected table of data to the SmartForm for processing and then the OTF encoded results from the SmartForm to the CONVERT_OTF FM for processing.

Did you try it? Did you get your PDF file like me?


Raja provided a nice code sample to work with for this option.

sy-spono will then contain your Spool number which you can then use with the function module CONVERT_ABAPSPOOLJOB_2_PDF with the Spool number as a parameter. This will return a table, PDF STRUCTURE TLINE, which you can then save with .pdf extension. As Raja pointed out "I havent tried this myself inside a BSP application, but i feel that it should work."

From a logic point of view I will say that since the normal ABAP write statements don't work directly in the BSP you would have to really think hard to figure out how to get this to work. We are now attempting to do just that and will post back with an update to the weblog if we figure it out.

Another option would be if you had the spool number first, for example from a select list or something. You would be as dynamic as with the SmartForm method but it should also work, just gotta convert your PDF table to XSTRING.

I think that should work, we will keep you posted on further developments using this method.

Here is a solution from Raja: SPOOL TO PDF

External Tools

Now there are lots of these tools out there, Eddy points out HTMLDOC. Eddy goes on to tell us that all we have to is

"The way to go is to install HTMLDOC, then make an external command. In your BSP page (with extension pdf, is needed for MIE) make you HTML and write it to temp file. Call the external command with the temp file as input. Then read the pdf and set it as content and set all response headers for pdf. Clean up the temp files. It works good and fast.

There are also JAVA and ActiveX tools out there as well. Each of you will have to decide your own strategy of course. Personally if the system can already do it then why install another component that you may have to worry about compatability issues with in the future?

Where does all this leave us?

So as you can see there are often many possiblities for problems you encounter and it is just a matter of deciding which one works best for you. In this case does it make sense to create a SmartForm for each and every item you want to print out? Perhaps if you have a Corporate Identity that you must adhere to then this could be the best way.

The "spool" seems like a great choice simply because you don't have create a SmartForm first.  In fact a clever person might just have a ABAP report that runs and creates the Spool outputs and then a BSP which lets a person select an existing Spool and then retrieve it as PDF.

External tools are always available and there are lots of them out there, however, you have to ask yourself "Do you really want to add a component that may not be compatible after the next SP or Release?". These are problems that sometimes arise as we move into the future, whereas, an internal solution such as SmartForms or ABAPSPOOL to PDF well those I think will be supported in the future.

Please consider this weblog a work in progress as I don't think we've heard the end of our efforts with ABAP Spool and I'm sure there are quite a few more possible solutions out there and I hope you'll share yours with us as well!

What the future holds!!

From Matthias Zeller, Indeed Interactive Forms is the "next generation" forms tool in SAP (and not only for interactive, but also for print forms). It is available starting with Web AS 6.40. Smart Forms and SAPscript will be continue to be available but all new development around SAP forms will be done in the new Interactive Forms. The Adobe document services (ADS) which are part of Interactive Forms can generate different output including PDF, PS, PCL and ZPL (for Zebra Label printers).
So with Interactive Forms you will be able to generate PDF in an SAP system natively by merging forms data with a form template (so you do not need to create OTF anymore and use the CONVERT_OTF libraries to generate PDF). This can be configured in ABAP using transaction SFP or with Web Dynpro for Java to create PDF documents embedded in a Web UI (and in the future also with Web Dynpro for ABAP).
The PDFs generated with ADS are actually the latest version PDF 1.6 and can be made accessible to blind people via screen readers.

From Jonathan Bourne, Just wanted to mention that rather than hunting for the Smartforms function module name the following function module can be used:


This FM takes the Smartform name and returns the function module name. This is a more robust solution as the Smartform may receive a different FM name when it is transported to other systems.