首页 > 其他 > 详细

ABAP-Dynamic-Internal table

时间:2021-06-30 20:57:53      阅读:21      评论:0      收藏:0      [点我收藏+]
技术分享图片
data:
      lr_any_t  type ref to data,
      lr_any_s  type ref to data.
    data:
      lr_dref   type ref to data,
      lr_stru   type ref to cl_abap_structdescr,
      lr_table  type ref to cl_abap_tabledescr,
      lr_elem   type ref to cl_abap_elemdescr,
      lt_para   type cl_abap_structdescr=>component_table,
      lt_comp   type cl_abap_structdescr=>component_table.
    field-symbols:
      <fs_tab>  type any,
      <ft_tab>  type standard table.

    try.

      lr_stru ?= cl_abap_tabledescr=>describe_by_data( it_any ).

      loop at lr_stru->components[] into data(ls_comps).
        if ls_comps-type_kind = P
        or ls_comps-type_kind = X.
        else.
          ls_comps-length = ls_comps-length / 2.
        endif.

        append initial line to lt_comp assigning field-symbol(<fs_comp>).
        <fs_comp>-name  =   ls_comps-name.
        <fs_comp>-type  ?=  cl_abap_elemdescr=>get_by_kind(
                            p_type_kind = ls_comps-type_kind
                            p_length = ls_comps-length
                            p_decimals = ls_comps-decimals ).
        unassign <fs_comp>.
      endloop.

      if lt_comp[] is not initial.
        clear:lr_stru,lr_table.
        lr_stru   =   cl_abap_structdescr=>create( lt_comp ).
        lr_table  =   cl_abap_tabledescr=>create( lr_stru ).

        create data lr_any_s type handle lr_stru.
        assign lr_any_s->* to <fs_tab>.

        create data lr_any_t type handle lr_table.
        assign lr_any_t->* to <ft_tab>.
      endif.

      move-corresponding it_any to <ft_tab>[].

      catch cx_root into data(lr_rt).
      data(lv_txt) = lr_rt->get_text( ).
      raise exception type zcx_root
        exporting
          textid = value #(
                     msgid = 00
                     msgno = 001
                     attr1 = lv_txt
                     ).
    endtry.
View Code

 

ABAP-Dynamic-Internal table

原文:https://www.cnblogs.com/datie/p/14955388.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!