日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

复制迁移数据库表数据程序

發布時間:2025/3/20 24 豆豆
生活随笔 收集整理的這篇文章主要介紹了 复制迁移数据库表数据程序 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
其實很簡單就是用move-corresponding語句,匹配兩邊的相同字段,然后賦值,就可以實現簡單地在數據庫表之間遷移數據了。
  • *&---------------------------------------------------------------------*
  • *& Report??ZTABLECOPY
  • *&
  • *&---------------------------------------------------------------------*
  • *&
  • *&
  • *&---------------------------------------------------------------------*

  • REPORT??ZTABLECOPY.
  • parameters:p_stbl type tabname16,"Source table name
  • ? ?? ?? ???p_ttbl type tabname16,"Target table name
  • ? ?? ?? ???p_over as checkbox,"Overwrite existing data
  • ? ?? ?? ???p_del as checkbox."Delete before copy
  • data:record_count type int4.
  • data:gs_table type dd02l.

  • at selection-screen on p_stbl."Check existence of source table
  • ??select single *
  • ? ? from dd02l
  • ? ? into gs_table
  • ? ? where tabname = p_stbl
  • ? ?? ?and as4local = 'A'.
  • ??if sy-subrc ne 0.
  • ? ? message 'Source table not exists' type 'E'.
  • ??endif.

  • at selection-screen on p_ttbl."Check existence of target table
  • ??select single *
  • ? ? from dd02l
  • ? ? into gs_table
  • ? ? where tabname = p_ttbl
  • ? ?? ?and as4local = 'A'.
  • ??if sy-subrc ne 0.
  • ? ? message 'Target table not exists' type 'E'.
  • ??endif.

  • ??select count(*) into record_count from (p_ttbl).
  • ? ? if record_count gt 0 and p_over is initial and p_del is initial.
  • ? ?? ?message 'Target table has data' type 'E'.
  • ? ? endif.

  • data:gt_data_s type ref to data,
  • ? ???gs_data_s type ref to data,
  • ? ???go_struct_type_s type ref to cl_ABAP_structdescr,
  • ? ???go_table_type_s type ref to cl_abap_tabledescr,
  • ? ???gt_data_t type ref to data,
  • ? ???gs_data_t type ref to data,
  • ? ???go_struct_type_t type ref to cl_abap_structdescr,
  • ? ???go_table_type_t type ref to cl_abap_tabledescr.
  • field-symbols:<fs_data_s> type any,
  • ? ?? ?? ?? ?? ?<ft_data_s> type standard table,
  • ? ?? ?? ?? ?? ?<fs_data_t> type any,
  • ? ?? ?? ?? ?? ?<ft_data_t> type standard table.


  • *get type and create data reference

  • go_struct_type_s ?= cl_abap_typedescr=>DESCRIBE_BY_NAME( p_stbl??).
  • go_struct_type_t ?= cl_abap_typedescr=>DESCRIBE_BY_NAME( p_ttbl??).
  • go_table_type_s = cl_abap_tabledescr=>CREATE(
  • ? ? P_LINE_TYPE??= go_struct_type_s
  • *? ? P_TABLE_KIND = TABLEKIND_STD
  • *? ? P_UNIQUE? ???= ABAP_FALSE
  • *? ? P_KEY? ?? ???=
  • *? ? P_KEY_KIND? ?= KEYDEFKIND_DEFAULT
  • ).
  • *??catch CX_SY_TABLE_CREATION.??" Exception when Creating a Table Type
  • go_table_type_t = cl_abap_tabledescr=>CREATE(
  • ? ? P_LINE_TYPE??= go_struct_type_t
  • *? ? P_TABLE_KIND = TABLEKIND_STD
  • *? ? P_UNIQUE? ???= ABAP_FALSE
  • *? ? P_KEY? ?? ???=
  • *? ? P_KEY_KIND? ?= KEYDEFKIND_DEFAULT
  • ).
  • *??catch CX_SY_TABLE_CREATION.??" Exception when Creating a Table Type

  • create data gs_data_s type handle go_struct_type_s.
  • create data gt_data_s type handle go_table_type_s.
  • create data gs_data_t type handle go_struct_type_t.
  • create data gt_data_t type handle go_table_type_t.
  • assign gs_data_s->* to <fs_data_s>.
  • assign gs_data_t->* to <fs_data_t>.
  • assign gt_data_s->* to <ft_data_s>.
  • assign gt_data_t->* to <ft_data_t>.

  • *fetch data from source table
  • select * from (p_stbl)
  • ??into table <ft_data_s>.

  • *copy using move coressponding
  • loop at <ft_data_s> assigning <fs_data_s>.
  • ??clear <fs_data_t>.
  • ??MOVE-CORRESPONDING <fs_data_s> to <fs_data_t>.
  • ??append <fs_data_t> to <ft_data_t>.
  • endloop.

  • *delete data if required
  • if p_del eq abap_true.
  • ??delete from (p_ttbl).
  • endif.
  • *update data
  • modify (p_ttbl) from table <ft_data_t>.

  • write:'finish'.
  • 總結

    以上是生活随笔為你收集整理的复制迁移数据库表数据程序的全部內容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。