日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) >

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

發(fā)布時(shí)間:2025/3/20 16 豆豆
生活随笔 收集整理的這篇文章主要介紹了 复制迁移数据库表数据程序 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
其實(shí)很簡(jiǎn)單就是用move-corresponding語(yǔ)句,匹配兩邊的相同字段,然后賦值,就可以實(shí)現(xiàn)簡(jiǎn)單地在數(shù)據(jù)庫(kù)表之間遷移數(shù)據(jù)了。
  • *&---------------------------------------------------------------------*
  • *& 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'.
  • 總結(jié)

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

    如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。