最近老忘备注下,动态内表传参。

 1     data:
 2       lr_any_t  type ref to data,
 3       lr_any_s  type ref to data.
 4     data:
 5       lr_dref   type ref to data,
 6       lr_stru   type ref to cl_abap_structdescr,
 7       lr_table  type ref to cl_abap_tabledescr,
 8       lr_elem   type ref to cl_abap_elemdescr,
 9       lt_para   type cl_abap_structdescr=>component_table,
10       lt_comp   type cl_abap_structdescr=>component_table.
11     field-symbols:
12       <fs_tab>  type any,
13       <ft_tab>  type standard table.
14 
15     try.
16 
17       lr_stru ?= cl_abap_tabledescr=>describe_by_data( it_any ).
18 
19       loop at lr_stru->components[] into data(ls_comps).
20         if ls_comps-type_kind = 'P'
21         or ls_comps-type_kind = 'X'.
22         else.
23           ls_comps-length = ls_comps-length / 2.
24         endif.
25 
26         append initial line to lt_comp assigning field-symbol(<fs_comp>).
27         <fs_comp>-name  =   ls_comps-name.
28         <fs_comp>-type  ?=  cl_abap_elemdescr=>get_by_kind(
29                             p_type_kind = ls_comps-type_kind
30                             p_length = ls_comps-length
31                             p_decimals = ls_comps-decimals ).
32         unassign <fs_comp>.
33       endloop.
34 
35       if lt_comp[] is not initial.
36         clear:lr_stru,lr_table.
37         lr_stru   =   cl_abap_structdescr=>create( lt_comp ).
38         lr_table  =   cl_abap_tabledescr=>create( lr_stru ).
39 
40         create data lr_any_s type handle lr_stru.
41         assign lr_any_s->* to <fs_tab>.
42 
43         create data lr_any_t type handle lr_table.
44         assign lr_any_t->* to <ft_tab>.
45       endif.
46 
47       move-corresponding it_any to <ft_tab>[].
48 
49       catch cx_root into data(lr_rt).
50       data(lv_txt) = lr_rt->get_text( ).
51       raise exception type zcx_root
52         exporting
53           textid = value #(
54                      msgid = '00'
55                      msgno = '001'
56                      attr1 = lv_txt
57                      ).
58     endtry.

 

posted on 2021-04-15 17:34  ricoo  阅读(108)  评论(0编辑  收藏  举报