标签:table catalog others mes splay 表数据 struct 备份表 assign
主要就是动态内表
PARAMETERS: p_tabf TYPE dd02l-tabname, "原表名称
p_tabt TYPE dd02l-tabname. "备份表名称
DATA: it_tabf TYPE lvc_t_fcat,
it_tabt TYPE lvc_t_fcat.
DATA: it_tabfc TYPE lvc_t_fcat,
it_tabtc TYPE lvc_t_fcat.
DATA: lcx_error TYPE REF TO cx_root.
DATA: dy_table TYPE REF TO data,
dy_line TYPE REF TO data.
FIELD-SYMBOLS: <dyn_table> TYPE STANDARD TABLE.
* <dyn_wa>,
* <dyn_field>.
FIELD-SYMBOLS: <fs_tab> LIKE lvc_s_fcat.
CALL FUNCTION ‘LVC_FIELDCATALOG_MERGE‘
EXPORTING
i_client_never_display = ‘‘
i_structure_name = p_tabf
CHANGING
ct_fieldcat = it_tabf
EXCEPTIONS
inconsistent_interface = 1
program_error = 2
OTHERS = 3.
CALL FUNCTION ‘LVC_FIELDCATALOG_MERGE‘
EXPORTING
i_client_never_display = ‘‘
i_structure_name = p_tabt
CHANGING
ct_fieldcat = it_tabt
EXCEPTIONS
inconsistent_interface = 1
program_error = 2
OTHERS = 3.
it_tabfc = it_tabf.
it_tabtc = it_tabt.
LOOP AT it_tabfc ASSIGNING <fs_tab>.
CLEAR: <fs_tab>-ref_table.
ENDLOOP.
LOOP AT it_tabtc ASSIGNING <fs_tab>.
CLEAR: <fs_tab>-ref_table.
ENDLOOP.
IF it_tabfc <> it_tabtc.
MESSAGE ‘复制的原表与目的表结构不一致,请确认‘ TYPE ‘S‘ DISPLAY LIKE ‘E‘.EXIT.
ENDIF.
CALL METHOD cl_alv_table_create=>create_dynamic_table
EXPORTING
it_fieldcatalog = it_tabf
* I_LENGTH_IN_BYTE = ‘X‘
IMPORTING
ep_table = dy_table.
ASSIGN dy_table->* TO <dyn_table>.
SELECT * INTO TABLE <dyn_table> FROM (p_tabf) .
IF sy-subrc = 0.
TRY.
DELETE FROM (p_tabt). "清除TO表中所有数据
INSERT (p_tabt) FROM TABLE <dyn_table>.
CATCH cx_sy_open_sql_db INTO lcx_error.
ENDTRY.
IF sy-subrc = 0.
COMMIT WORK.
MESSAGE ‘数据备份成功‘ TYPE ‘S‘.
ELSE.
ROLLBACK WORK.
MESSAGE ‘数据备份失败,请重试‘ TYPE ‘S‘ DISPLAY LIKE ‘E‘.
ENDIF.
ENDIF.
标签:table catalog others mes splay 表数据 struct 备份表 assign
原文地址:https://www.cnblogs.com/jingqing/p/13381137.html