Monday, 19 September 2016

Local Class : Friends

Ex :-


Steps :-

  • Go to Transaction Code SE38.
  • Enter the program name start's with Y or Z< program name > and click on Create.

Source Code



CLASS A DEFINITION DEFERRED.


CLASS B DEFINITION FRIENDS A.

  PROTECTED SECTION.

  DATA : V_PRO TYPE CHAR50.


  PRIVATE SECTION.

   DATA : V_PRI TYPE CHAR50.

  METHODS : M_CLASS.

ENDCLASS.


CLASS B IMPLEMENTATION.


  METHOD M_CLASS.



    V_PRO = 'PROTECTED DATA'.
    V_PRI = 'PRIVATE DATA'.

    WRITE : / 'PRIVATE METHOD: ' , / V_PRO , / V_PRI.
    SKIP.
   ENDMETHOD.
 ENDCLASS.

 CLASS A DEFINITION.

   PUBLIC SECTION.

   METHODS : FETCH.

 ENDCLASS.

 CLASS A IMPLEMENTATION.

   METHOD FETCH.

     DATA : OJ_B TYPE REF TO B.

     CREATE OBJECT OJ_B .

     CALL METHOD OJ_B->M_CLASS.

     SKIP 2.

     OJ_B->V_PRO = 'PROTECTED DATA ACCESSED BY B'.
     OJ_B->V_PRI =  'PRIVATE DATA ACCESSED BY B'.

     WRITE : / 'ACCESS BY B'.

     WRITE : / OJ_B->V_PRO,
              /  OJ_B->V_PRI.

   ENDMETHOD.

  ENDCLASS.


  DATA : OBJ TYPE REF TO A.

  START-OF-SELECTION.

  CREATE OBJECT OBJ.

  CALL METHOD OBJ->FETCH.



  • Save -> Check -> Activate.

Output

  • Click on Execute( F8 ).


No comments:

Post a Comment