gpt4 book ai didi

oop - 如何根据对象属性创建内部表?

转载 作者:行者123 更新时间:2023-12-01 05:25:31 26 4
gpt4 key购买 nike

我正在尝试基于实例创建排序表。
下面是我的编码:

CLASS my_fancy_pony DEFINITION.
PUBLIC SECTION.
DATA mv_nice_key TYPE i.
ENDCLASS.

CLASS my_fancy_pony IMPLEMENTATION.
ENDCLASS.


DATA lt_my_fancy_ponys TYPE SORTED TABLE OF REF TO my_fancy_pony WITH UNIQUE KEY mv_nice_key.
DATA lt_my_fancy_ponys TYPE SORTED TABLE OF REF TO my_fancy_pony WITH UNIQUE KEY table_line->mv_nice_key.
这没有通过语法检查。
你能告诉我如何做到这一点吗?

最佳答案

您不能直接将类用作结构。

但是,您可以构建一个满足您需要的 map :

TYPES:
BEGIN OF map_entry,
mv_nice_key TYPE i,
ref_to_object TYPE REF TO my_fancy_pony,
END OF map_entry.

TYPES map_type TYPE SORTED TABLE OF map_entry WITH UNIQUE KEY mv_nice_key.

DATA(lt_my_fancy_pony_map) = VALUE map_type(
FOR each IN lt_my_fancy_ponys
( mv_nice_key = each->mv_nice_key
ref_to_object = each ) ).

map 可以为您需要的任何类的属性编号:
TYPES:
BEGIN OF map_entry,
mv_nice_key TYPE i,
some_other_att TYPE i,
" ...
ref_to_object TYPE REF TO my_fancy_pony,
END OF map_entry.

TYPES map_type TYPE SORTED TABLE OF map_entry WITH NON-UNIQUE KEY table_line.

DATA(lt_my_fancy_pony_map) = VALUE map_type(
FOR each IN lt_my_fancy_ponys
( mv_nice_key = each->mv_nice_key
some_other_att = each->some_other_att
" ...
ref_to_object = each ) ).

关于oop - 如何根据对象属性创建内部表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61251606/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com