Wednesday, March 20, 2013

Static Method of Class

Static Method is the class method and it can access the static attributes and global attributes only. It cannot access any Instance attributes. When we declare a static method then we don't have to create any object to call that method. We can call a static method directly by the class where it has been declared. 

In the following example we have declared a static method in public section of a class. The method will need to access a variable which has been declared as static. The method can have the access of global variable as well. So we have declared a variable gv_time as global and a static variable cl_v_date in Public section of the class. Now the method has the access of those two variable and Write those as well.


REPORT  zsr_test NO STANDARD PAGE HEADING.

DATA gv_time TYPE sy-uzeit.
*----------------------------------------------------------------------*
*       CLASS cl_one DEFINITION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS cl_one DEFINITION.
  PUBLIC SECTION.
    DATA v_txt TYPE char40 VALUE 'SAP ABAP Object Oriented'.
    CLASS-DATA: cl_v_date TYPE sy-datum.
    CLASS-METHODS cl_m_one.
ENDCLASS.                    "cl_one DEFINITION

*----------------------------------------------------------------------*
*       CLASS cl_one IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS cl_one IMPLEMENTATION.
  METHOD cl_m_one.
    gv_time   = sy-uzeit.
    cl_v_date = sy-datum.
    WRITE: / 'Today''s date: ', cl_v_date,
           / 'Time: ', gv_time.
  ENDMETHOD.                    "cl_m_one
ENDCLASS.                    "cl_one IMPLEMENTATION

START-OF-SELECTION.
  CALL METHOD cl_one=>cl_m_one.

Now we shall investigate in debugging mode. Set the breakpoint at CALL METHOD. The system will enter into the method. There is no need to instantiate the class as the method is the class method / static method.


We can see here the static method doesn’t have access to the general public component v_txt. To get access of this component we need to declare a normal method. The output is as follows.

12 comments:

Cindy Dy said...


I am really impressed from this post! The person who created this post is a generous and knows how to keep the readers connected.Thank you. Please keep on posting.

Sol
www.gofastek.com

Manish Mendiratta said...

hi I have one doubt regarding static methods:
Which component of the class can access static method?
1.Types
2.constants
3.instance attribute
4.All Events.

Leslie Lim said...

I read your blog.I thought it was great.. Hope you have a great day. God bless.

Camille
www.imarksweb.org

sarah lee said...

I really enjoyed reading your article. I found this as an informative and interesting post, so i think it is very useful and knowledgeable. I would like to thank you for the effort you have made in writing this article.


edupdf.org

Bhavya Kumar said...

Best blog.Got to learn new things.Thanks for this Blog SAP Success Factors Training in Chennai

sanayamohit said...

SAP Success Factors Real Time Hands on Training in Chennai...

Don't always Depend on Training Institute Alone and so please aware of Best Trainers too..

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

If You need a Best Trainer over SAP Success Factors Means??? Please ready for an DEMO From the Trainer MR.Karthick
CONTACT:8122241286

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

Shruti Ramalingam said...

From My search…Creating Experts provides Best SAP Training with real time projects assistance.

Most of the modules are equipped with advance level topics which the student can learn from the basics to the advance level stage.

They also provide placement assistance in leading MNC companies across the globe according to the current requirements.

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

And these are the Best SAP training institute which provides Real Time Hands on Training…

codedion Technologies-9003085882

creating Experts-8122241286

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

Unknown said...



Best SAP Success Factors Training Institute in Chennai
http://thecreatingexperts.com/sap-successfactors-training-in-chennai/
Best SAP MM Training in Chennai
http://thecreatingexperts.com/sap-mm-training-in-chennai/
Best SAP SD Training in Chennai
http://thecreatingexperts.com/sap-sd-training-in-chennai/
http://thecreatingexperts.com/sap-hr-training-in-chennai/
Best SAP FICO Training in Chennai
http://thecreatingexperts.com/sap-fico-training-in-chennai/
Best SAP ABAP Training in Chennai
http://thecreatingexperts.com/sap-abap-training-in-chennai/
Best SAP BASIS Training in Chennai
http://thecreatingexperts.com/sap-basis-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!!!!!!

Keerthi Suresh 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!!!!!!

Camelliacanan said...

wow very well information you had shared here. This is important thing because when we are running a business first we have to make our focusing area and what we are ready for serve among the people. And really i am much inspired with this 10 steps. Surely it will be useful for craeting the better mindset among our business. Thank you and i am looking forward your more information here

SAP HR Training in Chennai

SAP SD Training in Chennai

SAP Basis Training in Chennai

sameera sam said...



It's so nice article thank you for sharing a valuable content
Sap Online Access

gilledashivani said...

Great information. the information provided is of great use as i got to learn new things. If you are looking for real time training in SAP ABAP, kindly contact sieve software
Sieve software offers real time training by industry experts with live projects and placement support.
SAP ABAP TRAINING IN HYDERABAD