Tuesday, December 27, 2011

sample code for Class within implementation of another class



*&---------------------------------------------------------------------*
*& Report  YSAP_CLASS_IN_CLASS_IMP
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT  yrsap_class_in_class_imp.


*----------------------------------------------------------------------*
*       CLASS class1 DEFINITION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS class1 DEFINITION.
  PUBLIC SECTION.
    METHODS method1.
ENDCLASS.                    "class1 DEFINITION

*----------------------------------------------------------------------*
*       CLASS class2 DEFINITION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS class2 DEFINITION.
  PUBLIC SECTION.
    METHODS method2.
ENDCLASS.                    "class2 DEFINITION

*----------------------------------------------------------------------*
*       CLASS class1 IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS class1 IMPLEMENTATION.
  METHOD method1.
    DATA: num TYPE i VALUE '5'.
    do 3 times.
      num = num * 2.
         WRITE: num.
      enddo.
  ENDMETHOD.                                                "method1
ENDCLASS.                    "class1 IMPLEMENTATION

class class2 IMPLEMENTATION.
  method method2.
  data: object1 type ref to class1.
  create object: object1.
  call method object1->method1.
  endmethod.
  endclass.

  START-OF-SELECTION.

  data: object2 type ref to class2.

  create object: object2.

  call method object2->method2.

OUTPUT:

No comments:

Post a Comment