Wednesday, 13 July 2016

Local Class creation and visibility of the class component-->Methods



Steps:

  • Enter the transaction code : SE38.
  • Enter the program name , start's with Y or Z<program name > and click on create.
  • Enter the Title,
  • Enter attribute Type as : Executable program.
  • Click on Save .




Note : 
  1. Instance methods are defined using  METHODS key word.
  2. Static  methods are defined using  CLASS-METHODS key word.
  • Class definition and declaration of methods as follows.


CLASS C1 DEFINITION.
  
  PUBLIC SECTION.
  METHODS : M1.
  CLASS-METHODS :M2.
  
  PROTECTED SECTION.
  
  METHODS : M3.
  CLASS-METHODS : M4.
  
  PRIVATE SECTION.
   METHODS : M5.
   
  CLASS-METHODS : M6.

ENDCLASS.



Note :
  1. M1 method is  known as instance public method.
  2. M2  method is  known as static public method.
  3. M3 method is  known as instance protected method.
  4. M4 method is  known as static protected method.
  5. M5 method is  known as instance private method.
  6. M6 method is  known as static private method.
  • Implement the methods.


CLASS C1 IMPLEMENTATION.
  
  METHOD M1.
    
    WRITE : / 'AM M1'.
  ENDMETHOD.
  
  
  METHOD M2.
    
    WRITE : / 'AM M2'.
  ENDMETHOD.
  
  METHOD M3.
    
    WRITE : / 'AM M3'.
  ENDMETHOD.
  
  
  METHOD M4.
    
    WRITE : / 'AM M4'.
  ENDMETHOD.
  
  
  METHOD M5.
    
    WRITE : / 'AM M5'.
  ENDMETHOD.
  
  
  METHOD M6.
    
    WRITE : / 'AM M6'.
  ENDMETHOD.
  
ENDCLASS.


  • Save -> Check -> Activate.

  • Local class is created.

Usage of Class.

Source code



CLASS C1 DEFINITION.

  PUBLIC SECTION.
  METHODS : M1.
  CLASS-METHODS :M2.

  PROTECTED SECTION.

  METHODS : M3.
  CLASS-METHODS : M4.

  PRIVATE SECTION.
   METHODS : M5.

  CLASS-METHODS : M6.

ENDCLASS.

CLASS C1 IMPLEMENTATION.

  METHOD M1.

    WRITE : / 'AM M1'.
  ENDMETHOD.


  METHOD M2.

    WRITE : / 'AM M2'.
  ENDMETHOD.

  METHOD M3.

    WRITE : / 'AM M3'.
  ENDMETHOD.


  METHOD M4.

    WRITE : / 'AM M4'.
  ENDMETHOD.


  METHOD M5.

    WRITE : / 'AM M5'.
  ENDMETHOD.


  METHOD M6.

    WRITE : / 'AM M6'.
  ENDMETHOD.

ENDCLASS.

DATA : OBJ   TYPE REF TO C1.

START-OF-SELECTION.

CREATE OBJECT OBJ.

CALL METHOD OBJ->M1.

CALL METHOD C1=>M2.

  • Save -> Check -> Activate.

  • Execute.


No comments:

Post a Comment