Start of Content Area

Example of a Print Program  Locate the document in its SAP Library structure

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.

ExampleFor 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




      FORM = 'S_EXAMPLE_1'

      DIALOG = 'X'


      others = 1

* (3) Print table heading




      TYPE = 'TOP'

      WINDOW = 'MAIN'

      FUNCTION = 'SET'


* (4) Print customer bookings

  LOOP AT bookings WHERE




        TYPE = 'BODY'

        WINDOW = 'MAIN'



* (5) 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.

NoteFor 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.