[SAP ABAP] 클래스(Class) 생성 및 구현 2, 생성자

2013. 5. 27. 23:30SAP ERP System/ABAP 실습

 이번시간에는 [SAP ABAP] 클래스(Class) 생성 및 구현 2, 생성자 에 대해서 알아보겠습니다.

 

*&---------------------------------------------------------------------*
*& Report  ZR_CLASS_03
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT  ZR_CLASS_03.

*----------------------------------------------------------------------*
*       CLASS lcl_car DEFINITION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
class lcl_car DEFINITION.
  PUBLIC SECTION.
    methods get_car EXPORTING ex_model TYPE string
                                                  ex_make TYPE string.

    methods constructor IMPORTING im_model type string
                                                        im_make type string.
  PRIVATE SECTION.
    data: model TYPE string,
            make TYPE string.
    METHODS set_car IMPORTING im_model TYPE string
                                                    im_make TYPE string.
ENDCLASS.                    "lcl_car DEFINITION



*----------------------------------------------------------------------*
*       CLASS lcl_car IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
class lcl_car IMPLEMENTATION.
  method constructor.
    me->set_carEXPORTING im_model im_model
                                             im_make im_make ).
    ENDMETHOD.

    METHOD get_car.
      ex_model me->model.
      ex_make make.
    ENDMETHOD.                    "get_car

    METHOD set_car.
      me->model im_model.
      me->make im_make.
    ENDMETHOD.                    "set_car
  ENDCLASS.                    "lcl_car IMPLEMENTATION

START-OF-SELECTION.
  data: r_car type REF TO lcl_car,
        r_tab type TABLE OF REF TO lcl_car,
        gv_model TYPE string,
        gv_make TYPE string.


  CREATE OBJECT r_car EXPORTING im_model 'SM7'
                                                          im_make '2009'.

  APPEND r_car to r_tab.

  CREATE OBJECT r_car EXPORTING im_model 'SM5'
                                                          im_make '2010'.


APPEND r_car to r_tab.

  r_car->get_carIMPORTING ex_model gv_model
                                               ex_make gv_make ).

*LOOP AT r_tab TO r_car


  WRITE : gv_model, gv_make.

 

 이번시간에는 [SAP ABAP] 클래스(Class) 생성 및 구현 2, 생성자 에 대해서 알아보았습니다.

 

1 2 3 4 5 6