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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
8 | |
3 | |
3 | |
2 | |
2 | |
2 | |
2 | |
2 | |
2 | |
1 |