ABAP 内表转CSV文件推送SAP服务器和SFTP到对方服务器
1、内表转CSV文件,老ECC个别版本该函数有BUG,I类型字段会dump
DATA:lt_csv_vbak TYPE ztruxs_t_text_data,"ztruxs_t_text_data长度为8192
CALL FUNCTION 'ZSAP_CONVERT_TO_CSV_FORMAT' TABLES i_tab_sap_data = lt_vbak CHANGING i_tab_converted_data = lt_csv_vbak EXCEPTIONS conversion_failed = 1 OTHERS = 2.
2、推送SAP服务器,使用open dataset,百度一堆
DATA:BEGIN OF ls_tab, tline(8192), "与内表转CSV文件参考类型长度一致 END OF LS_TAB. CONCATENATE lv_dir gv_vbak_filename INTO lv_dir_path. OPEN DATASET lv_dir_path FOR OUTPUT IN TEXT MODE ENCODING NON-UNICODE. IF sy-subrc = 0. CLEAR:ls_tab,ls_tab. LOOP AT lt_tab_vbak INTO ls_tab . TRANSFER ls_tab TO lv_dir_path. ENDLOOP. CLOSE DATASET lv_dir. ENDIF.
3、推送SFTP,以WINDOWS NT为例,LINUX系统类似;可参考SAP to SFTP simple Setup with a Windows Host | SAP Blogs;但把命令封装到参数里调用函数不行,使用下述方法可以
首先安装Winscp 方法网上有
其次配置SM69,文件操作命令写在脚本里
脚本命令
代码:
DATA:lv_param TYPE sxpgcolist-parameters, lv_exitcode TYPE btcxpgexit, lt_protocol TYPE TABLE OF btcxpm. CONCATENATE '/parameter d:\usr\sap\datalake\' p_lv_file_name INTO lv_param."sap服务器文件路径 CALL FUNCTION 'SXPG_COMMAND_EXECUTE' EXPORTING commandname = 'ZSFTP' additional_parameters = lv_param IMPORTING exitcode = lv_exitcode TABLES exec_protocol = lt_protocol EXCEPTIONS no_permission = 1 command_not_found = 2 parameters_too_long = 3 security_risk = 4 wrong_check_call_interface = 5 program_start_error = 6 program_termination_error = 7 x_error = 8 parameter_expected = 9 too_many_parameters = 10 illegal_command = 11 wrong_asynchronous_parameters = 12 cant_enq_tbtco_entry = 13 jobcount_generation_error = 14 OTHERS = 15. IF lv_exitcode = 0. p_lv_flg = 'S'. ELSE. p_lv_flg = 'E'. ENDIF.
社会很单纯,复杂的是人