Tach.Anonymous hat geschrieben:Die Instanz im Klassenkonstruktor der Klasse erzeugen und per Exportingparameter diese Instanz exportieren.
Instanzkonstruktor wird nur beim Alleresten Aufruf der Klasse durchlaufen daher bekommt man nur eine Instanz.
mfg abapstrizi
Hi Haubi,Haubi hat geschrieben: Gefragt ist ein "systemweiter Singleton"
Code: Alles auswählen.
DATA: LO_PROXY_AREA TYPE REF TO ZCL_PROXY_AREA.
DATA: LX_ERROR TYPE REF TO CX_ROOT.
TRY.
LO_PROXY_AREA = ZCL_PROXY_AREA=>ATTACH_FOR_READ( ).
LO_PROXY_AREA->ROOT->SET_INSTANCE( ).
LO_PROXY_AREA->DETACH( ).
CATCH CX_SHM_ATTACH_ERROR INTO LX_ERROR.
ENDTRY.
Code: Alles auswählen.
DATA:
lr_area TYPE REF TO zcl_area,
lr_root TYPE REF TO zcl_root,
lr_except TYPE REF TO cx_shm_error.
CLEAR lr_area.
TRY.
lr_area = zcl_area=>attach_for_read( ).
CATCH cx_shm_inconsistent INTO lr_except.
TRY.
zcl_area=>invalidate_area( ).
CATCH cx_shm_error INTO lr_except.
ENDTRY.
CATCH cx_shm_error INTO lr_except.
ENDTRY.
IF lr_area IS BOUND AND lr_area->root IS BOUND
AND lr_area->is_valid( ) EQ abap_true.
* Verarbeitung mit dem Objekt durchführen
TRY.
lr_area->detach( ).
CATCH cx_shm_error INTO lr_except.
ENDTRY.
CLEAR lr_area.
ELSE.
IF ( lr_area IS BOUND AND lr_area->root IS BOUND ).
TRY.
lr_area->detach( ).
CATCH cx_shm_error INTO lr_except.
ENDTRY.
ENDIF.
CLEAR lr_area.
TRY.
lr_area = zcl_area=>attach_for_write( ).
CATCH cx_shm_error INTO lr_except.
RAISE EXCEPTION TYPE cx_shm_build_failed
EXPORTING
previous = lr_except.
ENDTRY.
CREATE OBJECT lr_root AREA HANDLE lr_area.
lr_area->set_root( lr_root ).
* Objekt mit Daten befüllen
* Verarbeitung mit dem Objekt durchführen.
TRY.
lr_area->detach_commit( ).
CATCH cx_shm_error INTO lr_except.
RAISE EXCEPTION TYPE cx_shm_build_failed
EXPORTING
previous = lr_except.
ENDTRY.
CALL FUNCTION 'DB_COMMIT'.
ENDIF.
Code: Alles auswählen.
REPORT z_persistent.
DATA: agent TYPE REF TO zca_persistent,
connection TYPE REF TO zcl_persistent,
lr_ref TYPE REF TO ZCL_NO_PERSISTENT_CLASS. "Soll später eine Proxy-Klasse referenzieren
DATA lv_object TYPE REF TO object.
*
DATA: exc TYPE REF TO cx_root.
DATA: lv_text TYPE char40.
*
agent = zca_persistent=>agent.
TRY .
CALL METHOD agent->create_transient
RECEIVING
result = connection.
TRY .
DO 5 TIMES.
IF NOT lr_ref IS BOUND.
connection->set_gr_ref( lr_ref ).
CALL METHOD connection->get_gr_ref
RECEIVING
result = lr_ref.
CALL METHOD lr_ref->instantieted
RECEIVING
ev_result = lv_text.
* LOG-POINT ID z_persistent FIELDS lv_text.
ENDIF.
ENDDO.
CATCH cx_os_object_not_found INTO exc.
ENDTRY.
CATCH cx_os_object_existing INTO exc.
ENDTRY.