Translations:
Submitting a report to the spool and receiving PDF.
Don't forget to click ⭐ if you like it!
- What is it?
- What is this for?
- Why not just use cl_bp_abap_job?
- Installation
- Using
- Diagrams
- How to contribute
- Got questions
- Logo
SAP Spool PDF is a lightweight ABAP utility that simplifies generating PDFs from SAP reports. It provides a clean, object-oriented interface to submit a report to the spool and retrieve the output as a PDF file without dealing with low-level conversion logic.
Often, you need a report’s output as a PDF in xstring or binary format. One clean and non-intrusive way to achieve this is by submitting the report to the SAP spool (typically in the background) and then converting the spool request into a PDF using its spool ID. This approach avoids modifying standard SAP code—making it safer, upgrade-friendly, and easier to maintain.
SAP’s standard class cl_bp_abap_job can run reports in the background—but it only supports passing parameters via a variant. (Let me know if that’s changed!) While variants work, they’re not always convenient: you either have to predefine one or create it dynamically at runtime, which adds complexity and overhead.
SAP Spool PDF gives you more flexibility. It lets you run any report in the background and generate a PDF from its output passing parameters directly, via a variant, or even both.
Thanks to its minimal and intuitive API, you can get the resulting PDF as an xstring in a single line ready to save, display, email, or process further.
Install the package using abapGit. Just clone the repository into your SAP system, and you’re ready to go!
Example
TYPES ty_pernr TYPE n LENGTH 8.
DATA lt_pernr TYPE RANGE OF ty_pernr.
" This example demonstrates how to generate 2-NDFL certificates (HCM module).
" All individual PDF documents are automatically merged into a single file.
DATA(lv_year) = '2021'.
lt_pernr = VALUE #( sign = 'I' option = 'EQ' ( low = 00000001 ) ).
DATA(lv_filename) = `C:\TEMP\spdf_merged_test.pdf`.
TRY.
DATA(lo_report) = NEW zcl_spdf_report( iv_name = 'HRULNDFL'
iv_variant = 'T1' ).
lo_report->add_param( iv_name = 'PNPPERNR'
ia_data = lt_pernr ).
lo_report->add_param( iv_name = 'P_YEAR'
ia_data = lv_year ).
" Cases:
" 1) Getting xstring
DATA(lv_pdf) = lo_report->submit_to_sap_spool( )->get_merged_pdf( )->to_xstring( ).
" 2) Save and show PDF
lo_report->get_merged_pdf( )->save_local( lv_filename )->show( ).
" 3) Send email
lo_report->get_merged_pdf( )->send( iv_email = 'test@test.com'
iv_filename = lv_filename
iv_subject = 'This is an email with a PDF attachment' ).
CATCH zcx_spdf_exception
cx_rspo_spoolid_to_pdf INTO DATA(lx_e).
WRITE lx_e->get_text( ).
ENDTRY.will help you. Contributions are welcome! Please follow the official contribution guide from abapGit to get started.
If you have any questions, feature ideas, or just want to share feedback - feel free to open a new (GitHub issue).
Project logo designed by pixel-buddha