Wednesday, 13 July 2016

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




Steps:

  • Go to Transaction code SE24.



  • Enter the Object type as class name start's with YCL or ZCL<class name> and click on create button.





  • Pop-up will appear.
  • Enter the short description and click on the SAVE button.

  • Save it in either Package or Local Package name.



  • Initial Class Interface screen looks like.



  • Enter the method name.
  • Click on Level.
  • Click on F4 help.
  • Select the instance type.
  • Click on Visibility .
  • Press on F4 help.
  • Select the visibility.
  • Enter the description.
  • Similarly create different methods depends on Level and Visibility.


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.

  • Double click on M1 method.
  • Implement the method M1.
  • Click on Save and Click on back button.
  • Double click on M2 method.
  • Implement the method M2.

  • Click on Save and click on the back button.
  • Double click on M3 method.
  • Implement the method M3.
  • Click on Save and Click on back button.
  • Double click on M4 method.
  • Implement the method M4.

  • Click on Save and Click on back button.
  • Double click on M5 method.


   

  • Implement the method M5.

  • Click on Save and Click on back button.
  • Double click on M6 method.
     
  • Implement the method M6.
  • Click on Save and Click on back button.


  • Save -> Check -> Activate.



To known Visibility of the methods

  • Go to transaction code : SE38.
  • Enter the program name which start's with Y or Z<program name > and click on create button.
  • Enter the title.
  • Select the attribute type as : Executable program.
  • Click on Save button.
  • Save it in either Local Package or Package.
  • Declare the object.
  • Create the object.
  • We can call Global  method , click on pattern.

  • Pop-up will appear.

  • Click on  "ABAP object pattern" radio button.
  • Pop-up will appear.
  • Enter the Instance as Object name.
  • Enter the class name.
  • Select the method.
  • Click on Okay.
  • Code looks like,
  • Also , we can call static methods using class name itself.

Source code

DATA : OBJ TYPE REF TO ZCL_CLASS_METHOD.

START-OF-SELECTION.

CREATE OBJECT OBJ.

CALL METHOD OBJ->M1
    .
CALL METHOD ZCL_CLASS_METHOD=>M2.

  • Save->Check -> Activate.

  • Click on Execute ( F8).

Output




No comments:

Post a Comment