REPORT ztest_client_copy.
TYPE-POOLS:abap.
TABLES:dd02l.
SELECT-OPTIONS:s_name FOR dd02l-tabname NO INTERVALS.
PARAMETERS p_mandt1 TYPE mandt DEFAULT '600'.
PARAMETERS p_mandt2 TYPE mandt DEFAULT '700'.
TYPES:BEGIN OF ty_tname,tabname TYPE dd02l-tabname,END OF ty_tname.
DATA: lt_tname TYPE TABLE OF ty_tname ,
ls_tname TYPE ty_tname.
DATA: d_ref TYPE REF TO data,
lt_alv_cat TYPE TABLE OF lvc_s_fcat,
ls_alv_cat LIKE LINE OF lt_alv_cat.
DATA: lt_table LIKE TABLE OF dntab.
DATA: ls_table TYPE dntab.
DATA: dyn_table TYPE REF TO data.
DATA: dyn_wa TYPE REF TO data.
FIELD-SYMBOLS :
<dyn_table> TYPE table,
<dyn_wa> TYPE ANY,
<dyn_field> TYPE ANY,
<fs_str> TYPE ANY.
*取出表结构的字段目录
*BREAK-POINT.
SELECT tabname INTO TABLE lt_tname FROM dd02l WHERE tabname IN s_name.
LOOP AT lt_tname INTO ls_tname.
CALL FUNCTION 'NAMETAB_GET'
EXPORTING
langu = sy-langu
tabname = ls_tname-tabname
TABLES
nametab = lt_table
EXCEPTIONS
no_texts_found = 1.
*根据取出的字段目录生成参考字段目录
LOOP AT lt_table INTO ls_table.
ls_alv_cat-fieldname = ls_table-fieldname.
ls_alv_cat-ref_table = ls_tname-tabname.
ls_alv_cat-ref_field = ls_table-fieldname.
APPEND ls_alv_cat TO lt_alv_cat.
CLEAR: ls_alv_cat,
ls_table.
ENDLOOP.
*内表创建
CALL METHOD cl_alv_table_create=>create_dynamic_table
EXPORTING
it_fieldcatalog = lt_alv_cat
IMPORTING
ep_table = d_ref.
*指定生成的内表到字段符号
ASSIGN d_ref->* TO <dyn_table>.
*创建动态工作区结构
CREATE DATA dyn_wa LIKE LINE OF <dyn_table>.
*创建动态工作区
ASSIGN dyn_wa->* TO <dyn_wa>.
*从动态表中取数到动态内表中
SELECT * INTO CORRESPONDING FIELDS OF TABLE <dyn_table> FROM (ls_tname-tabname) CLIENT SPECIFIED
WHERE mandt = p_mandt1.
LOOP AT <dyn_table> ASSIGNING <dyn_wa>.
ASSIGN COMPONENT 'MANDT' OF STRUCTURE <dyn_wa> TO <fs_str>.
<fs_str> = p_mandt2.
* append <dyn_wa> to <dyn_table>.
ENDLOOP.
MODIFY (ls_tname-tabname) CLIENT SPECIFIED FROM TABLE <dyn_table>.
IF sy-subrc = 0.
WRITE:/ ls_tname-tabname , ' copy successfully'.
ENDIF.
CLEAR: ls_tname,lt_table,ls_table,lt_alv_cat,ls_alv_cat.
free d_ref.
ENDLOOP.
标签:lt,alv,ABAP,Client,ls,tname,table,拷贝,TYPE
From: https://blog.51cto.com/u_8215601/7508986