Smart Forms Part 6: Tables, Templates, Loops and Conditions
Choose the right node for structured output: table nodes for dynamic item lists with header/main area/footer, templates for fixed grids, loops, line types and cell layout, sorting and events (subtotals), calculations, and conditions on nodes.
Explanation
📌 KEY POINTS
✅ Table node: dynamic number of rows (items) with header, main area and footer; header can repeat on each page.
✅ Template: fixed grid with a fixed number of rows/columns (e.g. address block, summary box).
✅ Table nodes support sorting with events (subtotals on sort change) and the "Calculations" tab for totals.
⚠️ Line types must add up exactly to the table width, otherwise you get errors or shifted columns.
━━━━━━━━━━━━━━━━━━━━
▶ WHERE WE ARE
Part 5 defined windows. Inside the main window, the table node prints the items.
━━━━━━━━━━━━━━━━━━━━
▶ 1. TABLE NODE
- Data tab: loop over IT_ITEMS INTO GS_ITEM (optional WHERE condition).
- Table tab: line types (e.g. LINE_HEADER, LINE_ITEM, LINE_TOTAL) with column widths; borders.
- Header: printed at the start and optionally on every new page ("at page break").
- Main area: one row per item; cells contain text nodes with &GS_ITEM-…&.
- Footer: at the end (totals) or at each page end.
━━━━━━━━━━━━━━━━━━━━
▶ 2. SORTING AND EVENTS
- Data tab → sort criteria (e.g. MATKL) with "event on sort begin/end".
- Event nodes print group headers or subtotals.
━━━━━━━━━━━━━━━━━━━━
▶ 3. CALCULATIONS TAB
- Operation total/count/max over a field: e.g. total GS_ITEM-NETWR into GV_TOTAL, time "after loop".
- Avoid manual summing in program lines when the tab suffices.
━━━━━━━━━━━━━━━━━━━━
▶ 4. TEMPLATE
- Fixed layout of cells; each cell addressed by row/column; no looping.
- Use for boxes like invoice summary or address-and-reference blocks.
━━━━━━━━━━━━━━━━━━━━
▶ 5. LOOP NODE
Loop without table layout — for repeated text blocks (e.g. conditions, notes).
━━━━━━━━━━━━━━━━━━━━
▶ 6. CONDITIONS
- Conditions tab on any node: field comparisons, events (only on first page, only after main window end).
- Alternative node: TRUE/FALSE branches.
━━━━━━━━━━━━━━━━━━━━
▶ STEP BY STEP
- Create a table node over IT_ITEMS with header, item line and footer.
- Add sorting by material group with subtotal event.
- Add a total via the Calculations tab and print it in the footer.
✅ CHECKPOINT: you can print dynamic item lists with headers, subtotals and totals.
Code example
* ===== Table node ITEMS (in MAIN window) =====* Data tab : Internal table IT_ITEMS INTO GS_ITEM* Sort criteria : MATKL [x] event on sort end* Table tab : line type HEAD cells 2 cm | 4 cm | 7 cm | 2.5 cm | 2.5 cm (= 18 cm)* line type ITEM same widths* line type SUBT 11 cm | 7 cm* Header : row HEAD [x] at start [x] at page break -> repeats on every page* cells: Pos | Material | Description | Quantity | Amount* Main area : row ITEM* &GS_ITEM-POSNR& | &GS_ITEM-MATNR& | &GS_ITEM-ARKTX&* &GS_ITEM-FKIMG& &GS_ITEM-VRKME& | &GS_ITEM-NETWR& &GS_ITEM-WAERK&* Event MATKL end: row SUBT -> "Subtotal &GS_ITEM-MATKL&: &GV_SUBTOTAL&"* Calculations: Total GS_ITEM-NETWR -> GV_TOTAL time: after loop* Total GS_ITEM-NETWR -> GV_SUBTOTAL (reset in event via program lines)* Footer : row SUBT -> "Total: &GV_TOTAL& &IS_HEADER-WAERK&" [x] at end * ===== Program lines in the sort-end event (reset the subtotal) =====* Input: GV_SUBTOTAL Output: GV_SUBTOTALCLEAR gv_subtotal. * ===== Template SUMMARY (fixed 3 x 2 grid) =====* row 1: Net amount | &GV_TOTAL&* row 2: Tax | &IS_HEADER-MWSBK&* row 3: Gross | &IS_HEADER-GROSS&Real project scenario
An invoice form printed column headers only on the first page; on 10-page invoices, auditors could not read pages 2–10 without flipping back. The header row wasn't set to repeat at page breaks.
Enabling "at page break" for the header and moving totals to the footer "at end" fixed the layout. Subtotals per material group via the sort event replaced 40 lines of program-lines code.
Common mistakes
- Templates used for dynamic item lists.
- Line type widths not matching the table width.
- Header not repeating on new pages.
- Manual totals in program lines where Calculations suffice.
- Subtotal variables not reset per group.
Best practices
- Table node for dynamic data, template for fixed grids.
- Repeat headers at page breaks.
- Use sort events for group headers/subtotals.
- Use the Calculations tab for totals.
- Keep cells simple; format in driver/initialization.
Interview angle
Questions: "Table vs template in Smart Forms?", "How do you print subtotals?", "How do you repeat table headers on each page?"
Strong answer: table node for dynamic rows with header/main/footer and line types summing to the width; template for fixed grids; sort criteria with events for subtotals; Calculations tab for totals; header "at page break" to repeat; conditions and alternative nodes.
Practice this lesson
Quick check
1. How are subtotals per material group best printed in a table node?
2. When should a template be used instead of a table node?
3. Line type widths in a table node must...
Interview questions
1. A purchase order form must print items grouped by material group with subtotals and a grand total. How do you build it in Smart Forms?
Answer it in your own words first, then compare.
2. A SmartForm item table does not continue to the second page. What is the likely issue?
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 2: Anatomy of a Smart Form and the Driver Program
- 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 7: Texts, Translations and Language Handling
- Smart Forms Part 8: Debugging Smart Forms and Generated Function Modules