Smart Forms Part 2: Anatomy of a Smart Form and the Driver Program
Build a complete driver program for a Smart Form: selection screen, data retrieval into interface structures, SSF FUNCTION MODULE NAME, control parameters (preview, no dialog, getotf), output options, printing multiple documents in one spool with SSF OPEN/SSF CLOSE, and checking job output info.
Explanation
📌 KEY POINTS
✅ The driver program owns: selection, data retrieval, determining the FM, output options and error handling.
✅ Control parameters (SSFCTRLOP): PREVIEW, NO_DIALOG, GETOTF (return OTF instead of printing), NO_OPEN/NO_CLOSE (several forms in one spool).
✅ Output options (SSFCOMPOP): TDDEST (printer), TDIMMED (print immediately), TDNEWID (new spool), TDCOPIES.
⚠️ Calling the form once per document without NO_OPEN/NO_CLOSE creates one spool per document — thousands of spools in mass printing.
━━━━━━━━━━━━━━━━━━━━
▶ WHERE WE ARE
Part 1 showed the basic call. Now we build a driver that prints many documents properly.
━━━━━━━━━━━━━━━━━━━━
▶ 1. ANATOMY OF THE FORM (SMARTFORMS)
- Global settings: form attributes (style, language), form interface, global definitions (data, types, initialization).
- Pages and windows: first page, next page, main window, secondary windows (header, footer, address).
- Nodes within windows produce output.
━━━━━━━━━━━━━━━━━━━━
▶ 2. DRIVER RESPONSIBILITIES
- Selection screen (document numbers, printer, preview flag).
- Read and prepare data into structures matching the form interface.
- Get FM name with SSF_FUNCTION_MODULE_NAME.
- Set control and output options.
- Call the FM (per document) and handle exceptions.
- Report results (spool numbers via JOB_OUTPUT_INFO).
━━━━━━━━━━━━━━━━━━━━
▶ 3. MULTIPLE DOCUMENTS IN ONE SPOOL
- SSF_OPEN before the loop; each call with NO_OPEN = 'X' and NO_CLOSE = 'X'; SSF_CLOSE after the loop.
- Alternative: first call NO_CLOSE = 'X', middle calls NO_OPEN/NO_CLOSE, last call NO_OPEN only.
━━━━━━━━━━━━━━━━━━━━
▶ 4. BACKGROUND AND NO DIALOG
- NO_DIALOG = 'X' suppresses the print dialog (required in background, output control).
- In background, a printer (TDDEST) must be given.
━━━━━━━━━━━━━━━━━━━━
▶ 5. OTF / PDF
GETOTF = 'X' returns OTF in JOB_OUTPUT_INFO-OTFDATA; convert to PDF with CONVERT_OTF (Part 8 / email scenarios).
━━━━━━━━━━━━━━━━━━━━
▶ STEP BY STEP
- Build the driver from the code example for your own form.
- Print 3 documents and check SP01: one spool with 3 documents.
- Remove SSF_OPEN/SSF_CLOSE and compare the number of spools.
✅ CHECKPOINT: you can write a driver that prints many documents efficiently in one spool.
Code example
REPORT zsf_invoice_driver. TABLES vbrk.SELECT-OPTIONS s_vbeln FOR vbrk-vbeln OBLIGATORY.PARAMETERS: p_dest TYPE rspopname DEFAULT 'LP01', p_prev AS CHECKBOX DEFAULT 'X'. DATA: lv_fm TYPE rs38l_fnam, ls_control TYPE ssfctrlop, ls_output TYPE ssfcompop, ls_jobinfo TYPE ssfcrescl, lt_vbrk TYPE STANDARD TABLE OF vbrk, ls_vbrk TYPE vbrk, ls_header TYPE zsf_inv_header, lt_items TYPE ztt_inv_items. START-OF-SELECTION.* ===== Step 1: documents to print ===== SELECT * FROM vbrk INTO TABLE lt_vbrk WHERE vbeln IN s_vbeln. IF lt_vbrk IS INITIAL. MESSAGE 'No billing documents found' TYPE 'S' DISPLAY LIKE 'E'. RETURN. ENDIF. * ===== Step 2: FM name ===== CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME' EXPORTING formname = 'ZSF_INVOICE' IMPORTING fm_name = lv_fm EXCEPTIONS OTHERS = 1. IF sy-subrc <> 0. MESSAGE 'Form ZSF_INVOICE not active' TYPE 'E'. ENDIF. * ===== Step 3: one spool for all documents ===== ls_output-tddest = p_dest. ls_output-tdnewid = 'X'. ls_control-no_dialog = 'X'. ls_control-preview = p_prev. CALL FUNCTION 'SSF_OPEN' EXPORTING output_options = ls_output control_parameters = ls_control EXCEPTIONS OTHERS = 1. ls_control-no_open = 'X'. ls_control-no_close = 'X'. * ===== Step 4: one form call per document ===== LOOP AT lt_vbrk INTO ls_vbrk. PERFORM prepare_data USING ls_vbrk CHANGING ls_header lt_items. CALL FUNCTION lv_fm EXPORTING control_parameters = ls_control output_options = ls_output is_header = ls_header it_items = lt_items EXCEPTIONS OTHERS = 1. IF sy-subrc <> 0. WRITE: / 'Error printing', ls_vbrk-vbeln. ENDIF. ENDLOOP. * ===== Step 5: close spool, get info ===== CALL FUNCTION 'SSF_CLOSE' IMPORTING job_output_info = ls_jobinfo EXCEPTIONS OTHERS = 1. FORM prepare_data USING is_vbrk TYPE vbrk CHANGING cs_header TYPE zsf_inv_header ct_items TYPE ztt_inv_items. CLEAR: cs_header, ct_items. cs_header-vbeln = is_vbrk-vbeln. cs_header-fkdat = is_vbrk-fkdat. cs_header-kunag = is_vbrk-kunag. SELECT posnr matnr arktx fkimg vrkme netwr FROM vbrp INTO CORRESPONDING FIELDS OF TABLE ct_items WHERE vbeln = is_vbrk-vbeln.ENDFORM.Real project scenario
A reprint program for 5,000 invoices created 5,000 spool requests, overwhelmed the spool system and printed every invoice with a separate cover page on the high-speed printer.
Using SSF_OPEN, NO_OPEN/NO_CLOSE and SSF_CLOSE put all invoices into one spool. Printing became one job, and the print shop could handle it in a single run.
Common mistakes
- One spool per document in mass printing.
- Missing NO_DIALOG in background.
- No printer passed in background.
- Data selection in the form instead of the driver.
- Ignoring exceptions per document.
Best practices
- SSF_OPEN / NO_OPEN / NO_CLOSE / SSF_CLOSE for batches.
- NO_DIALOG and TDDEST for background.
- Prepare data per document in a FORM or class.
- Log errors per document and continue.
- Use GETOTF for PDF/email scenarios.
Interview angle
Questions: "What does a Smart Form driver program do?", "How do you print many forms in one spool?", "What are control parameters?"
Strong answer: selection, data preparation, SSF_FUNCTION_MODULE_NAME, control (PREVIEW, NO_DIALOG, GETOTF, NO_OPEN/NO_CLOSE) and output options (TDDEST, TDNEWID, TDIMMED), call FM and handle exceptions; batch printing with SSF_OPEN, NO_OPEN/NO_CLOSE per call, SSF_CLOSE; JOB_OUTPUT_INFO for spool/OTF.
Practice this lesson
Quick check
1. A form prints fine in preview but fails in background output. Which setting is most likely missing?
2. To suppress the print dialog set:
3. For Smart Forms, which function module returns the generated runtime function module name?
Interview questions
1. What is the role of a SmartForm driver program?
Answer it in your own words first, then compare.
2. Printing 5000 invoices in one job is slow. Options?
Answer it in your own words first, then compare.
Reference-verified: the steps are checked against official SAP documentation and tutorials, and object and field names in the sample code are checked for consistency. The code has not been compiled or run on an SAP system by ERPClimb. Syntax marked release-dependent varies by SAP release, so check it in your own system.
More lessons in this topic
- Smart Forms Part 1: What Smart Forms Are and How Printing Works
- Smart Forms Part 3: Output Determination and the Print Program Entry
- Smart Forms Part 4: Form Interface — Import Parameters, Tables and Global Data
- Smart Forms Part 5: Pages, Windows and Main Window Flow
- Smart Forms Part 6: Tables, Templates, Loops and Conditions
- Smart Forms Part 7: Texts, Translations and Language Handling
- Smart Forms Part 8: Debugging Smart Forms and Generated Function Modules