Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

ABAP Object sample prog

Former Member
0 Kudos

Hi All,

I am beginner of ABAP objects.

REPORT example.

----


  • CLASS counter DEFINITION

----


*

----


CLASS counter DEFINITION.

PUBLIC SECTION.

METHODS : set IMPORTING value(set_value) TYPE i,

increment,

get EXPORTING value(get_value) TYPE i.

PRIVATE SECTION.

DATA : count TYPE i.

ENDCLASS. "counter DEFINITION.

----


  • CLASS counter IMPLEMENTATION

----


*

----


CLASS counter IMPLEMENTATION.

METHOD set.

count = set_value.

ENDMETHOD. "set

METHOD increment.

count = count + 1.

ENDMETHOD. "increment

METHOD get.

get_value = count.

ENDMETHOD. "get

ENDCLASS. "counter IMPLEMENTATION

DATA cnt TYPE REF TO counter.

CREATE OBJECT cnt.

DATA : number TYPE i VALUE 5.

CALL METHOD cnt->set

EXPORTING

set_value = number.

DO 3 TIMES.

CALL METHOD cnt->increment.

ENDDO.

call method cnt->get

importing get_value = number.

It is giving error like Stament is not accessbile

please help

4 REPLIES 4

Former Member
0 Kudos

I got the Answer.

I missed the START-OF-SELECTION , before creating the object.

regards,

anjireddi

0 Kudos

Hello anjireddi,

then you could close the thread?

Regards

Martin

0 Kudos

yes......Instantiation and declaration cannot happen in the same event...

Instantiation is generally done in the start of selection

Former Member
0 Kudos

Hi Raman,

In case if you are interested in understanding why you got the error because of not using Start_of_selection, please check out the thread.

https://forums.sdn.sap.com/click.jspa?searchID=1653133&messageID=3017631

Regards

Indrajit