Z_06MM_FWYS_PRINT
FUNCTION z_06mm_fwys_print.
*"----------------------------------------------------------------------
*"*"本地接口:
*"----------------------------------------------------------------------
* 数据申明
data:ET_ALV TYPE Z29MMTENTRYSHEET.
* data:ET_LINES like TLINE.
DATA:lt_number TYPE TABLE OF z06pms_not_number_i WITH HEADER LINE,
ls_number TYPE z06pms_not_number_i.
DATA: gt_alv TYPE TABLE OF z29mmsentrysheet.
DATA:gt_hs TYPE STANDARD TABLE OF tline .
DATA:gs_hs TYPE tline .
RANGES:r_qmnum FOR qmel-qmnum.
DATA:gs_alv TYPE z29mmsentrysheet.
DATA:return_pdf TYPE TABLE OF z06pms_bapiret2 WITH HEADER LINE.
DATA:lv_path TYPE z06pmepath,
lv_filename TYPE z06pmefilename,
lt_return TYPE TABLE OF z06pms_bapiret2 WITH HEADER LINE,
ls_return TYPE z06pms_bapiret2.
DATA:lv_msg TYPE string.
* data : gt_notif_otfdata_01 TYPE TABLE OF itcoo.
"----------------------------------------------------------------------
* 数据初始化
INCLUDE z06pm500_z01_notif_print_01.
CLEAR:object_tab[],gs_notif_ssfcrescl,gt_notif_otfdata[],gs_notif_otfdata.
CLEAR:lv_msg.
CLEAR:return_pdf[].
CLEAR:lv_path,lv_filename,lt_return[],ls_return.
CLEAR:return_notif_print[],gs_return_notif_print.
* gv_webusrid = i_webusrid.
*"----------------------------------------------------------------------
* 数据校验
*"----------------------------------------------------------------------
* 获取打印数据
*-------------------
IF IV_ALV[] IS NOT INITIAL.
PERFORM frm_print TABLES IV_ALV
IV_LINES
CHANGING ccc_ccc .
ELSE.
MESSAGE ID 'Z06500' TYPE 'E' NUMBER '093' INTO lv_msg.
ls_return-type = 'E'.
ls_return-message = lv_msg.
APPEND ls_return TO lt_return.CLEAR:ls_return.
ENDIF.
*"----------------------------------------------------------------------
* 处理打印返回参数
APPEND LINES OF return_notif_print TO lt_return.
LOOP AT lt_return TRANSPORTING NO FIELDS WHERE type CA 'EA'.
EXIT.
ENDLOOP.
*"----------------------------------------------------------------------
* SMARTFORMS生成PDF至FTP
IF sy-subrc <> 0.
IF gt_notif_otfdata_01[] IS NOT INITIAL.
CALL FUNCTION 'Z_06PM_NOTIF_SF_TO_FTP'
IMPORTING
e_path = lv_path
e_filename = lv_filename
TABLES
it_otfdata = gt_notif_otfdata_01
et_return = return_pdf.
APPEND LINES OF return_pdf TO lt_return.
ELSE.
MESSAGE ID 'Z06500' TYPE 'E' NUMBER '080' INTO lv_msg.
ls_return-type = 'E'.
ls_return-message = lv_msg.
APPEND ls_return TO lt_return.CLEAR:ls_return.
ENDIF.
ENDIF.
*"----------------------------------------------------------------------
e_path = lv_path.
e_filename = lv_filename.
et_return[] = lt_return[].
*"----------------------------------------------------------------------
ENDFUNCTION.
Z_06PM_NOTIF_SF_TO_FTP
FUNCTION z_06pm_notif_sf_to_ftp.
*"----------------------------------------------------------------------
*"*"Local interface:
*" EXPORTING
*" VALUE(E_PATH) TYPE Z06PMEPATH
*" VALUE(E_FILENAME) TYPE Z06PMEFILENAME
*" TABLES
*" IT_OTFDATA STRUCTURE ITCOO
*" ET_RETURN STRUCTURE Z06PMS_BAPIRET2
*"----------------------------------------------------------------------
* 数据申明
DATA:lt_otfdata TYPE TABLE OF itcoo WITH HEADER LINE.
DATA:file_bin TYPE xstring,
file_size(12) TYPE c.
DATA:lv_hdl TYPE i,
lv_command(255) TYPE c,
lv_blength TYPE i,
lv_num(100) TYPE i,
lv_ftp_path TYPE z06pmepath,
lv_path TYPE z06pmepath,
lv_filename TYPE char1024,
lv_comp_sizp TYPE i,
lv_guid TYPE sysuuid_c32.
DATA:lt_lines TYPE TABLE OF tline,
ls_lines TYPE tline.
TYPES:BEGIN OF ls_blob,
line(1022) TYPE x,
END OF ls_blob.
DATA:lt_bindata TYPE STANDARD TABLE OF ls_blob,
ls_bindata TYPE ls_blob.
DATA:BEGIN OF it_result OCCURS 0,
line(100) TYPE c,
END OF it_result.
DATA:ls_msgout TYPE LINE OF z10wfsket1,
ls_return TYPE z06pms_bapiret2,
lv_msg TYPE string,
lv_oref TYPE REF TO cx_uuid_error,
ls_ftp TYPE z06pmtftpcf.
*"----------------------------------------------------------------------
* 数据初始化
CLEAR:lt_otfdata[].
CLEAR:file_bin,file_size.
CLEAR:lv_hdl,lv_command,lv_blength,lv_num,lv_ftp_path,lv_filename,lv_comp_sizp,lv_guid.
CLEAR:lt_lines[],ls_lines.
CLEAR:lt_bindata[],ls_bindata.
CLEAR:it_result[].
CLEAR:ls_msgout,ls_return,lv_msg,lv_oref,ls_ftp.
lt_otfdata[] = it_otfdata[].
* 查询FTP配置表
SELECT SINGLE *
INTO ls_ftp
FROM z06pmtftpcf
WHERE intid EQ 'PWPFTP'.
lv_ftp_path = ls_ftp-folder_t."临时文件夹
* lv_ftp_path = '/upload'.
*"----------------------------------------------------------------------
* OTF预览和转换
CALL FUNCTION 'CONVERT_OTF'
EXPORTING
format = 'PDF'
IMPORTING
bin_filesize = file_size
bin_file = file_bin
TABLES
otf = lt_otfdata
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 'Z06500' TYPE 'E' NUMBER '087' INTO lv_msg.
ls_return-type = 'E'.
ls_return-message = lv_msg.
APPEND ls_return TO et_return.CLEAR:ls_return.
RETURN.
ENDIF.
*"----------------------------------------------------------------------
* 数据二进制转换
CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
EXPORTING
buffer = file_bin
IMPORTING
output_length = lv_comp_sizp
TABLES
binary_tab = lt_bindata.
##FM_SUBRC_OK
IF sy-subrc <> 0.
MESSAGE ID 'Z06500' TYPE 'E' NUMBER '088' INTO lv_msg.
ls_return-type = 'E'.
ls_return-message = lv_msg.
APPEND ls_return TO et_return.CLEAR:ls_return.
RETURN.
ELSE.
lv_blength = lv_comp_sizp.
ENDIF.
*"----------------------------------------------------------------------
* 连接FTP
CALL FUNCTION 'Z_06PM_FTP_CONNECT'
IMPORTING
e_hdl = lv_hdl
e_msg = ls_msgout.
IF ls_msgout-msgtyp CA 'EA'.
ls_return-type = ls_msgout-msgtyp.
ls_return-message = ls_msgout-msgtxt.
APPEND ls_return TO et_return.CLEAR:ls_return.
RETURN.
ENDIF.
*"----------------------------------------------------------------------
* 操作FTP
* 打开upload文件夹
CLEAR:lv_command.
CONCATENATE 'cd' lv_ftp_path INTO lv_command SEPARATED BY space.
CALL FUNCTION 'FTP_COMMAND'
EXPORTING
handle = lv_hdl
command = lv_command
TABLES
data = it_result
EXCEPTIONS
command_error = 1
tcpip_error = 2.
IF sy-subrc <> 0.
MESSAGE ID 'Z06500' TYPE 'E' NUMBER '089' INTO lv_msg."FTP操作失败-打开根目录失败
ls_return-type = 'E'.
ls_return-message = lv_msg.
APPEND ls_return TO et_return.CLEAR:ls_return.
RETURN.
ENDIF.
* 打开临时文件夹
CLEAR:lv_command.
CONCATENATE 'cd' lv_ftp_path INTO lv_command SEPARATED BY space.
CONCATENATE lv_command sy-datum INTO lv_command. "edit by pxmwyzh 20181014
* CONCATENATE lv_command '/' sy-datum INTO lv_command.
CALL FUNCTION 'FTP_COMMAND'
EXPORTING
handle = lv_hdl
command = lv_command
TABLES
data = it_result
EXCEPTIONS
command_error = 1
tcpip_error = 2.
IF sy-subrc = 1.
* 如临时文件夹不存在,创建临时文件夹
CLEAR:lv_command.
CONCATENATE 'mkdir' sy-datum INTO lv_command SEPARATED BY space.
CALL FUNCTION 'FTP_COMMAND'
EXPORTING
handle = lv_hdl
command = lv_command
TABLES
data = it_result
EXCEPTIONS
command_error = 1
tcpip_error = 2.
IF sy-subrc <> 0.
MESSAGE ID 'Z06500' TYPE 'E' NUMBER '100' INTO lv_msg."FTP操作失败-创建子目录失败
ls_return-type = 'E'.
ls_return-message = lv_msg.
APPEND ls_return TO et_return.CLEAR:ls_return.
RETURN.
ENDIF.
* 打开临时文件夹
CLEAR:lv_command.
CONCATENATE 'cd' lv_ftp_path INTO lv_command SEPARATED BY space.
CONCATENATE lv_command sy-datum INTO lv_command. "edit by pxmwyzh 20181014
* CONCATENATE lv_command '/' sy-datum INTO lv_command.
CALL FUNCTION 'FTP_COMMAND'
EXPORTING
handle = lv_hdl
command = lv_command
TABLES
data = it_result
EXCEPTIONS
command_error = 1
tcpip_error = 2.
IF sy-subrc <> 0.
MESSAGE ID 'Z06500' TYPE 'E' NUMBER '101' INTO lv_msg. "FTP操作失败-打开子目录失败
ls_return-type = 'E'.
ls_return-message = lv_msg.
APPEND ls_return TO et_return.CLEAR:ls_return.
RETURN.
ENDIF.
ELSEIF sy-subrc <> 0 AND sy-subrc <> 1.
MESSAGE ID 'Z06500' TYPE 'E' NUMBER '101' INTO lv_msg.
ls_return-type = 'E'.
ls_return-message = lv_msg.
APPEND ls_return TO et_return.CLEAR:ls_return.
RETURN.
ENDIF.
*"----------------------------------------------------------------------
* 获取GUID
TRY.
lv_guid = cl_system_uuid=>create_uuid_c32_static( ).
CATCH cx_uuid_error INTO lv_oref.
ls_return-type = 'E'.
ls_return-number = '000'.
ls_return-message = lv_oref->get_text( ).
APPEND ls_return TO et_return.CLEAR:ls_return.
RETURN.
ENDTRY.
*"----------------------------------------------------------------------
* 生成PDF文件
CONCATENATE lv_guid '.pdf' INTO lv_filename.CONDENSE lv_filename NO-GAPS.
CALL FUNCTION 'FTP_R3_TO_SERVER' "传输到FTP服务器
EXPORTING
handle = lv_hdl
fname = lv_filename
blob_length = lv_blength
TABLES
blob = lt_bindata
EXCEPTIONS
tcpip_error = 1
command_error = 2
data_error = 3.
IF sy-subrc <> 0.
MESSAGE ID 'Z06500' TYPE 'E' NUMBER '090' INTO lv_msg. "PDF文件生成失败
ls_return-type = 'E'.
ls_return-message = lv_msg.
APPEND ls_return TO et_return.CLEAR:ls_return.
RETURN.
ENDIF.
lv_num = strlen( lv_command ).
lv_path = lv_command+2(lv_num).
CONDENSE lv_path NO-GAPS.
*"----------------------------------------------------------------------
e_path = lv_path.
e_filename = lv_filename.
*"----------------------------------------------------------------------
ENDFUNCTION.
Z_06PM_FTP_CONNECT
FUNCTION z_06pm_ftp_connect.
*"----------------------------------------------------------------------
*"*"Local interface:
*" EXPORTING
*" REFERENCE(E_HDL) TYPE I
*" REFERENCE(E_MSG) TYPE Z10WFSKE01
*"----------------------------------------------------------------------
DATA: lv_slen TYPE i,
lv_host(100) TYPE c,
lv_pwd(50) TYPE c,
ls_mess TYPE z10wfske01,
lv_hdl TYPE i.
DATA: ls_ftp TYPE z06pmtftpcf.
*查询配置表
SELECT SINGLE *
INTO ls_ftp
FROM z06pmtftpcf
WHERE intid EQ cns_intid .
* 生成FTP服务器地址
CLEAR lv_host.
CONCATENATE ls_ftp-ipadr ls_ftp-zport INTO lv_host SEPARATED BY space.
* CONCATENATE cns_ip cns_port INTO lv_host SEPARATED BY space.
CLEAR lv_slen.
lv_slen = strlen( ls_ftp-paswd ).
* lv_slen = strlen( cns_pass ).
* 将密码加密
CLEAR lv_pwd.
CALL FUNCTION 'HTTP_SCRAMBLE'
EXPORTING
source = ls_ftp-paswd
* source = cns_pass
sourcelen = lv_slen
key = cns_key
IMPORTING
destination = lv_pwd.
* 连接到FTP服务器
DO 3 TIMES.
CLEAR lv_hdl.
CALL FUNCTION 'FTP_CONNECT'
EXPORTING
user = ls_ftp-usrid
* user = cns_user
password = lv_pwd
host = lv_host
rfc_destination = cns_dest
IMPORTING
handle = lv_hdl
EXCEPTIONS
not_connected = 1.
IF sy-subrc NE 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4 INTO ls_mess-msgtxt.
ls_mess-msgtyp = sy-msgty.
ls_mess-msgno = sy-msgno.
e_msg = ls_mess.
RETURN.
ENDIF.
ENDDO.
e_hdl = lv_hdl.
ENDFUNCTION.