Page tree
Skip to end of metadata
Go to start of metadata

This scenario shows address printing in scripts.

 Step1: Go to  transaction SE71 which is FORM PAINTER. Give a name and create.

 Step2: Go to pages tab, by default first page is there. In the standard attributes give the page as first, give meaning to that and next page also as first.



 

Step3: Go to windows tab and create windows. To create a new window edit → create element →  window. Give the window name and meaning.  

 

Step4: Go to page windows tab and double click on the main window and select text elements(F9)

write the code as

/E address
/: BOX WIDTH '5' CM HEIGHT '5' CM FRAME 10 TW
/: ENDPROTECT
/: ADDRESS
/: ADDRESSNUMBER &FS_ADRC-ADDRNUMBER&
/: ENDADDRESS
/: NEW-WINDOW
/: PROTECT

And fill the other windows also with suitable data.

Step 5:  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
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
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
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
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
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
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 




************************************************** 

The output will be in this way.

Select the range of address in the selection screen

 

Then execute it ,output as shown below.

So in each window one addresses will appear.

This page is part of:

SAPscript Wiki

Tiny link (useful for e-mail):

https://wiki.scn.sap.com/wiki/x/PgamB

  • No labels