The example below shows a typical print program. This simple print program creates an invoice that contains company-related information, date, page numbering, customer address, and all flight bookings of a customer.
For the detailed sample program RSTXEXP1, refer to development class SAPBC460 (corresponding form S_EXAMPLE_1).
Print program: overview
* (1) Get customer data
TABLES: scustom, sbook, spfli.
DATA: bookings like sbook...
select * from...
* (2) Open form
CALL FUNCTION 'OPEN_FORM'
EXPORTING
DEVICE = 'PRINTER'
FORM = 'S_EXAMPLE_1'
DIALOG = 'X'
EXCEPTIONS
others = 1
* (3) Print table heading
CALL FUNCTION 'WRITE_FORM'
EXPORTING
ELEMENT = 'HEADING'
TYPE = 'TOP'
WINDOW = 'MAIN'
FUNCTION = 'SET'
...
* (4) Print customer bookings
LOOP AT bookings WHERE
CALL FUNCTION 'WRITE_FORM'
EXPORTING
ELEMENT = 'BOOKING'
TYPE = 'BODY'
WINDOW = 'MAIN'
...
ENDLOOP
* (5) Close form
CALL FUNCTION 'CLOSE_FORM'
...
In this example, the first section reads the required data from the database and fills it into internal tables (for example, BOOKINGS). In section (2), the function module OPEN_FORM is called to initialize the print output of the form S_EXAMPLE_1. Then, WRITE_FORM uses the
text element HEADING to output general text and the column heading of the invoice in the MAIN window (section (3)). In section (4), the text element BOOKING in the MAIN window is used to output the bookings of a customer that are read in a loop from the internal table BOOKINGS. The address of the customer as well as company-related information is output in other form windows directly, using default text elements. CLOSE_FORM finally ends the printing of the form.For each printout of a form, you must use the pair of function modules OPEN_FORM and CLOSE_FORM. You can also use a print program to print several forms, which you can either maintain in separate spool requests or combine into one. In the latter case, you must use the function modules START_FORM and END_FORM.
For more information, see
OPEN_FORM and CLOSE_FORM as well as START_FORM and END_FORM.