REPORT zr_class_02.
*----------------------------------------------------------------------*
* CLASS lcl_car DEFINITION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS lcl_car DEFINITION.
PUBLIC SECTION.
METHODS set_car IMPORTING im_model TYPE string
im_make TYPE string.
METHODS get_car EXPORTING ex_model TYPE string
ex_make TYPE string.
PRIVATE SECTION.
DATA: model TYPE string,
make TYPE string.
ENDCLASS. "lcl_car DEFINITION
*----------------------------------------------------------------------*
* CLASS lcl_car IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS lcl_car IMPLEMENTATION.
METHOD set_car.
model = im_model.
make = im_make.
ENDMETHOD. "set_car
METHOD get_car.
ex_model = model.
ex_make = make.
ENDMETHOD. "get_car
ENDCLASS. "lcl_car IMPLEMENTATION
START-OF-SELECTION.
DATA: r_car01 TYPE REF TO lcl_car,
r_car02 TYPE REF TO lcl_car.
DATA: gv_model TYPE string,
gv_make TYPE string.
CREATE OBJECT r_car01.
r_car01->set_car( EXPORTING im_model = 'SM7'
im_make = '2009' ).
r_car01->get_car( IMPORTING ex_model = gv_model
ex_make = gv_make ).
WRITE:/ gv_model, gv_make.
r_car02 = r_car01. "casging
CREATE OBJECT r_car01. " r_car01 below new object indicate
r_car01->set_car( EXPORTING im_model = 'SM5'
im_make = '2010' ).
r_car01->get_car( IMPORTING ex_model = gv_model
ex_make = gv_make ).
WRITE:/ gv_model, gv_make.
r_car02 = r_car01. "casging
여기서의 casting 에 의미는 instance 의 복사 정도로 이해 하면 될 듯 합니다.
위 프로그램 예는 r_car01 을 r_car02 로 복사후 새로 r_car01 을 지정하여
기존의 r_car01 과 새로운 r_car01 을 만드는 예 입니다.
참고하세요.