Monday, April 1, 2013

Interface Static Attribute and Method are Accessed Directly


Static attribute and method of Interface can be accessed directly in the data processing as of class. There is no need to create object for class.

Following program contains an interface where we have defined constants, static data and static method. The program contains a class which defines the interface and implements its method. Now in the start of selection we are valuing the class data directly by cls=>it~cls_var = 'Interface Data valued directly' statement and calling the method directly by call method cls=>it~cls_mit statement.

*&---------------------------------------------------------------------*
*& Report  ZSR_TEST
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT  zsr_test.

*----------------------------------------------------------------------*
*       INTERFACE it
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
INTERFACE it.
  CONSTANTS c_var TYPE char40 VALUE 'SAP ABAP Object Oriented'.
  CLASS-DATA cls_var TYPE char50.
  CLASS-METHODS cls_mit.
ENDINTERFACE.                    "it

*----------------------------------------------------------------------*
*       CLASS cls DEFINITION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS cls DEFINITION.
  PUBLIC SECTION.
    INTERFACES it.
ENDCLASS.                    "cls DEFINITION

*----------------------------------------------------------------------*
*       CLASS cls IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS cls IMPLEMENTATION.
  METHOD it~cls_mit.
    WRITE: / 'Interface Method',
           / it~cls_var,
           / it~c_var.
  ENDMETHOD.                    "it~cls_mit
ENDCLASS.                    "cls IMPLEMENTATION

START-OF-SELECTION.
  cls=>it~cls_var = 'Interface Data valued directly'.
  CALL METHOD cls=>it~cls_mit.


The output is below:


4 comments:

yektek training said...

nice post thanks for sharing from Swathi

siva sankar Sankar said...

excellent post thanks for sharing from Sankar

Bhavya Kumar said...

Thanks for the great information in your blog SAP Success FactorsTraining in Chennai

suganya said...

SAP Success Factors Real Time Hands on Training in Chennai…

Don’t always Depend on Training Institute alone.Please aware of Best Trainers too..

http://thecreatingexperts.com/sap-successfactors-training-in-chennai/

If You need a Best Trainer in SAP Success Factors??? Then be ready for a DEMO From the Trainer MR.Karthick
CONTACT:8122241286
http://thecreatingexperts.com/sap-mm-training-in-chennai/

Both Classroom/Online Training is Available!!!!!!