1.上传CSV文件的时候分隔符是分号,导致传过去的一行数据全部在第一列的第一格里面。在上传之前转换成逗号;
2.上传文件出现中文乱码,网上出现中文乱码的情况很多,这里我只记录自己遇到的。中文传到FTP的时候显示#;
CALL FUNCTION 'SCMS_TEXT_TO_BINARY'
EXPORTING
ENCODING = '8400'
IMPORTING
output_length = blob_length
TABLES
text_tab = text " input
binary_tab = in_data" output
EXCEPTIONS
failed = 1
OTHERS = 2.
此时只需要在传递文件之前转码,encoding = 8400即可 这是在RZ10 的install/codepage/appl_server = 8400的情况下还要注明的,不管该参数的结果是否是8400,都需要转码。
3.SAP上传文件到ftp需要后台执行的时候, rfc_destination = 'SAPFTPA'不能写成SAPFTP。
FOR EXAMPLE:(该程序需要修改才能激活)
TYPE-POOLS truxs.
DATA: mi_key TYPE i VALUE 26101957,
mi_handle TYPE i,
slen TYPE i .
DATA: csvtab TYPE truxs_t_text_data .
DATA:csvtab1 TYPE truxs_t_text_data WITH HEADER LINE.
DATA : filename(128) .
DATA:BEGIN OF RES OCCURS 0,
LINE(100) TYPE C,
END OF RES.
CONCATENATE sy-datum 'test.csv' INTO filename .
DATA: suser(30) TYPE c,
spwd(30) TYPE c,
shost(64) TYPE c.
suser = 'test'.
spwd = 'test'.
shost = '10.20.30.40'.
DATA: in_data TYPE STANDARD TABLE OF bapiconten."like csvtab OCCURS 0.
DATA: text TYPE lvc_t_1022 WITH HEADER LINE.
DATA:blob_length TYPE i.
DATA:b(20) TYPE c.
slen = STRLEN( spwd ).
TYPES:BEGIN OF ty_itab,
* mandt TYPE zyyzb035hz-mandt,
BUDAT_MKPF(8) TYPE c,
KUNNR TYPE zyyzb035hz-KUNNR,
NAME1 TYPE zyyzb035hz-NAME1,
KTEXT TYPE zyyzb035hz-KTEXT,
ZLX TYPE zyyzb035hz-zlx,
ZBM TYPE zyyzb035hz-zbm,
ZQU TYPE zyyzb035hz-zqu,
ZDRXS(20) TYPE c,
ZDYXS(20) TYPE c,
ZDNXS(20) TYPE c,
END OF ty_itab.
DATA:gw_itab TYPE TABLE OF ty_itab.
DATA:gs_itab TYPE ty_itab.
FIELD-SYMBOLS
FIELD-SYMBOLS
LOOP AT lt_itab1 ASSIGNING
gs_itab-BUDAT_MKPf =
gs_itab-KUNNR =
gs_itab-NAME1 =
gs_itab-KTEXT =
gs_itab-ZLX =
gs_itab-ZBM =
gs_itab-ZQU =
gs_itab-ZDRXS =
gs_itab-ZDYXS =
gs_itab-ZDNXS =
APPEND gs_itab to gw_itab.
CLEAR gs_itab.
ENDLOOP.
LOOP AT gw_itab ASSIGNING
IF
b =
CALL FUNCTION 'CLOI_PUT_SIGN_IN_FRONT'
CHANGING
value = b.
ENDIF.
IF
b =
CALL FUNCTION 'CLOI_PUT_SIGN_IN_FRONT'
CHANGING
value = b.
ENDIF.
IF
b =
CALL FUNCTION 'CLOI_PUT_SIGN_IN_FRONT'
CHANGING
value = b.
ENDIF.
ENDLOOP.
CALL FUNCTION 'SAP_CONVERT_TO_CSV_FORMAT'
TABLES
I_TAB_SAP_DATA = gw_itab
CHANGING
I_TAB_CONVERTED_DATA = csvtab
EXCEPTIONS
CONVERSION_FAILED = 1
OTHERS = 2.
IF SY-SUBRC <> 0.
* Implement suitable error handling here
ENDIF.
LOOP AT csvtab INTO csvtab1.
REPLACE ALL OCCURRENCES OF ',' in csvtab1 WITH ''.
REPLACE ',' WITH '' INTO csvtab1 LENGTH 1.
CONDENSE csvtab1 NO-GAPS.
APPEND csvtab1 to csvtab1.
ENDLOOP.
DATA a(400) TYPE c.
a = '过帐日期,客户,XXX,XXX,XXX,XXX,XXX,XXX,XXX,XXX'.
APPEND a to text.
LOOP AT csvtab1.
a = csvtab1.
* REPLACE ';' WITH '' INTO a LENGTH 1.
REPLACE ';' WITH ',' INTO a LENGTH 1.
REPLACE ';' WITH ',' INTO a LENGTH 1.
REPLACE ';' WITH ',' INTO a LENGTH 1.
REPLACE ';' WITH ',' INTO a LENGTH 1.
REPLACE ';' WITH ',' INTO a LENGTH 1.
REPLACE ';' WITH ',' INTO a LENGTH 1.
REPLACE ';' WITH ',' INTO a LENGTH 1.
REPLACE ';' WITH ',' INTO a LENGTH 1.
REPLACE ';' WITH ',' INTO a LENGTH 1.
CONDENSE a NO-GAPS.
*
* REPLACE ALL OCCURRENCES OF ',' in a WITH ';'.
* REPLACE ';' WITH ',' INTO a LENGTH 5.
APPEND a to text.
ENDLOOP.
CALL FUNCTION 'HTTP_SCRAMBLE'
EXPORTING
SOURCE = spwd
sourcelen = slen
key = mi_key
IMPORTING
destination = spwd.
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 'FTP_CONNECT'
EXPORTING
user = suser
password = spwd
host = shost
rfc_destination = 'SAPFTPA' "SAPFTPA
IMPORTING
handle = mi_handle
EXCEPTIONS
not_connected = 1
OTHERS = 2.
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 'SCMS_TEXT_TO_BINARY'
EXPORTING
ENCODING = '8400'
IMPORTING
output_length = blob_length
TABLES
text_tab = text " input
binary_tab = in_data" output
EXCEPTIONS
failed = 1
OTHERS = 2.
CALL FUNCTION 'FTP_COMMAND'
EXPORTING
HANDLE = mi_handle
COMMAND = 'cd SAP'" jmswechat/custom'
COMPRESS = 'N'
TABLES
DATA = RES "result
EXCEPTIONS
COMMAND_ERROR = 1
TCPIP_ERROR = 2.
CALL FUNCTION 'FTP_R3_TO_SERVER'
EXPORTING
handle = mi_handle
fname = filename
blob_length = blob_length
* character_mode = 'X'
TABLES
blob = in_data.
* text = text.
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 'FTP_DISCONNECT'
EXPORTING
handle = mi_handle
EXCEPTIONS
OTHERS = 1.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.