调用SAP SCRIPT的方法技巧

调用SAP SCRIPT的方法技巧

*-----------------------------------------------------------------------
* Program ID  :ZTEST904
* Program Name :ZTEST904
*-----------------------------------------------------------------------
* CREATED DATE :2004/09/04
* CREATED BY  :LG
* DESCRIPTION  :这个程序是学习如何通过程序来调用
*        已经做好的SCRIPT画面来生成报表的。
*-----------------------------------------------------------------------
* MODIFICATION :
* DATE MODIFIED    MODIFIED BY   TRANSPORT REQUEST  DESCRIPTION
* 2004/09/18     LG       VERSION:01/01      学习
*-----------------------------------------------------------------------
REPORT ZTEST904 .

*定义需要使用的表
***********************************************
TABLES: MSEG,
    MARA,
    MKPF.

*定义一个内部表(带表头)
***********************************************
DATA:  BEGIN OF ITAB OCCURS 0,
      A LIKE MSEG-MBLNR,
      B LIKE MSEG-ZEILE,
    END  OF ITAB.


* 插入一些使用的数据。
***********************************************
DO 30 TIMES.
 ITAB-A = '测试数据'.
 ITAB-B = SY-INDEX.
 APPEND ITAB.
ENDDO.

* 显示画面数据,显示上面的打印按钮。用户点击打印
* 然后调用打印的SCRIPT。显示答应的数据。
***********************************************

* INITIALIZATION
***********************************************
INITIALIZATION.

* AT SELECTION-SCREEN.
***********************************************
AT SELECTION-SCREEN.

* START-OF-SELECTION
***********************************************
START-OF-SELECTION.
SET PF-STATUS 'ZTEST_904'.
PERFORM PRINT_ITAB TABLES ITAB.

* AT USER-COMMAND.
***********************************************
AT USER-COMMAND.
CASE SY-UCOMM.
  WHEN 'USER_PRINT'.
   WRITE:/ 'BUTTON CLIKCKED'.
   PERFORM OPEN_FORM.
    PERFORM START_FORM.
     DO 50 TIMES.
      PERFORM WRITE_FORM USING '' 'MAIN' 'SET'.
     ENDDO.
    PERFORM END_FORM.
   PERFORM CLOSE_FORM.
ENDCASE.

* TOP-OF-PAGE.
***********************************************
TOP-OF-PAGE.

* END-OF-PAGE.
***********************************************
END-OF-PAGE.


*&----------------------------------------------------------------------
*& FORM : PRINT_ITAB
*&----------------------------------------------------------------------
* <处理概要>
*-----------------------------------------------------------------------
* <种别(入出力) <参数名> <类型> <调用类型参照,值>>
*-----------------------------------------------------------------------
* FORM PRINT_ITAB TABLES JTAB LIKE ITAB[].
FORM PRINT_ITAB TABLES JTAB STRUCTURE ITAB.
 LOOP AT JTAB.
  WRITE:/ JTAB-A , 10 JTAB-B.
 ENDLOOP.
ENDFORM.

FORM PRINT_PAGE.

ENDFORM.

FORM OPEN_FORM.
 CALL FUNCTION 'OPEN_FORM'
  EXPORTING
*   APPLICATION            = 'TX'
*   ARCHIVE_INDEX           =
*   ARCHIVE_PARAMS          =
   DEVICE              = 'PRINTER'
*   DIALOG              = 'X'
   FORM               = 'ZTEST904'
   LANGUAGE             = SY-LANGU
*   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
   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.
ENDFORM.

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
  OTHERS             = 5
      .
 IF SY-SUBRC <> 0.
 MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
     WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
 ENDIF.

ENDFORM.

FORM START_FORM.
 CALL FUNCTION 'START_FORM'
  EXPORTING
*  ARCHIVE_INDEX     =
   FORM          = 'ZTEST904'
*  LANGUAGE        = ' '
   STARTPAGE       = 'FRIST'
*  PROGRAM        = ''
*  MAIL_APPL_OBJECT    =
* IMPORTING
*  LANGUAGE        =
 EXCEPTIONS
  FORM          = 1
  FORMAT         = 2
  UNENDED        = 3
  UNOPENED        = 4
  UNUSED         = 5
  SPOOL_ERROR      = 6
  OTHERS         = 7
      .
 IF SY-SUBRC <> 0.
 MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
     WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
 ENDIF.

ENDFORM.

FORM END_FORM.
 CALL FUNCTION 'END_FORM'
* IMPORTING
*  RESULT             =
 EXCEPTIONS
  UNOPENED            = 1
  BAD_PAGEFORMAT_FOR_PRINT    = 2
  SPOOL_ERROR          = 3
  OTHERS             = 4
      .
 IF SY-SUBRC <> 0.
 MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
     WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
 ENDIF.
ENDFORM.

FORM WRITE_FORM USING ELE WIN FUNC.
 CALL FUNCTION 'WRITE_FORM'
 EXPORTING
   ELEMENT            = ELE
   FUNCTION            = FUNC
*  TYPE              = 'BODY'
   WINDOW             = WIN
* IMPORTING
*  PENDING_LINES         =
  EXCEPTIONS
  ELEMENT            = 1
  FUNCTION            = 2
  TYPE              = 3
  UNOPENED            = 4
  UNSTARTED           = 5
  WINDOW             = 6
  BAD_PAGEFORMAT_FOR_PRINT    = 7
  SPOOL_ERROR          = 8
  OTHERS             = 9
      .
 IF SY-SUBRC <> 0.
  MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
      WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
 ENDIF.

ENDFORM.