*&---------------------------------------------------------------------*
*& 包括 ZUPLOAD_DOWNLOAD
*&---------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*& Form ws_filename_get
*&---------------------------------------------------------------------*
FORM WS_FILENAME_GET USING P_FILE.
CALL FUNCTION 'WS_FILENAME_GET'
EXPORTING
DEF_FILENAME = '*.txt'
DEF_PATH = 'C:\'
MASK = ',*.txt.'
MODE = 'O'
TITLE = TEXT-004
IMPORTING
FILENAME = P_FILE
EXCEPTIONS
INV_WINSYS = 1
NO_BATCH = 2
SELECTION_CANCEL = 3
SELECTION_ERROR = 4
OTHERS = 5.
ENDFORM. " ws_filename_get
*&---------------------------------------------------------------------*
*& Form UPLOAD_FILE
*&---------------------------------------------------------------------*
FORM UPLOAD_FILE TABLES IT_UPLOAD
USING P_FILE.
DATA: FSIZEIN TYPE I,
W_REJECT TYPE I,
IJIR TYPE I VALUE 0,
W_TYPE LIKE DD01V-DATATYPE.
DATA: P_TYPE LIKE RLGRAP-FILETYPE VALUE 'DAT'.
*-- Upload the Main Material Master file using Function 'WS_UPLOAD'
CALL FUNCTION 'WS_UPLOAD'
EXPORTING
FILENAME = P_FILE
FILETYPE = P_TYPE
IMPORTING
FILELENGTH = FSIZEIN
TABLES
DATA_TAB = IT_UPLOAD
EXCEPTIONS
CONVERSION_ERROR = 1
FILE_OPEN_ERROR = 2
FILE_READ_ERROR = 3
INVALID_TABLE_WIDTH = 4
INVALID_TYPE = 5
NO_BATCH = 6
UNKNOWN_ERROR = 7
OTHERS = 8.
*-- If error, display the necessary Error Message.
CASE SY-SUBRC.
WHEN 1. PERFORM MSG USING '转换错误' 'E'.
WHEN 2. PERFORM MSG USING '文件打开错误' 'E'.
WHEN 3. PERFORM MSG USING '文件读取错误' 'E'.
WHEN 4. PERFORM MSG USING '表宽不对' 'E'.
WHEN 5. PERFORM MSG USING '文件类型不对' 'E'.
WHEN 6. PERFORM MSG USING '不是批处理' 'E'.
WHEN 7. PERFORM MSG USING '不知名的错误' 'E'.
WHEN 8. PERFORM MSG USING '其他错误' 'E'.
ENDCASE.
DELETE IT_UPLOAD INDEX 1.
IF IT_UPLOAD[] IS INITIAL.
MESSAGE E315 WITH '上载文件错误,请检查'.
STOP.
ENDIF.
ENDFORM. " UPLOAD_FILE
*&---------------------------------------------------------------------*
*& Form MSG
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->MSGTXT text
* -->MSGTYPE text
*----------------------------------------------------------------------*
FORM MSG USING MSGTXT MSGTYPE.
CASE MSGTYPE.
WHEN 'E'. MESSAGE E315 WITH MSGTXT.
WHEN 'I'. MESSAGE I315 WITH MSGTXT.
WHEN 'S'. MESSAGE S315 WITH MSGTXT.
WHEN 'W'. MESSAGE W315 WITH MSGTXT.
WHEN 'A'. MESSAGE A315 WITH MSGTXT.
ENDCASE.
ENDFORM. "MSG
*&---------------------------------------------------------------------*
*& Form DOWN_LOAD
*&---------------------------------------------------------------------*
FORM DOWN_LOAD TABLES IT_ERROR
USING P_DOWN.
CONCATENATE P_DOWN '_' SY-DATUM '_' SY-UZEIT '.txt'
INTO P_DOWN.
CONDENSE P_DOWN.
CALL FUNCTION 'WS_DOWNLOAD'
EXPORTING
FILENAME = P_DOWN
FILETYPE = 'DAT'
TABLES
DATA_TAB = IT_ERROR
EXCEPTIONS
CONVERSION_ERROR = 1
FILE_OPEN_ERROR = 2
FILE_READ_ERROR = 3
INVALID_TABLE_WIDTH = 4
INVALID_TYPE = 5
NO_BATCH = 6
UNKNOWN_ERROR = 7
OTHERS = 8.
IF SY-SUBRC = 0.
MESSAGE I999 WITH TEXT-S01 P_DOWN.
STOP.
ENDIF.
ENDFORM. " DOWN_LOAD