Global data is accessible from any class in a program. We
know that the visibility depends on the public, protected or private section.
The globally declared variable is visible from anywhere in the program. We have
created a program where the global variable is v_globe and in the debugging
mode we can see its value from any of classes.
REPORT zsr_test NO STANDARD PAGE
HEADING.
DATA: v_globe TYPE char40 VALUE 'This is Global Data'.
*----------------------------------------------------------------------*
* CLASS cls1 DEFINITION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS cls1 DEFINITION.
PUBLIC SECTION.
DATA v_pub_1 TYPE char40 VALUE 'Class 1 public data'.
METHODS m_cls1.
PROTECTED SECTION.
DATA v_pro_1 TYPE char40 VALUE 'Class 1 protected data'.
PRIVATE SECTION.
DATA v_pri_1 TYPE char40 VALUE 'Class 1 private data'.
ENDCLASS. "cls1 DEFINITION
*----------------------------------------------------------------------*
* CLASS cls2 DEFINITION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS cls2 DEFINITION.
PUBLIC SECTION.
DATA v_pub_2 TYPE char40 VALUE 'Class 2 public data'.
METHODS m_cls2.
PROTECTED SECTION.
DATA v_pro_2 TYPE char40 VALUE 'Class 2 protected data'.
PRIVATE SECTION.
DATA v_pri_2 TYPE char40 VALUE 'Class 2 private data'.
ENDCLASS. "cls2 DEFINITION
*----------------------------------------------------------------------*
* CLASS cls1 IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS cls1 IMPLEMENTATION.
METHOD m_cls1.
WRITE: / v_pub_1,
/ v_pro_1,
/ v_pri_1.
ENDMETHOD. "m_cls1
ENDCLASS. "cls1 IMPLEMENTATION
*----------------------------------------------------------------------*
* CLASS cls2 IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS cls2 IMPLEMENTATION.
METHOD m_cls2.
WRITE: / v_pub_2,
/ v_pro_2,
/ v_pri_2.
ENDMETHOD. "m_cls2
ENDCLASS. "cls2 IMPLEMENTATION
START-OF-SELECTION.
DATA: obj1 TYPE REF TO cls1,
obj2 TYPE REF TO cls2.
CREATE OBJECT: obj1, obj2.
CALL METHOD: obj1->m_cls1,
obj2->m_cls2.
DATA: v_globe TYPE char40 VALUE 'This is Global Data'.
*----------------------------------------------------------------------*
* CLASS cls1 DEFINITION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS cls1 DEFINITION.
PUBLIC SECTION.
DATA v_pub_1 TYPE char40 VALUE 'Class 1 public data'.
METHODS m_cls1.
PROTECTED SECTION.
DATA v_pro_1 TYPE char40 VALUE 'Class 1 protected data'.
PRIVATE SECTION.
DATA v_pri_1 TYPE char40 VALUE 'Class 1 private data'.
ENDCLASS. "cls1 DEFINITION
*----------------------------------------------------------------------*
* CLASS cls2 DEFINITION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS cls2 DEFINITION.
PUBLIC SECTION.
DATA v_pub_2 TYPE char40 VALUE 'Class 2 public data'.
METHODS m_cls2.
PROTECTED SECTION.
DATA v_pro_2 TYPE char40 VALUE 'Class 2 protected data'.
PRIVATE SECTION.
DATA v_pri_2 TYPE char40 VALUE 'Class 2 private data'.
ENDCLASS. "cls2 DEFINITION
*----------------------------------------------------------------------*
* CLASS cls1 IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS cls1 IMPLEMENTATION.
METHOD m_cls1.
WRITE: / v_pub_1,
/ v_pro_1,
/ v_pri_1.
ENDMETHOD. "m_cls1
ENDCLASS. "cls1 IMPLEMENTATION
*----------------------------------------------------------------------*
* CLASS cls2 IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS cls2 IMPLEMENTATION.
METHOD m_cls2.
WRITE: / v_pub_2,
/ v_pro_2,
/ v_pri_2.
ENDMETHOD. "m_cls2
ENDCLASS. "cls2 IMPLEMENTATION
START-OF-SELECTION.
DATA: obj1 TYPE REF TO cls1,
obj2 TYPE REF TO cls2.
CREATE OBJECT: obj1, obj2.
CALL METHOD: obj1->m_cls1,
obj2->m_cls2.
Now we have set the debugger at the CALL METHOD. The method of first class can access public, protected & private variables and the global variable from that first class implementation.
Similarly when the program enters to the second class implementation, the method can access all variables of that class and the global variable.
When the program is not under any class then also global variable can be accessed.
The output is as follows.
4 comments:
really nice post thanks
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!!!!!!
Best SAP Success Factors Training Institute in Chennai
Best SAP MM Training in Chennai
Best SAP SD Training in Chennai
Best SAP ABAP Training in Chennai
Best SAP FICO Training in Chennai
Best SAP BASIS Training in Chennai
http://thecreatingexperts.com/sap-successfactors-training-in-chennai/
http://thecreatingexperts.com/sap-mm-training-in-chennai/
http://thecreatingexperts.com/sap-sd-training-in-chennai/
http://thecreatingexperts.com/sap-hr-training-in-chennai/
http://thecreatingexperts.com/sap-fico-training-in-chennai/
http://thecreatingexperts.com/sap-abap-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!!!!!!
Thanks for sharing. I hope it will be helpful for too many people that are searching for this topic.sap hr training
Post a Comment