Skip to Content
avatar image
Former Member

sample print program for script.

Hi

I want to develop simple sapscript for displaying data from single internal table.

so for that i have to wirte print program, if anyone have sample print program then plz send me.

thanks.

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

3 Answers

  • avatar image
    Former Member
    Nov 29, 2006 at 05:01 AM
    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Nov 29, 2006 at 05:02 AM

    Hi,

    This code will print the material numbers which is available in the internal table ITAB..

    DATA: BEGIN OF ITAB OCCURS 0,

    MATNR TYPE MATNR,

    END OF ITAB.

    SELECT MATNR UP TO 50 ROWS

    INTO TABLE ITAB

    FROM MARA.

    CALL FUNCTION 'OPEN_FORM'

    EXPORTING

    FORM = 'Z_TEST'

    LANGUAGE = SY-LANGU

    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

    SPOOL_ERROR = 10

    OTHERS = 11

    .

    IF sy-subrc <> 0.

    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

    WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

    ENDIF.

    LOOP AT ITAB.

    CALL FUNCTION 'WRITE_FORM'

    EXPORTING

    ELEMENT = 'MATNR'

    .

    ENDLOOP.

    CALL FUNCTION 'CLOSE_FORM'

    .

    Thanks,

    Naren

    Add comment
    10|10000 characters needed characters exceeded

  • Nov 29, 2006 at 05:14 AM

    Hi,

    Check this.

    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.

    --Ragu

    Add comment
    10|10000 characters needed characters exceeded