Frage

when inspecting an object-instance in the debugger, it will be printed like this:

{O:9*CLASS=CL_SOMETHING}

Is it possible to retrieve that class' identity-number 9 from a given object reference? I want to distinguish multiple instances of the same class and print their instance-number.

I found no way using the RTTI to get that information, any advice?

War es hilfreich?

Lösung 2

I actually found an (internal) way to get the object's internal ID in the Object Services CL_OS_CA_COMMON=>OS_GET_INTERNAL_OID_BY_REF:

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

Yes, this is internal stuff... Use at own risk.

Andere Tipps

As far as I know, you can't access that internal object identifier. The debugger uses some private kernel interface to do so that is not accessible to the ordinary user. You could try something like this:

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
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top