REPORT Z_DOWN_FROM_SCRIPTFORM.
DATA:DATAB TYPE TABLE OF ITCOO WITH HEADER LINE.
DATA: PDFTAB TYPE TABLE OF TLINE WITH HEADER LINE.
DATA OPT LIKE ITCPO.
OPT-TDDEST = 'LP01'. "打印设备
OPT-TDIMMED = 'X'. "立刻打印
OPT-TDDELETE = 'X'. "打印后删除
OPT-TDPREVIEW = 'X'. "打印预览
OPT-TDGETOTF = 'X'. "如果要生成PDF,这个参数一定要设
DATA: BINFILESIZE TYPE I,
FILE_NAME TYPE STRING,
FILE_PATH TYPE STRING,
FULL_PATH TYPE STRING.
EXPORTING
DEVICE = 'PRINTER'
FORM = 'ZPMSBTZ'
DIALOG = ' '
OPTIONS = OPT
EXCEPTIONS
CANCELED = 1
DEVICE = 2
FORM = 3
OPTIONS = 4
UNCLOSED = 5
OTHERS = 6.
IF SY-SUBRC <> 0.
WRITE:/'ERROR IN OPEN_FORM'.
EXIT.
ENDIF.
CALL FUNCTION 'START_FORM'
EXPORTING
FORM = 'ZPMSBTZ'
STARTPAGE = 'PAG1'
EXCEPTIONS
FORM = 1
FORMAT = 2
UNENDED = 3
UNOPENED = 4
UNUSED = 5
SPOOL_ERROR = 6
CODEPAGE = 7
OTHERS = 8.
IF SY-SUBRC <> 0.
WRITE:/ 'ERROR IN START_FORM OF PAGE:'.
EXIT.
ENDIF.
CALL FUNCTION 'WRITE_FORM'
EXPORTING
ELEMENT = 'HEAD'
FUNCTION = 'SET'
TYPE = 'BODY'
WINDOW = 'MAIN'
EXCEPTIONS
OTHERS = 1.
IF SY-SUBRC <> 0.
WRITE :/ 'ERROR IN WRITE_FORM OF WINDOW:'.
EXIT.
ENDIF.
CALL FUNCTION 'END_FORM'.
IF SY-SUBRC <> 0.
WRITE :/ 'ERROR IN END_FORM'.
EXIT.
ENDIF.
CALL FUNCTION 'CLOSE_FORM'
TABLES
OTFDATA = DATAB[]
EXCEPTIONS
UNOPENED = 1
BAD_PAGEFORMAT_FOR_PRINT = 2
SEND_ERROR = 3
OTHERS = 4.
PERFORM DOWN_FILE_FORMAT_PDF.
*将打印的FORM内容下载为PDF格式文件
FORM DOWN_FILE_FORMAT_PDF.
CALL FUNCTION 'CONVERT_OTF'
EXPORTING
FORMAT = 'PDF'
IMPORTING
BIN_FILESIZE = BINFILESIZE
TABLES
OTF = DATAB[]
LINES = PDFTAB[].
CALL METHOD CL_GUI_FRONTEND_SERVICES=>FILE_SAVE_DIALOG
CHANGING
FILENAME = FILE_NAME
PATH = FILE_PATH
FULLPATH = FULL_PATH.
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
BIN_FILESIZE = BINFILESIZE
FILENAME = FULL_PATH
FILETYPE = 'BIN'
TABLES
DATA_TAB = PDFTAB[]
EXCEPTIONS
FILE_WRITE_ERROR = 1
NO_BATCH = 2
GUI_REFUSE_FILETRANSFER = 3
INVALID_TYPE = 4
NO_AUTHORITY = 5
UNKNOWN_ERROR = 6
HEADER_NOT_ALLOWED = 7
SEPARATOR_NOT_ALLOWED = 8
FILESIZE_NOT_ALLOWED = 9
HEADER_TOO_LONG = 10
DP_ERROR_CREATE = 11
DP_ERROR_SEND = 12
DP_ERROR_WRITE = 13
UNKNOWN_DP_ERROR = 14
ACCESS_DENIED = 15
DP_OUT_OF_MEMORY = 16
DISK_FULL = 17
DP_TIMEOUT = 18
FILE_NOT_FOUND = 19
DATAPROVIDER_EXCEPTION = 20
CONTROL_FLUSH_ERROR = 21
OTHERS = 22.
ENDFORM. "DOWN_FILE_FORMAT_PDF
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/73630/viewspace-994754/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/73630/viewspace-994754/