If you’ve ever worked with SAP SmartForms, you probably know how easy it is to generate beautiful, print-ready documents directly from your ABAP programs. But what if you need to automatically save that SmartForm output as a PDF file — and not just any PDF, but one with a custom filename defined at runtime?
In this tutorial, we’ll walk through the process of:
Calling the SmartForm programmatically.
Converting the output to PDF.
Downloading the file with your own custom filename.
Let’s get started.
- Get the SmartForm Function Module Name Before calling a SmartForm, we need its generated function module name. This can be retrieved with SSF_FUNCTION_MODULE_NAME.
DATA: lv_fm_name TYPE rs38l_fnam,
lv_bin_filesize TYPE i,
lt_pdf_content TYPE TABLE OF solix.
CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'
EXPORTING
formname = 'Z_MY_SMARTFORM'
IMPORTING
fm_name = lv_fm_name.
- Call the SmartForm and Get the PDF Output We’ll call the SmartForm’s function module with parameters that tell it to generate PDF output (PDF1).
DATA: ls_job_output TYPE ssfcrescl.
CALL FUNCTION lv_fm_name
EXPORTING
control_parameters-no_dialog = 'X'
output_options-tdprinter = 'PDF1'
user_settings = 'X'
IMPORTING
job_output_info = ls_job_output
EXCEPTIONS
OTHERS = 1.
lt_pdf_content = ls_job_output-otfdata.
- Convert OTF to PDF The SmartForm output is initially in OTF format. We’ll convert it to PDF binary using CONVERT_OTF.
DATA: lt_pdf_bin TYPE TABLE OF solix,
lv_pdf_size TYPE i.
CALL FUNCTION 'CONVERT_OTF'
EXPORTING
format = 'PDF'
IMPORTING
bin_filesize = lv_pdf_size
TABLES
otf = lt_pdf_content
lines = lt_pdf_bin
EXCEPTIONS
err_conv_not_possible = 1
OTHERS = 2.
- Download the PDF with a Custom Filename Now that we have our PDF binary, we can download it to the local machine with a dynamic filename.
DATA: lv_filename TYPE string.
lv_filename = |C:\Temp\Invoice_{ sy-datum }.pdf|.
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
bin_filesize = lv_pdf_size
filename = lv_filename
filetype = 'BIN'
TABLES
data_tab = lt_pdf_bin
EXCEPTIONS
OTHERS = 1.
Final Thoughts
With just a few function calls, you can:
Retrieve the SmartForm’s generated function module name.
Call it to produce PDF output directly.
Convert and download the PDF with a filename of your choice.
This approach is perfect for automated processes, batch jobs, or scenarios where users shouldn’t have to manually save files themselves.
If you’re working in environments where file access is restricted (like web-based SAP GUI), consider adapting this approach to store the PDF in an application server directory or send it via email automatically.
Related Resources
- Official SAP Documentation for SmartForms
- Base64 Converter Online Tool – Useful if you want to convert your generated PDF to Base64 for API transfers.
Top comments (0)