获取 ABAP 对象的标识号



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

{O:9*CLASS=CL_SOMETHING}

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

我没有办法使用RTTI来获取这些信息,有什么建议吗?

据我所知,您无法访问该内部对象标识符。调试器使用一些普通用户无法访问的专用内核接口。你可以试试这样的东西:

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

我实际上找到了一种(内部)方法来在对象服务CL_OS_CA_COMMON=>OS_GET_INTERNAL_OID_BY_REF:中获取对象的内部ID

CALL 'OBJMGR_GET_INFO' ID 'OPNAME' FIELD 'GET_OBJID'
                       ID 'OBJID'  FIELD integer_oid
                       ID 'OBJ'    FIELD ref_to_object.

是的,这是内部的东西。。。使用风险自负。

相关内容

  • 没有找到相关文章

最新更新