SAP ABAP Code Shrikant Naidu

Home
Site Map
What is SAP ?
SAP LSMW Explained with example
User Exits & Enhancements
Best Of SAP Links
BDC Code
SAP SmartForms Step by Step
SAP ABAP ALV Grid Explained with Example
Useful Tips
ABAP System Fields
SAP Script
SAP Script Graphics
SAPScript Print Program
ABAP ListViewer
Dialog Programming
SAP Tables
SAP ALE and IDOC
Recommended SAP ABAP Coding guidelines
SAP General ABAP
SAP Books For consultants
About Me
Contact Me
My Resume
SAPScript Print Program

Print Program and Function modules used in it .
  The  function modules like OPEN_FORM
CLOSE_FORM,COMMAND_FORM ,WRITE_FORM and Print Program Etc Explained with example.

 
The print program is used to print the actual form ,the functions the print program has to do include retrieving of data from database tables , selecting a FORM and printing of TEXT ELEMENTS in a desired sequence.
            The function modules used in aprint prgram are :
 
OPEN_FORM
START_FORM
WRITE_FORM
CONTROL_FORM
END_FORM
CLOSE_FROM
 
To start printing a form we must use OPEN_FORM and in the end we should use CLOSE_FORM to complete the spool request.
 
Function modules in detail.
 
OPEN_FORM function module
This function module should be called first before any printing can take place , here we specify the name of the form and the print language.
 
CALL FUNCTION 'OPEN_FORM'
EXPORTING
   DIALOG         = 'X'
   DEVICE         = 'PRINTER'
   FORM            = form name
   LANGUAGE   = SY-LANGU
*  OPTIONS      =
EXCEPTIONS
   CANCELLED  = 1
   DEVICE          = 2
   FORM            = 3
   OTHERS        = 11
.
 
IF SY-SUBRC NE 0.
MESSAGE ...
ENDIF.
 
In the above function module the parameter
FORM      = Name of form
DEVICE    = PRINTER (print using spool),TELEFAX (fax output)
                   SCREEN (output to screen)
OPTIONS = It is a structure of type ITCPO and it controls the various
                   attributes like number of copies , print preview etc.
 
START_FROM function module
 
This function module is called if we want to use different forms with similar characterstics in a single spool request,it must be closed by END_FORM function module.
 
 
CALL FUNCTION 'START_FORM'
EXPORTING
  FORM            =
  LANGUAGE    =
  STARTPAGE  =
EXCEPTIONS
  FORM            = 1
  OTHERS        = 7
.
 
IF SY-SUBRC NE 0.
MESSAGE ...
ENDIF.
 
WRITE_FORM Function module
 
This function module is used to write text in a window in the form using
text elements (/:E element). We can specify whether the text is to be appended , replaced or added and in which portion of the window it will be printed i.e TOP, BOTTOM ,BODY. In this function module actual printing takes place.
 
CALL FUNCTION 'WRITE_FORM'
EXPORTING
   ELEMENT    =
   FUNCTION  =
   TYPE          =
   WINDOW    =
EXCEPTIONS
   ELEMENT   =  1
    OTHERS    =  9
.
 
IF SY-SUBRC NE 0.
MESSAGE ...
ENDIF.
 
Here in this function module the ELEMENT specifies which textelement is
printed . WINDOW specifies which window of the form to be print in.
TYPE specifies the output area of the window TOP,BOTTOM,BODY.
FUNCTION specifies whether the text is to be appended , replaced or added.
 
CLOSE_FORM function module
 
This function module should be called in the end and it has no exporting
parameter.
 
CALL FUNCTION 'CLOSE_FROM'
IMPORTING
*   RESULT     =
EXCEPTIONS
    UNOPENED = 1
    OTHERS     =  5
 
.
 
IF SY-SUBRC NE 0.
MESSAGE ...
ENDIF.
   Here the result parameteer returns the status information and print/fax parameters after the form has been printed.
 
 
CONTROL_FORM function module
 
 This function module is used to insert SAPScript control commands like NEW-PAGE etc from whithin the ABAP program.
 
CALL FUNCTION 'CONTROL_FORM'
EXPORTING
  COMMAND    =
EXCEPTIONS
  UNOPENED   = 1
  OTHERS        = 3
.
 
IF SY-SUBRC NE 0.
MESSAGE ...
ENDIF.
 
 
NOTE: The print program and the form are stored in the table TNAPR

Enter supporting content here

Shrikant Naidu SAP ABAP Developer (INDIA)