上载CSV文件到本机(KCD_CSV_FILE_TO_INTERN_CONVERT)

Posted china_wangxiaowen

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了上载CSV文件到本机(KCD_CSV_FILE_TO_INTERN_CONVERT)相关的知识,希望对你有一定的参考价值。

可以通过过函数KCD_CSV_FILE_TO_INTERN_CONVERT将CSV格式的文件上载到本机。

代码如下:

REPORT z_upload_csv.
TYPE-POOLS: kcde.

TYPES: BEGIN OF ty_input,
         id    TYPE string,
         name  TYPE string,
         place TYPE string,
         phone TYPE string,
       END OF ty_input.

CONSTANTS: c_separator TYPE c VALUE \',\'.

DATA: gt_intern  TYPE kcde_intern,
      gwa_intern TYPE kcde_intern_struc.

DATA: gt_input  TYPE TABLE OF ty_input,
      gwa_input TYPE ty_input.
*----------------------------------------------------------------------*
*     SELECTION-SCREEN
*----------------------------------------------------------------------*
PARAMETERS: p_file TYPE localfile OBLIGATORY.
*----------------------------------------------------------------------*
*     AT SELECTION-SCREEN ON VALUE-REQUEST
*----------------------------------------------------------------------*
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
*F4 help for the file in selection screen
  CALL FUNCTION \'F4_FILENAME\'
    IMPORTING
      file_name = p_file.
*----------------------------------------------------------------------*
*     START-OF-SELECTION
*----------------------------------------------------------------------*
START-OF-SELECTION.
* Read data from File
  PERFORM readfile USING p_file.
* Display data
  PERFORM display.
*&---------------------------------------------------------------------*
*&      Form  READFILE
*&---------------------------------------------------------------------*
FORM readfile USING p_file TYPE localfile.

  DATA: lv_filename TYPE rlgrap-filename.
  DATA: lv_index TYPE i.
  FIELD-SYMBOLS: <lfs_field> TYPE any.

  lv_filename = p_file.

* 读取CSV文件
  CALL FUNCTION \'KCD_CSV_FILE_TO_INTERN_CONVERT\'
    EXPORTING
      i_filename      = lv_filename
      i_separator     = c_separator
    TABLES
      e_intern        = gt_intern
    EXCEPTIONS
      upload_csv      = 1
      upload_filetype = 2
      OTHERS          = 3.
  IF sy-subrc <> 0.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
            WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  ENDIF.

* 将读取的CSV内容转换保存到内表gt_input中
  LOOP AT gt_intern INTO gwa_intern.
    MOVE : gwa_intern-col TO lv_index.
    ASSIGN COMPONENT lv_index OF STRUCTURE gwa_input TO <lfs_field>.
    MOVE : gwa_intern-value TO <lfs_field> .
    AT END OF row.
      APPEND gwa_input TO gt_input.
      CLEAR gwa_input.
    ENDAT.
  ENDLOOP.

ENDFORM.                    " READFILE
*&---------------------------------------------------------------------*
*&      Form  DISPLAY
*&---------------------------------------------------------------------*
FORM display.
* 输出CSV内容
  LOOP AT gt_input INTO gwa_input.
    WRITE:/ gwa_input-id,8 gwa_input-name,16
            gwa_input-place,26 gwa_input-phone.
  ENDLOOP.
ENDFORM.                    " DISPLAY

 

引用来自 http://www.baidusap.com/abap/function/2114

 

以上是关于上载CSV文件到本机(KCD_CSV_FILE_TO_INTERN_CONVERT)的主要内容,如果未能解决你的问题,请参考以下文章

从vmware workstation9.0中 上载虚拟服务器到ESXI

批量插入/上载microsoft sql server(csv)

php 将文件上载到AWS S3

php 允许将SVG文件上载到媒体库

正在将二进制文件上载到Dropbox

Servlet如何读取客户端上载的文件