ABAP顾问
分类:
2011-07-25 16:28:26
REPORT z_barry_up_server.
TABLES: sscrfields.
DATA: serverfile(100) ,
file(80).
DATA dyfields LIKE dynpread OCCURS 0 WITH HEADER LINE.
SELECTION-SCREEN FUNCTION KEY 1.
SELECTION-SCREEN FUNCTION KEY 2.
PARAMETERS: p_file LIKE rcgfiletr-ftfront OBLIGATORY LOWER CASE ,
p_serv LIKE rcgfiletr-ftappl OBLIGATORY.
PARAMETERS p_over LIKE bapistdtyp-boolean.
INITIALIZATION.
CALL 'C_SAPGPARAM' ID 'NAME' FIELD 'DIR_HOME'
ID 'VALUE' FIELD serverfile.
CONCATENATE serverfile '/' INTO serverfile.
p_serv = serverfile.
sscrfields-functxt_01 = '上载到服务器'.
sscrfields-functxt_02 = '从服务器下载'.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
CALL FUNCTION 'F4_FILENAME'
EXPORTING
program_name = syst-cprog
dynpro_number = syst-dynnr
field_name = ' '
IMPORTING
file_name = p_file.
CALL FUNCTION 'SO_SPLIT_FILE_AND_PATH'
EXPORTING
full_name = p_file
IMPORTING
stripped_name = file
EXCEPTIONS
x_error = 1
OTHERS = 2.
CLEAR:dyfields, dyfields[].
dyfields-fieldname = 'P_SERV'.
CONCATENATE serverfile file INTO dyfields-fieldvalue.
APPEND dyfields.
CALL FUNCTION 'DYNP_VALUES_UPDATE'
EXPORTING
dyname = sy-cprog
dynumb = sy-dynnr
TABLES
dynpfields = dyfields.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_serv.
CLEAR: dyfields[], dyfields.
dyfields-fieldname = 'P_SERV'.
APPEND dyfields.
CALL FUNCTION 'DYNP_VALUES_READ'
EXPORTING
dyname = sy-cprog
dynumb = sy-dynnr
TABLES
dynpfields = dyfields.
READ TABLE dyfields INDEX 1.
CALL FUNCTION '/SAPDMC/LSM_F4_SERVER_FILE'
EXPORTING
directory = dyfields-fieldvalue
filemask = ' '
IMPORTING
serverfile = serverfile
EXCEPTIONS
canceled_by_user = 1
OTHERS = 2.
CONCATENATE serverfile '/' INTO serverfile .
p_serv = serverfile.
AT SELECTION-SCREEN.
CASE sy-ucomm . " SY-DYNNR SSCRFIELDS-UCOMM
WHEN 'FC01'.
CALL FUNCTION 'C13Z_FILE_UPLOAD_BINARY'
EXPORTING
i_file_front_end = p_file
i_file_appl = p_serv
i_file_overwrite = p_over
EXCEPTIONS
fe_file_not_exists = 1
fe_file_read_error = 2
ap_no_authority = 3
ap_file_open_error = 4
ap_file_exists = 5
OTHERS = 6.
IF sy-subrc <> 0.
CASE sy-subrc.
WHEN 1.
MESSAGE e000(oo) WITH '本地文件不存在'.
WHEN 2.
MESSAGE e000(oo) WITH '读取本地文件错误'.
WHEN 3.
MESSAGE e000(oo) WITH '没有服务器上载权限'.
WHEN 4.
MESSAGE e000(oo) WITH '服务器文件打开错误'.
WHEN 5.
MESSAGE e000(oo) WITH '服务器上此文件已存在'.
WHEN OTHERS.
MESSAGE e000(oo) WITH '不知道什么错误,反正是出错了'.
ENDCASE.
ELSE.
MESSAGE s000(oo) WITH '上船完毕!'.
ENDIF.
WHEN 'FC02'.
CALL FUNCTION 'C13Z_FILE_DOWNLOAD_BINARY'
EXPORTING
i_file_front_end = p_file
i_file_appl = p_serv
i_file_overwrite = p_over
EXCEPTIONS
fe_file_open_error = 1
fe_file_exists = 2
fe_file_write_error = 3
ap_no_authority = 4
ap_file_open_error = 5
ap_file_empty = 6
OTHERS = 7.
IF sy-subrc <> 0.
CASE sy-subrc.
WHEN 1.
MESSAGE e000(oo) WITH '本地文件打开错误'.
WHEN 2.
MESSAGE e000(oo) WITH '本地文件已存在'.
WHEN 3.
MESSAGE e000(oo) WITH '写本地文件出错,可能是这个路径不让写'.
WHEN 4.
MESSAGE e000(oo) WITH '没有服务器下载权限'.
WHEN 5.
MESSAGE e000(oo) WITH '服务器文件打开错误'.
WHEN 6.
MESSAGE e000(oo) WITH '服务器上文件为空'.
WHEN OTHERS.
MESSAGE e000(oo) WITH '不知道什么错误,反正是出错了'.
ENDCASE.
ELSE.
MESSAGE s000(oo) WITH '下载完毕!'.
ENDIF.
ENDCASE.
START-OF-SELECTION.
MESSAGE s000(oo) WITH '点旁边那两个按钮,别点我!'.