0% found this document useful (0 votes)
4 views2 pages

Attributes Example

The document outlines the implementation of a report in ABAP that defines a class with instance and static attributes, as well as constants. It demonstrates how to create instances of the class and access its attributes using object references. The report includes examples of accessing both instance and static attributes, along with constants, through different object instances.

Uploaded by

kishancp
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views2 pages

Attributes Example

The document outlines the implementation of a report in ABAP that defines a class with instance and static attributes, as well as constants. It demonstrates how to create instances of the class and access its attributes using object references. The report includes examples of accessing both instance and static attributes, along with constants, through different object instances.

Uploaded by

kishancp
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

*&---------------------------------------------------------------------*

*& Report ZSAP_TRAINING_CLASS_ATTRIBUTES


*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT zsap_training_class_attributes.

"1. definition
"2. Implementation
"3. Creating the instance of the class
"4. Access the variable/methods using the instance/class

CLASS lcl_abc DEFINITION.

PUBLIC SECTION.
TYPES ty1 TYPE i.

DATA lv1 TYPE i." instance attribute


DATA lv3 TYPE ty1.
CLASS-DATA lv2 TYPE i. " static attribute
CLASS-DATA lv4 TYPE ty1. " static attribute
CONSTANTS lc1 TYPE i VALUE 50. "constant

PROTECTED SECTION.

PRIVATE SECTION.

ENDCLASS.

ULINE.
FORMAT COLOR 1.

WRITE:/ 'Access the instance attribute using class name'.

*write:/ lcl_abc->lv1.
*write:/ lcl_abc=>lv1.

WRITE:/ 'Access the static attribute, constant using class name'.


WRITE:/ lcl_abc=>lv2.
WRITE:/ lcl_abc=>lc1.

DATA obj1 TYPE REF TO lcl_abc.


CREATE OBJECT obj1.
obj1->lv1 = 100. "instance attribute
obj1->lv2 = 200. " static attribute
*obj1->lc1 = 300 . "constant " syntax error

WRITE:/ 'Access the all the attributes using onject reference'.


WRITE:/ obj1->lv1. "instance attribute "100
WRITE:/ obj1->lv2. " static attribute "200
WRITE:/ obj1->lc1. "constant "50
WRITE:/ obj1->lv3.

DATA obj2 TYPE REF TO lcl_abc.


CREATE OBJECT obj2.

ULINE.
FORMAT COLOR 3.
WRITE:/ 'Access the all the attributes using onject reference for obj2'.
obj2->lv1 = 500.
WRITE:/ obj2->lv1. "instance attribute
WRITE:/ obj2->lv2. " static attribute
WRITE:/ obj2->lc1. "constant

DATA(obj3) = NEW lcl_abc( ).


FORMAT COLOR 3.
WRITE:/ 'Access the all the attributes using onject reference for obj3'.

obj3->lv1 = 500.
obj3->lv2 = 1000.
WRITE:/ obj3->lv1. "instance attribute " 500
WRITE:/ obj3->lv2. " static attribute "1000
WRITE:/ obj3->lc1. "constant 50

FORMAT COLOR 3.
WRITE:/ 'Access the all the attributes using onject reference for obj3'.

WRITE:/ obj1->lv1. "instance attribute "100


WRITE:/ obj1->lv2. " static attribute "1000
WRITE:/ obj1->lc1. "constant"50

FORMAT COLOR 3.
WRITE:/ 'Access the all the attributes from the global classzcl_attributes'.

*WRITE:/ ZCL_ATTRIBUTE->mv1. "instance attribute " syntax error


*WRITE:/ ZCL_ATTRIBUTE=>mv1. " instance attribute "syntax error
ZCL_ATTRIBUTE=>mv2 = 2500. "static attributes
WRITE:/ ZCL_ATTRIBUTE=>mv2. "static attribute
WRITE:/ ZCL_ATTRIBUTE=>mc1. " constant attribute

data(obj4) = new zcl_attribute( ).

WRITE:/ 'Access the all the attributes from the global classzcl_attributes after
creation of obj4'.
obj4->mv1 = 3500.
obj4->mv2 = 4500.

WRITE:/ obj4->mv1. "istance attrinute


write:/ obj4->mv2. " stati attribute
WRITE:/ obj4->mc1. "constant"50

You might also like