Structure of a print program


  1. General Structure
  2. Examples of function calls
    1. OPEN FORM
    2. START_FORM
    3. WRITE_FORM
    4. END_FORM
    5. CLOSE_FORM


General Structure


The print program is used to print forms. The program retieves the necesary data from datbase tables, defines the order of in which text elements are printed, chooses a form for printing and selects an output device and print options.  

* Open form printing - Must be called before working with any of the other form function modules.
Must be ended with function module CLOSE FORM
call function 'OPEN_FORM'.....


*To begin several indentical forms containing different data within a single spool request, begin each form using START_FORM, and end it using END_FORM
call funtion 'START_FORM'.....


* Write text elements to a window of the form
call function 'WRITE_FORM'.....

* Ends form
call funtion 'END_FORM'.....


* Closes form printing
call function 'CLOSE_FORM'....


Examples of function calls


OPEN FORM


* Structure for the OPTIONS parameter
DATA BEGIN OF OPTIONS.
  INCLUDE STRUCTURE ITCPO.
DATA END   OF OPTIONS.


OPTIONS-TDDEST = '*'.

OPTIONS-TDIMMED = '*'.
OPTIONS-TDDELETE = '*'.
OPTIONS-TDNEWID = 'X'.

CALL FUNCTION 'OPEN_FORM'
    EXPORTING
*         APPLICATION                 = 'TX'
*         ARCHIVE_INDEX            =
*         ARCHIVE_PARAMS       =
          DEVICE                            = 'PRINTER'
          DIALOG                            = 'X'
*         FORM                               = ' '
*         LANGUAGE                     = SY-LANGU
          OPTIONS                          = OPTIONS

*         MAIL_SENDER                =
*         MAIL_RECIPIENT              =
*         MAIL_APPL_OBJECT            =
*         RAW_DATA_INTERFACE          = '*'
*    IMPORTING
*         LANGUAGE                    =
*         NEW_ARCHIVE_PARAMS          =
*         RESULT                      =
    EXCEPTIONS
         CANCELED                    = 1
         DEVICE                      = 2
         FORM                        = 3
         OPTIONS                     = 4

         UNCLOSED                    = 5
         MAIL_OPTIONS                = 6
         ARCHIVE_ERROR               = 7
         INVALID_FAX_NUMBER          = 8
         MORE_PARAMS_NEEDED_IN_BATCH = 9
         OTHERS                      = 10
          .
IF sy-subrc <> 0.
 ...............................
ENDIF.



START_FORM


CALL FUNCTION 'START_FORM'
*    EXPORTING
*         ARCHIVE_INDEX    =
          FORM                       = 'MY_FORM'

*          LANGUAGE             = ' '
*         STARTPAGE           = ' '
*         PROGRAM              = ' '
*         MAIL_APPL_OBJECT =
*    IMPORTING
*         LANGUAGE         =
*    EXCEPTIONS
         FORM             = 1
         FORMAT           = 2
         UNENDED          = 3
         UNOPENED         = 4
         UNUSED           = 5
         OTHERS           = 6


WRITE_FORM


CALL FUNCTION 'WRITE_FORM'
    EXPORTING
         ELEMENT                   =
         FUNCTION                 =
         TYPE                          =
         WINDOW                    =
    IMPORTING
         PENDING_LINES      =
    EXCEPTIONS
         ELEMENT                  = 1
         FUNCTION                 = 2

         TYPE                           = 3
         UNOPENED                 = 4
         UNSTARTED                = 5
         WINDOW                   = 6
         BAD_PAGEFORMAT_FOR_PRINT = 7
         OTHERS                   = 8
          .

Parameters


Note: To write lines to the main window, you can also use the WRITE_FORM_LINES function module.


Examples

Form layout of MAIN window

/E INTRODUCTION
*   Dear Customer
    ...........................

/E ITEM_HEADER
IH Carrier, Departure

/E ITEM_LINE
IL &SBOOK-CARRID&, &SPFLI-DEPTIME&

/E  CLOSING_REMARK


Writing introduction

CALL FUNCTION 'WRITE_FORM'
     EXPORTING
          ELEMENT                  = 'INTRODUCTION'
          FUNCTION                 = 'SET'
          TYPE                         = 'BODY'
          WINDOW                   = 'MAIN'
    EXCEPTIONS
         OTHERS                   = 8
          .

Writing column headers

CALL FUNCTION 'WRITE_FORM'

     EXPORTING
          ELEMENT                  = 'ITEM_HEADER'
          FUNCTION                = 'SET'
          TYPE                         = 'BODY'
          WINDOW                   = 'MAIN'
    EXCEPTIONS
         OTHERS                   = 8
          .

Set column headings into TOP area of main window for subsequent pages

CALL FUNCTION 'WRITE_FORM'
     EXPORTING
          ELEMENT                  = 'ITEM_HEADER'
          FUNCTION                 = 'SET'

          TYPE                         = 'TOP'
          WINDOW                   = 'MAIN'
    EXCEPTIONS
         OTHERS                   = 8

Write item lines

LOOP AT .....
   CALL FUNCTION 'WRITE_FORM'
        EXPORTING
             ELEMENT                  = 'ITEM_LINE'
             FUNCTION                = 'SET'
             TYPE                         = 'BODY'
             WINDOW                   = 'MAIN'
       EXCEPTIONS
            OTHERS                   = 8.

ENDLOOP.


Delete column headings from TOP area of main window

CALL FUNCTION 'WRITE_FORM'
     EXPORTING
          ELEMENT                  = 'ITEM_HEADER'
          FUNCTION                = 'DELETE'
          TYPE                         = 'TOP'
          WINDOW                   = 'MAIN'
    EXCEPTIONS
         OTHERS                   = 8



Print closing remark

CALL FUNCTION 'WRITE_FORM'
     EXPORTING
          ELEMENT                  = 'CLOSING_REMARK'

          FUNCTION                 = 'SET'
          TYPE                          = 'BODY'
          WINDOW                    = 'MAIN'
    EXCEPTIONS
         OTHERS                   = 8



END_FORM


CALL FUNCTION 'END_FORM'

*    IMPORTING
*        RESULT                   =
    EXCEPTIONS
*        UNOPENED                 = 1
*        BAD_PAGEFORMAT_FOR_PRINT = 2
         OTHERS                   = 3



CLOSE_FORM


* Structure for Print options (return values) - Pages selected for printing, Number of copies etc.
DATA BEGIN OF RESULT.
  INCLUDE STRUCTURE ITCPP.
DATA END   OF RESULT.

CALL FUNCTION 'CLOSE_FORM'
    IMPORTING
          RESULT                   = RESULT

*         RDI_RESULT               =
*    TABLES
*         OTFDATA                  =
*    EXCEPTIONS
*         UNOPENED                 = 1
*         BAD_PAGEFORMAT_FOR_PRINT = 2
*         SEND_ERROR               = 3
*         OTHERS                   = 4
          .
Converted from CHM to HTML with chm2web Standard 2.7 (unicode)