EXCEL 导入数据到数据库表

TABLES: alsmex_tabline,ztraining_wxj.

DATA: BEGIN OF iexcel OCCURS 0.
        INCLUDE STRUCTURE alsmex_tabline.
DATA: END OF iexcel.

DATA: BEGIN OF itab OCCURS 0.
        INCLUDE STRUCTURE ztraining_wxj.
DATA: END OF itab.
DATA wa LIKE LINE OF itab.

* No of columns
DATA: BEGIN OF data_tab OCCURS 0,
       value_0001(003) TYPE c,
       value_0002(004) TYPE c,
       value_0003(010) TYPE c,
       value_0004(002) TYPE c,
       value_0005(020) TYPE c.
DATA: END OF data_tab.           "存放excel里的数据

DATA: tind(4) TYPE n.
DATA: zwfeld(19).
FIELD-SYMBOLS: <fs1>.
DATA: filenm LIKE rlgrap-filename.

call function 'WS_FILENAME_GET'
  exporting
    title            = '请选择目标文件文件 '
  importing
    filename         = filenm
  exceptions
    inv_winsys       = 1
    no_batch         = 2
    selection_cancel = 3
    selection_error  = 4
    others           = 5.

*PARAMETERS: filenm   LIKE rlgrap-filename MEMORY ID m01,
*            noheader AS CHECKBOX.

CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'
  EXPORTING
    filename                = filenm
    i_begin_col             = 1
    i_begin_row             = 1
    i_end_col               = 100
    i_end_row               = 30000
  TABLES
    intern                  = iexcel               "excel数据所在的内表
  EXCEPTIONS
    inconsistent_parameters = 1
    upload_ole              = 2
    OTHERS                  = 3.

IF sy-subrc <> 0.
  WRITE: / 'EXCEL UPLOAD FAILED ', filenm, sy-subrc.
ELSE.
  SORT iexcel BY row col.
  LOOP AT iexcel FROM 6.                           "从第6个字段开始读取,第五个是地址
    tind = iexcel-col.
    CONCATENATE 'DATA_TAB-VALUE_' tind INTO zwfeld.
    ASSIGN (zwfeld) TO <fs1>.     "
    <fs1> = iexcel-value.
    AT END OF row.
      APPEND data_tab.
*      move-corresponding data_tab to wa.
      wa-zpid = data_tab-value_0002.
      wa-mandt = data_tab-value_0001.
      wa-zpname = data_tab-value_0003.
      wa-zpage = data_tab-value_0004.
      wa-zpaddress = data_tab-value_0005.
      APPEND wa TO itab.
*      WRITE:/ data_tab-value_0001, data_tab-value_0002,
*                           data_tab-value_0003, data_tab-value_0004.
*      write : / wa-zpid, wa-zpname.
      INSERT into ztraining_wxj values wa.
      IF sy-subrc = 0.
        MESSAGE '成功更新' TYPE 'I'.
      ELSE.
        MESSAGE '更新失败' TYPE 'I'.
      ENDIF.
      CLEAR data_tab.
    ENDAT.
  ENDLOOP.
ENDIF.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值