Processing Loops and Tables

Overview

When you use a loop or table node, you usually specify an internal table. SAP Smart Forms reads the table line by line to retrieve the data. Since the number of entries in such a table can be too large to fit onto one page, use a main window for table output.

When you print a table, the size of a table is determined dynamically. The output control must consider several heights to calculate a page correctly:

  • The height of the footer. The height of the header area is not important, since it is always printed at the beginning of the main window.
  • The height of a table line, meaning the output from all nodes using a certain line type. The height of a table line depends on the highest cell in the line; the height of a cell depends on its content.
  • The height of a line. Within a table cell, you can print output that covers several lines. If you want all lines of a table line to be printed together, you must set the No Break indicator for this line type.

When processing a table, SAP Smart Forms does not calculate the space required for the entire table in advance, but determines for each line whether it still fits onto the current page.

Footer

With table output, besides using the main area for output of table lines, you will frequently print a header and footer. If the footer is printed at the end of each page, the output control must consider the footer height when determining the position of the automatic page break. Therefore, you must specify a height for the footer output. If you don't, then the output control cannot reserve any space at the end of the main window and thus not print the inferior nodes of the footer before the page break.

Automatic Page Break vs No Break

The output control triggers an automatic page break to print contents on several pages. As a form developer, you may not want the system to automatically break a page, for example, if you want to print all lines of a table on one page. For these table lines, you must specify No Break with the line type to prevent the system from breaking up the table at the end of the main window for space reasons. If there is not enough space left on the current page, the entire table will be printed on the next page.

For all other output, you can use the output option Page Protection instead of No Break .

Processing

Requirements for Automatic Page Breaks

During output SAP Smart Forms must determine dynamically whether the output still fits onto the current page. Otherwise it must trigger a page break. When processing tables, this is of special importance, since the table lines are not printed immediately after the corresponding node is processed. Whenever a new line starts, the output control must determine the height of it. To do so, it stores the entire line in a buffer. The following examples illustrate why:

The cells within a table line contain data that may be printed on one as well as on several lines. If the line type is protected against page break, all cells of the table line must be printed on the page. This depends on the height of the highest cell within the table line.

Even if the table line type is not break-protected, a subsequent cell might contain a graphic which is higher than the first cells.

These examples illustrate that the output control can determine the height of each line only by analyzing the entire line in the buffer.

Process Flow

For form development not every detail of the output control is important. We want to concentrate on two questions: When is the footer processed? How is the automatic page break determined?

  1. If you activated output at the beginning of the table or at a page break, the header is processed and printed.
  2. With the old table node, output of the first inferior node, for which the output option New Line is marked, determines the end of the current line as well as the beginning of a new line. With the new table node you specify the end of the line by explicitly creating table lines. In both cases, SAP Smart Forms calculates at this event wheter to execute an automatic line feed:
    1. If the buffer already contains a table line, this is the line of the previous loop pass. With the beginning of the new line, the output control can now check whether the buffered line still fits onto the current page, thereby considering the yet unprinted footer (provided it must be printed before the page break):
      • If there is enough space left on the page, the buffered line is printed.
      • If there is not enough space left, the output control processes the footer and prints it. Then the output control processes all subsequent windows of the page and triggers a page break. It prints the buffered line after the page break.
    1. The output control buffers the table line of the current loop pass to determine its height. However, this line is printed only during the next loop pass.
  1. After processing the last inferior node, processing resumes with the first inferior node of the table (in the main area, with new table nodes).

Program Lines Nodes

Nodes of type program lines must be considered separately:

  • Program lines nodes cannot be buffered. The output control executes them directly while they are processed (unlike table lines, where the buffered line is printed during the next loop pass). This affects subtotals that are printed at the end of a page above the footer.
  • Program lines nodes have no output. With the old table node this has the effect that they do not represent the start of a new line for the output control. This means that all program lines nodes that appear before the next node that contains output are processed even though the line of the last loop pass has not yet been completed. With the new table node this is different because you specify the line end by explicitly creating table lines.

The program lines nodes within a table or loop are processed in the desired sequence and only once per loop pass. But note that due to the mechanism described above they are executed out of sync with the output (with the new table node as well).

The section Summing Up Different Currencies describes how you can use program lines nodes to print correct totals.

The procedure described there is required only if you want to sum up values with different currencies or measurement units. Otherwise you can use the Calculations tab of the new table node and avoid pondering about how to process the loop.