h0945634 发表于 2015-9-20 09:42:48

sap批量删除、添加、修改透明表数据

  删除一定要注意,空清空整个表的数据。慎用!
  REPORT   ZTEST006 MESSAGE-ID zmess.
DATA:lr_t_dtab    type ref to data."定义一个能够接纳任何数据对象的参照物
field-symbols:                                 "定义指针类型
   <lt_dtab_ins> type any table,
   <lt_dtab> type standard table.
PARAMETERS: p_del radiobutton group r1,
             p_insert radiobutton group r1 default 'X',
             p_modify radiobutton group r1,
            TABLE   LIKE DD02L-TABNAME,
             P_FILE TYPE STRING.
data: ICOUNT   TYPE i.
START-OF-SELECTION.
create data lr_t_dtab type standard table of (TABLE). “创建一个类型为table的动态工作区
assign lr_t_dtab->* to <lt_dtab>.”参考lr_t_dtab定义一个指针it_dtab来分配给该工作区
assign lr_t_dtab->* to <lt_dtab_ins>.
IF P_DEL = 'X'.
    DELETE FROM (TABLE).
    IF SY-SUBRC = 0.
    MESSAGE i101 WITH 'Delete success.'.
    endif.
ENDIF.
IF p_insert = 'X'.
   select * from (TABLE) into table <lt_dtab>.
IF SY-SUBRC = 0.
    MESSAGE E101 WITH 'Table is not empty.'.
ELSE.
    CALL FUNCTION 'GUI_UPLOAD'
      EXPORTING
         FILENAME                     = P_FILE
         FILETYPE                     = 'DAT'
      TABLES
         DATA_TAB                     = <lt_dtab>   .
    IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ELSE.
      INSERT (TABLE) FROM TABLE <lt_dtab>.
      MESSAGE i101 WITH 'Insert successful.'.
    ENDIF.
endif.
endif.
if p_modify   = 'X' .
      CALL FUNCTION 'GUI_UPLOAD'
      EXPORTING
         FILENAME                     = P_FILE
         FILETYPE                     = 'DAT'
      TABLES
         DATA_TAB                     = <lt_dtab>.
   IF SY-SUBRC <> 0.
       MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
   ELSE.
      delete (TABLE) FROM TABLE <lt_dtab>.
      commit work and wait.
      INSERT (TABLE) FROM TABLE <lt_dtab>.
   ENDIF.
endif.
   commit work and wait
页: [1]
查看完整版本: sap批量删除、添加、修改透明表数据