gpt4 book ai didi

oop - 获取 ABAP 对象的标识号

转载 作者:行者123 更新时间:2023-12-01 02:21:14 25 4
gpt4 key购买 nike

在调试器中检查对象实例时,它将像这样打印:

{O:9*CLASS=CL_SOMETHING}

是否可以从给定的对象引用中检索该类的标识号 9?
我想区分同一类的多个实例并打印它们的实例号。

我发现无法使用 RTTI 获取该信息,有什么建议吗?

最佳答案

据我所知,您无法访问该内部对象标识符。调试器使用一些私有(private)内核接口(interface)来完成普通用户无法访问的操作。你可以尝试这样的事情:

CLASS lcl_object_id_map DEFINITION.

PUBLIC SECTION.
METHODS get_id
IMPORTING ir_object TYPE REF TO object
RETURNING value(r_id) TYPE sysuuid_c.

PRIVATE SECTION.

TYPES: BEGIN OF t_object_id,
object TYPE REF TO object,
id TYPE sysuuid_c,
END OF t_object_id,
tt_object_id_map TYPE HASHED TABLE OF t_object_id
WITH UNIQUE KEY object.

DATA gt_object_id_map TYPE tt_object_id_map.

ENDCLASS. "lcl_object_id_map DEFINITION

*----------------------------------------------------------------------*

CLASS lcl_object_id_map IMPLEMENTATION.

METHOD get_id.

DATA: ls_entry TYPE t_object_id.
FIELD-SYMBOLS: <ls_entry> TYPE t_object_id.

READ TABLE gt_object_id_map
ASSIGNING <ls_entry>
WITH KEY object = ir_object.
IF sy-subrc <> 0.
ls_entry-object = ir_object.
ls_entry-id = cl_system_uuid=>create_uuid_c32_static( ).
INSERT ls_entry INTO TABLE gt_object_id_map ASSIGNING <ls_entry>.
ENDIF.
r_id = ls_entry-id.

ENDMETHOD. "get_id

ENDCLASS. "lcl_object_id_map IMPLEMENTATION

关于oop - 获取 ABAP 对象的标识号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20383307/

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