SAP里常常要画各种smartform,并且用户还希望保存至本地PDF文件,下面就详细说明smartform转成PDF的四种方法,如果还有其他方法欢迎留言补充。
一、代码开发
1)先调用smartform函数获取OTF格式数据
2)后调用函数CONVERT_OTF转换成PDF格式数据
3)再调用GUI_DOWNLOAD函数下载
示例代码如下(本示例中需下载四个smartform对应的四个PDF文件)
METHOD DOWNLOAD_PDF.
DATA: LT_FORMNAME TYPE STANDARD TABLE OF /PICM/ADOBEFORM_STR,
LT_OTF TYPE STANDARD TABLE OF ITCOO,
LT_LINES TYPE STANDARD TABLE OF TLINE,
LT_DATA TYPE STANDARD TABLE OF ZSSD042,
LS_DATA TYPE ZSSD042,
LS_CONTROL_PARAMETERS TYPE SSFCTRLOP,
LS_OUTPUT_OPTIONS TYPE SSFCOMPOP,
LS_JOB_OUTPUT_INFO TYPE SSFCRESCL,
LV_FILENAME TYPE STRING,
LV_PATH TYPE STRING.
DATA(LV_TIME) = SY-DATUM && SY-UZEIT.
DATA(LT_VBELN) = T_ALV[].
DELETE LT_VBELN WHERE CHOOSE IS INITIAL.
SORT LT_VBELN BY VBELN.
DELETE ADJACENT DUPLICATES FROM LT_VBELN COMPARING VBELN.
IF LT_VBELN[] IS INITIAL.
MESSAGE TEXT-E03 TYPE 'E'.
ENDIF.
CALL METHOD CL_GUI_FRONTEND_SERVICES=>DIRECTORY_BROWSE
CHANGING
SELECTED_FOLDER = LV_PATH
EXCEPTIONS
CNTL_ERROR = 1
ERROR_NO_GUI = 2
NOT_SUPPORTED_BY_GUI = 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.
IF LV_PATH IS INITIAL.
RETURN.
ENDIF.
" LS_OUTPUT_OPTIONS-TDDEST = 'LP01'.
LS_OUTPUT_OPTIONS-TDIMMED = 'X'.
LS_OUTPUT_OPTIONS-TDDELETE = 'X'.
LS_OUTPUT_OPTIONS-TDNOPREV = 'X'.
LS_CONTROL_PARAMETERS-NO_DIALOG = 'X'.
LS_CONTROL_PARAMETERS-GETOTF = 'X'.
LT_FORMNAME = VALUE #(
( FORMNAME = 'ZSD001_FORM' FUGRNAME = 'despatchlist_&1_&2.pdf' ) "DespatchList
( FORMNAME = 'ZSD002_FORM' FUGRNAME = 'EDIDoc_&1_&2.pdf' ) "EDIDoc
( FORMNAME = 'ZSD003_FORM' FUGRNAME = 'shippingorder_&1_&2.pdf' ) "ShippingOrder
( FORMNAME = 'ZSD004_FORM' FUGRNAME = 'SO_DELIVERY_NOTE_&1_&2.pdf' ) "SO_DELIVERY_NOTE
).
* 获取SMARTFORM对应函数名
LOOP AT LT_FORMNAME INTO DATA(LS_FORMNAME).
CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'
EXPORTING
FORMNAME = LS_FORMNAME-FORMNAME
IMPORTING
FM_NAME = LS_FORMNAME-FUNCNAME
EXCEPTIONS
NO_FORM = 1
NO_FUNCTION_MODULE = 2
OTHERS = 3.
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
MODIFY LT_FORMNAME FROM LS_FORMNAME.
ENDLOOP.
LOOP AT LT_VBELN INTO DATA(LS_VBELN).
CLEAR LT_DATA[].
LOOP AT T_ALV INTO DATA(LS_ALV) WHERE VBELN = LS_VBELN-VBELN.
MOVE-CORRESPONDING LS_ALV TO LS_DATA.
APPEND LS_DATA TO LT_DATA.
ENDLOOP.
LOOP AT LT_FORMNAME INTO LS_FORMNAME WHERE FUNCNAME IS NOT INITIAL.
CLEAR: LT_OTF[], LT_LINES[], LS_JOB_OUTPUT_INFO, LV_FILENAME.
* 编辑文件名
LV_FILENAME = LS_FORMNAME-FUGRNAME.
DATA(LV_VBELN) = |{ LS_VBELN-VBELN ALPHA = OUT }|.
REPLACE '&1' WITH LV_TIME INTO LV_FILENAME.
REPLACE '&2' WITH LV_VBELN INTO LV_FILENAME.
CONDENSE LV_FILENAME NO-GAPS.
CONCATENATE LV_PATH LV_FILENAME INTO LV_FILENAME SEPARATED BY '\'.
* 调用SMARTFORM
CALL FUNCTION LS_FORMNAME-FUNCNAME
EXPORTING
CONTROL_PARAMETERS = LS_CONTROL_PARAMETERS
OUTPUT_OPTIONS = LS_OUTPUT_OPTIONS
USER_SETTINGS = 'X'
IMPORTING
JOB_OUTPUT_INFO = LS_JOB_OUTPUT_INFO
TABLES
IT_DATA = LT_DATA
EXCEPTIONS
FORMATTING_ERROR = 1
INTERNAL_ERROR = 2
SEND_ERROR = 3
USER_CANCELED = 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.
* 转换PDF
LT_OTF[] = LS_JOB_OUTPUT_INFO-OTFDATA[].
CALL FUNCTION 'CONVERT_OTF'
EXPORTING
FORMAT = 'PDF'
TABLES
OTF = LT_OTF
LINES = LT_LINES
EXCEPTIONS
ERR_MAX_LINEWIDTH = 1
ERR_FORMAT = 2
ERR_CONV_NOT_POSSIBLE = 3
ERR_BAD_OTF = 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.
* 下载文件
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
FILENAME = LV_FILENAME
FILETYPE = 'BIN'
TABLES
DATA_TAB = LT_LINES
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.
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
ENDLOOP.
ENDLOOP.
ENDMETHOD.
二、?通过打印池假脱机请求转成PDF文件
1)打印smartform输出假脱机请求
2)SP01查看假脱机请求,选择菜单中 假脱机请求->转发->导出为PDF 进行下载,或者执行SAP标准程序RSTXPDFT4输入假脱机请求号进行下载
?执行程序RSTXPDFT4
三、在打印预览界面输入Tcode PDF!预览PDF,点击保存按钮进行下载
四、使用PDF虚拟打印机,本电脑使用的是微软自带的Microsoft?Print?to PDF虚拟打印机
SPAD配置输出设备
1)如果?主机假脱机访问方法?选择了 G:使用控制技术的前台打印,则先设置smartform打印选项后选择打印机
?打印smartform
?选择打印机
?2)如果?主机假脱机访问方法?选择了 F:计算机前台打印,则设置smartform打印选项时可同时选择打印机
?设置smartform打印选项并选择打印机
|