动态内表实例

****************** hardcoded "old style" local type*******************
* This is a normal hardcoded local type
TYPES : BEGIN OF TYP_HARDCODED,
      L_COUNT TYPE I,
      LT_SFLIGHT TYPE SFLIGHT.
TYPES : END OF TYP_HARDCODED.
* create a table based on hardcoded type
DATA : LT_HARDCODED TYPE TABLE OF TYP_HARDCODED.
****************** dynamic "new wave" local type *******************
TYPES: TYP_COUNT TYPE I.
FIELD-SYMBOLS : <LT_DYNAMIC> TYPE ANY TABLE.
DATA: DREF TYPE REF TO DATA,
  ITAB_TYPE TYPE REF TO CL_ABAP_TABLEDESCR,
  STRUCT_TYPE TYPE REF TO CL_ABAP_STRUCTDESCR,
  ELEM_TYPE TYPE REF TO CL_ABAP_ELEMDESCR,
  COMP_TAB TYPE CL_ABAP_STRUCTDESCR=>COMPONENT_TABLE,
  COMP_FLD TYPE CL_ABAP_STRUCTDESCR=>COMPONENT.
* We read information about each fields of SFLIGHT (see ABAP FAQ #2)
STRUCT_TYPE ?= CL_ABAP_TYPEDESCR=>DESCRIBE_BY_NAME( 'SFLIGHT' ).
* We also need the information about the type "typ_count", note that
* we should use class cl_abap_elemdescr instead of cl_abap_typedescr
ELEM_TYPE ?= CL_ABAP_ELEMDESCR=>DESCRIBE_BY_NAME( 'TYP_COUNT' ).
* we read all fleids of SFLIGHT and create a component table
COMP_TAB = STRUCT_TYPE->GET_COMPONENTS( ).
* We add manually the counter
COMP_FLD-NAME = 'L_COUNT'.
COMP_FLD-TYPE = ELEM_TYPE.
INSERT COMP_FLD INTO COMP_TAB INDEX 1.
* we create the structure
STRUCT_TYPE = CL_ABAP_STRUCTDESCR=>CREATE( COMP_TAB ).
* ... and the internal table
ITAB_TYPE = CL_ABAP_TABLEDESCR=>CREATE( STRUCT_TYPE ).
* The new thing here is the "type handle" which create a pointer to a handle
CREATE DATA DREF TYPE HANDLE ITAB_TYPE.
* we finally assign a field symbol to the pointer because we cannot directly access a pointer.
ASSIGN DREF->* TO <LT_DYNAMIC>.
* At the end of this small program, internal table lt_hardcoded and lt_dynamic are the same

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值