fypoop

博客园 首页 新随笔 联系 订阅 管理

REPORT  ZTEST_XIN0917                           .

TYPES:BEGIN OF i_file ,
       col1 TYPE i ,
        col2(3) TYPE c,
        col3(5) TYPE c,
     END OF i_file.

DATA: itab_file TYPE i_file OCCURS 0 WITH HEADER LINE.

***用户可看SAP帮助使用Download和upload的例##
***使用类弹出用户对话框
  DATA :s_filedir    LIKE rlgrap-filename .
  DATA: s_filemask(20) TYPE  c VALUE   ',*.txt ,*.txt. '.
  DATA: s_filepath(60) TYPE  c.


itab_file-col1 = 1.
itab_file-col2 = 'aaa'.
itab_file-col3 = 'aaa'.

append itab_file.


***Get current direcotry
  CALL FUNCTION 'WS_QUERY'
    EXPORTING
      query  = 'CD'
    IMPORTING
      return = s_filepath.
*** get file name ***
  CALL FUNCTION 'WS_FILENAME_GET'
    EXPORTING
      def_filename     = space
      def_path         = s_filepath
      mask             = s_filemask
      mode             = 'O'
    IMPORTING
      filename         = s_filedir
    EXCEPTIONS
      inv_winsys       = 1
      no_batch         = 2
      selection_cancel = 3
      selection_error  = 4
      OTHERS           = 5.
  CHECK sy-subrc EQ 0. "User might cancel operation.
***如果文件后坠非.TXT加上后坠
  TRANSLATE s_filedir TO UPPER CASE.
  IF '.TXT' CN s_filedir .
    CONCATENATE s_filedir '.TXT' INTO s_filedir .
  ENDIF.
*** write data to file ****
  CALL FUNCTION 'WS_DOWNLOAD'
    EXPORTING
      filename         = s_filedir
      filetype         = 'DAT'
      mode             = 'A'
    TABLES
      data_tab         = itab_file
    EXCEPTIONS
      file_open_error  = 01
      file_write_error = 02
      invalid_type     = 03
      no_batch         = 04
      unknown_error    = 05.
  CASE sy-subrc.
    WHEN 0.
      MESSAGE i001(00) WITH 'Data have been write into file:'
                            s_filedir ',Please check!' .
    WHEN 1.
      MESSAGE i001(00) WITH 'Error while opening file:' s_filedir.
    WHEN 2.
      MESSAGE i001(00) WITH  'Error in writing file ' s_filedir.
    WHEN 3.
      MESSAGE i001(00) WITH  'invalid file type of ' s_filedir .
    WHEN OTHERS.
      MESSAGE i001(00) WITH  'unknown error occured'.
  ENDCASE.

posted on 2007-09-18 13:34  冰冷  阅读(592)  评论(0编辑  收藏  举报