I think in WM or EWM, if you think “singleton” it often is not right, as we don’t want
“one instance per system”
but
“one instance per LGNUM per system” -> Multiton!
Here is an example:
Okumaya devam et...
“one instance per system”
but
“one instance per LGNUM per system” -> Multiton!
Here is an example:
Kod:
CLASS zcl_example DEFINITION
PUBLIC
FINAL
CREATE PRIVATE.
PUBLIC SECTION.
CLASS-METHODS: get_instance IMPORTING iv_lgnum TYPE /scwm/lgnum
RETURNING VALUE(rref_instance) TYPE REF TO zcl_example.
PROTECTED SECTION.
PRIVATE SECTION.
TYPES: BEGIN OF gty_instance_buffer,
lgnum TYPE /scwm/lgnum,
instance TYPE REF TO zcl_example,
END OF gty_instance_buffer.
CLASS-DATA: st_instance_buffer TYPE HASHED TABLE OF gty_instance_buffer WITH UNIQUE KEY lgnum.
METHODS constructor IMPORTING iv_lgnum TYPE /scwm/lgnum.
DATA: mv_lgnum TYPE /scwm/lgnum.
ENDCLASS.
CLASS zcl_example IMPLEMENTATION.
METHOD constructor.
me->mv_lgnum = iv_lgnum.
ENDMETHOD.
METHOD get_instance.
READ TABLE st_instance_buffer WITH TABLE KEY lgnum = iv_lgnum
ASSIGNING FIELD-SYMBOL(<lfs_instance>).
IF sy-subrc EQ 0.
rref_instance = <lfs_instance>-instance.
ELSE.
rref_instance = NEW zcl_example( iv_lgnum = iv_lgnum ).
INSERT VALUE #( lgnum = iv_lgnum instance = rref_instance ) INTO TABLE st_instance_buffer.
ENDIF.
ENDMETHOD.
ENDCLASS.
Okumaya devam et...