Smart Forms Part 5: Pages, Windows and Main Window Flow
Lessons are open to try during our launch period. Some advanced content may move to Pro later. AI practice limits apply separately.
Control the physical layout of Smart Forms: pages and next-page sequence, main window vs secondary windows, final windows, page breaks, page-dependent content (first page vs next pages), page numbering with SFSY fields, and common layout problems.
In this lessonShow sectionsHide sections
Visual overview
Expert visual walkthrough
Pages, Windows and Main Window Flow
SmartForms · Chapter-specific technical teaching map
Architecture hierarchy
Page node
Secondary windows
Main window
Overflow page
Tutor's chapter takeaway
Control the physical layout of Smart Forms: pages and next-page sequence, main window vs secondary windows, final windows, page breaks, page-dependent content (first page vs next pages), page numbering with SFSY fields, and common layout problems.
In a real project
A delivery note printed the customer address on every page, and on long deliveries the page count showed "Page 2 of 1". The address window lacked the "first page only" condition, and the page count was in a normal secondary…
Watch out for
• Different main window widths on pages. • Total page count outside a final window. • Missing Next page definition (only one page printed). • Secondary windows used for dynamic item lists. • No page protection for item…
The situation: a real project scenario
A delivery note printed the customer address on every page, and on long deliveries the page count showed "Page 2 of 1". The address window lacked the "first page only" condition, and the page count was in a normal secondary window processed before the total was known.
Adding the condition SFSY-PAGE = 1 and moving the page count to a final window fixed both issues.
Explanation
Part 4 of this series defined the data a form works with; now it's time to control where that data actually appears on the page. Only the main window flows: once it's full, output continues onto the next page, as defined by that page's "Next page" attribute. Secondary windows — header, address, footer — print fixed content once per page, while a final window is processed only at the very end, which makes it the right place to show totals or page counts.
On pages: a FIRST page typically carries a full header and address, while a NEXT page carries a more compact header; the page attribute "Next page" controls the flow, for example FIRST leading to NEXT, and NEXT leading to NEXT again; each page also has its own format (such as DINA4 or LETTER) and orientation.
There's exactly one main window per form, and it's placed on every page where the flow needs to continue; it holds the item table or loop — the dynamic part of the form — and must keep the same width on every page it appears on, even though its height can differ from page to page. A main window with different widths on different pages causes errors, so keeping that width identical everywhere is essential.
Secondary windows cover header, address, logo, footer, and page-number content, and their content is printed once per page on which the window appears; conditions can control when a window actually prints — for example, only on the first page, checked via SFSY-PAGE = 1, or configured through the window's own "Output options" → conditions.
A window of type "Final window" is processed after every other window, which makes it the place to show something like "Total pages," or totals computed while the main window was looping over its data.
Page breaks happen automatically whenever the main window fills up; they can also be triggered manually with the command node "Go to new page" — useful, for example, to start a new page per sales order inside a combined form — and a block can be protected from being split across a page break using "Protect against page break," which is useful for keeping an item and its associated texts together.
Page numbering is handled through system fields in a secondary window's text, such as "Page &SFSY-PAGE& of &SFSY-FORMPAGES&" (with formatting options such as &SFSY-PAGE(C)&); SFSY-PAGE gives the current page, SFSY-FORMPAGES the total number of pages in the form, and SFSY-JOBPAGES the total for the whole print job.
To practice, create a FIRST and a NEXT page sharing a main window of the same width, add a page-number window on both pages, and print 60 items to check the page break and numbering. By the end, you should be able to design multi-page forms with correct flow, headers, and page numbering.
Code example
* ===== Layout plan (SMARTFORMS) =====* Page FIRST (next page: NEXT)* Window LOGO (secondary) graphic node, only on FIRST* Window ADDRESS (secondary) address node, customer address* Window HEADER (secondary) invoice number, date* Window MAIN (main) item table width 18 cm* Window FOOTER (secondary) bank details* Window PAGENO (secondary) "Page &SFSY-PAGE& of &SFSY-FORMPAGES&"* Page NEXT (next page: NEXT)* Window HEADER2 (secondary) compact header* Window MAIN (main) same width 18 cm, taller* Window PAGENO (secondary)* Window TOTALS (final window) totals after all items processed * ===== Condition examples (Conditions tab of a node) =====* Only on first page : SFSY-PAGE = 1* Only if reprint : IV_REPRINT = 'X'* Only after last item : event "Only after end of main window" * ===== Command node for manual page break =====* Node type: Command -> "Go to new page" -> NEXT* Condition: GS_ITEM-VBELN <> GV_LAST_VBELN (new document in combined output) * ===== Program lines node to track the last document =====* Input : GS_ITEM Output: GV_LAST_VBELNGV_LAST_VBELN = GS_ITEM-VBELN. " runs after the page break check, so the next item's compare sees the new documentWatch out
Common mistakes
- Different main window widths on pages.
- Total page count outside a final window.
- Missing Next page definition (only one page printed).
- Secondary windows used for dynamic item lists.
- No page protection for item blocks.
Do this
Best practices
- One main window, same width everywhere.
- FIRST/NEXT page design.
- Final window for totals and page counts.
- Conditions for page-specific windows.
- Test with long and short documents.
In the interview
Interview angle
Questions: "Difference between main and secondary windows?", "What is a final window?", "How do you print Page X of Y?"
Strong answer: main window flows across pages (one per form, same width), secondary windows fixed per page, final window processed at the end; next-page sequence FIRST→NEXT; page breaks automatic or via command node; &SFSY-PAGE& of &SFSY-FORMPAGES&; conditions for page-specific content.
Practice this lesson
Quick check
0 of 3 questions attempted
Question 1 of 3
A 3-page purchase order prints items only on page 1. Most likely cause?
Question 2 of 3
Main window in SmartForm is used for:
Question 3 of 3
Which window type is normally used for long dynamic item tables that may continue to the next page?
Practise this in an interview
Answer in your own words and get instant feedback, the way an interviewer would judge it.
1A SmartForm item table does not continue to the second page. What is the likely issue?
2A delivery note placed a variable-length item list in a secondary window, so long deliveries were cut off. Why, and how do you fix it?
Try a related Code Lab
This published exercise covers the same SAP topic. Apply the ideas in a hands-on scenario, then return to review your answers.
Open: Item Table Not Continuing to Next Page →See it in code
Each example starts from a requirement, shows the design, then the code step by step with a plain-language explanation of every part.
Was this lesson helpful?
Keep exploring
Interview questions on this topic
Related SAP topics
Check before use: lesson examples are educational, not a guarantee of correctness for your SAP edition or release. Sample code has not been executed on your SAP system. Confirm API availability, syntax, authorizations and business impact in an approved development or test environment.