Address printing in SAP Script

...Previous

Step5:  Save the form and activate.

The print preview for the layout will be as shown below.

Step6:  Go to transaction SE38 and write the print program for the form.
Here is the code for that.

REPORT ZDEMO.
TABLES:
  adrc.

SELECT-OPTIONS:
  s_addrno FOR adrc-addrnumber.

TYPES:
  BEGIN OF type_s_adrc,
    addrnumber TYPE adrc-addrnumber,
  END OF type_s_adrc.
DATA:
  fs_adrc TYPE type_s_adrc.

DATA:
    t_adrc LIKE
  STANDARD TABLE
        OF fs_adrc.

SELECT  addrnumber
        INTO TABLE t_adrc
        FROM adrc
        WHERE addrnumber IN s_addrno.

PERFORM open_form.
LOOP AT t_adrc INTO fs_adrc.
  PERFORM write_form." USING 'ADDRESS' 'APPEND' 'MAIN'.
ENDLOOP.                               "LOOP AT T_ADRC
PERFORM close_form.
*&---------------------------------------------------------------------*
*&      Form  OPEN_FORM
*&---------------------------------------------------------------------*

FORM open_form .
  CALL FUNCTION 'OPEN_FORM'
   EXPORTING
*   APPLICATION                       = 'TX'
*   ARCHIVE_INDEX                     =
*   ARCHIVE_PARAMS                    =
*   DEVICE                            = 'PRINTER'
*   DIALOG                            = 'X'
     form                              = 'Y_ADDRESS'
*   LANGUAGE                          = SY-LANGU
*   OPTIONS                           =
*   MAIL_SENDER                       =
*   MAIL_RECIPIENT                    =
*   MAIL_APPL_OBJECT                  =
*   RAW_DATA_INTERFACE                = '*'
*   SPONUMIV                          =
* 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
*   SPOOL_ERROR                       = 10
*   CODEPAGE                          = 11
*   OTHERS                            = 12
            .
  IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.                               " If sy-subrc <> 0

ENDFORM.                               "FORM OPEN_FORM
*&---------------------------------------------------------------------*
*&      Form  WRITE_FORM
*&---------------------------------------------------------------------*

FORM write_form .
  CALL FUNCTION 'WRITE_FORM'
   EXPORTING
     element                        = 'ADDRESS'
*   FUNCTION                       = 'SET'
*   TYPE                           = 'BODY'
     window                         = 'MAIN'
* IMPORTING
*   PENDING_LINES                  =
   EXCEPTIONS
     element                        = 1
     function                       = 2
     type                           = 3
     unopened                       = 4
     unstarted                      = 5
     window                         = 6
     bad_pageformat_for_print       = 7
     spool_error                    = 8
     codepage                       = 9
     OTHERS                         = 10
            .
  IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.                               " If sy-subrc <> 0

ENDFORM.                               "FORM WRITE_FORM

*&---------------------------------------------------------------------*
*&      Form CLOSE_FORM
*&---------------------------------------------------------------------*

FORM close_form .
  CALL FUNCTION 'CLOSE_FORM'
* IMPORTING
*   RESULT                         =
*   RDI_RESULT                     =
* TABLES
*   OTFDATA                        =
* EXCEPTIONS
*   UNOPENED                       = 1
*   BAD_PAGEFORMAT_FOR_PRINT       = 2
*   SEND_ERROR                     = 3
*   SPOOL_ERROR                    = 4
*   CODEPAGE                       = 5
*   OTHERS                         = 6
            .
  IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.                               " If sy-subrc <> 0

ENDFORM.                               " FORM CLOSE_FORM

Click here to continue...

Please send us your feedback/suggestions at webmaster@SAPTechnical.COM 

HomeContribute About Us Privacy Terms Of Use • Disclaimer • SafeCompanies: Advertise on SAPTechnical.COM | Post JobContact Us  

Graphic Design by Round the Bend Wizards

footer image footer image