Application Development and Automation 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: 
Read only

doubt in ABAP OOP

Former Member
0 Likes
1,200

CLASS SAMPLE DEFINITION.

PUBLIC SECTION.

DATA : PU_A TYPE I.

METHODS : CONSTRUCTOR,MM1,MM2.

PRIVATE SECTION.

DATA : PR_B TYPE I.

ENDCLASS.

CLASS SAMPLE IMPLEMENTATION.

METHOD CONSTRUCTOR.

ENDMETHOD.

METHOD MM1.

ENDMETHOD.

METHOD MM2.

ENDMETHOD.

ENDCLASS.

DATA : OBJ_SAMPLE TYPE REF TO SAMPLE.

<b>CREATE OBJECT OBJ_SAMPLE.</b>

In CREATE OBJECT OBJ_SAMPLE its giving err msg that statement could not be accessible.why id it so?.plz help

1 ACCEPTED SOLUTION
Read only

Former Member
1,145

give start-of-selection before data object declaration and try

like this

Start-of-selection.

DATA : OBJ_SAMPLE TYPE REF TO SAMPLE.

CREATE OBJECT OBJ_SAMPLE.

CLASS SAMPLE DEFINITION.

PUBLIC SECTION.

DATA : PU_A TYPE I.

METHODS : CONSTRUCTOR,MM1,MM2.

PRIVATE SECTION.

DATA : PR_B TYPE I.

ENDCLASS.

CLASS SAMPLE IMPLEMENTATION.

METHOD CONSTRUCTOR.

ENDMETHOD.

METHOD MM1.

ENDMETHOD.

METHOD MM2.

ENDMETHOD.

ENDCLASS.

DATA : OBJ_SAMPLE TYPE REF TO SAMPLE.

<b>CREATE OBJECT OBJ_SAMPLE.</b>

In CREATE OBJECT OBJ_SAMPLE its giving err msg that statement could not be accessible.why id it so?.plz help

10 REPLIES 10
Read only

Former Member
1,146

give start-of-selection before data object declaration and try

like this

Start-of-selection.

DATA : OBJ_SAMPLE TYPE REF TO SAMPLE.

CREATE OBJECT OBJ_SAMPLE.

Read only

0 Likes
1,145

Hi,

Object creation should be done under start-of-selection.

example

data obj1 type ref to <classname>.

start-of-selection.

create object obj1.

reward if useful

Regards,

Prajith

Read only

Former Member
0 Likes
1,145

is start-of-selection compulsory? but start-of-selection is not compulsary no?

Read only

0 Likes
1,145

if it has a selection sceen then an event is necessary...

try and see if it solves the problem

<b>PLEASE REWARD POINTS IF IT SOLVED THE PROBLEM</b>

Read only

0 Likes
1,145

<b>START-OF-SELECTION is compulsory as we are creating object.</b>

Regards,

Pavan P.

Read only

0 Likes
1,145

no it doesnot have a selection screen. Is the event start-of-selection compulsory?

Read only

Former Member
0 Likes
1,145

CLASS SAMPLE DEFINITION.

PUBLIC SECTION.

DATA : PU_A TYPE I.

METHODS : CONSTRUCTOR,MM1,MM2.

PRIVATE SECTION.

DATA : PR_B TYPE I.

ENDCLASS.

CLASS SAMPLE IMPLEMENTATION.

METHOD CONSTRUCTOR.

ENDMETHOD.

METHOD MM1.

ENDMETHOD.

METHOD MM2.

ENDMETHOD.

ENDCLASS.

DATA : OBJ_SAMPLE TYPE REF TO SAMPLE.

start-of-selection.

CREATE OBJECT OBJ_SAMPLE .

<b>Write START-OF-SELECTION before that line.</b>

Regards,

Pavan P.

Read only

Former Member
0 Likes
1,145

hi

copy paste my code and check. its very simple one that ur are looking for.



REPORT  zaaclc_report.

*----------------------------------------------------------------------*
*       CLASS lcl_test_class DEFINITION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS lcl_test_class DEFINITION.
  PUBLIC SECTION.
    METHODS increment_counter.
    EVENTS break_statement EXPORTING value(count) TYPE i.

  PRIVATE SECTION.
    DATA: num TYPE i,
          max TYPE i VALUE 5.
ENDCLASS.                    "lcl_test_class DEFINITION



*----------------------------------------------------------------------*
*       CLASS lcl_test_class IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS lcl_test_class IMPLEMENTATION.
  METHOD increment_counter.
    num = num + 1.

    IF num EQ max.
      RAISE EVENT break_statement  EXPORTING count = num.
    ENDIF.

    WRITE:/ num .
  ENDMETHOD.                    "increment_counter
ENDCLASS.                    "lcl_test_class IMPLEMENTATION

*----------------------------------------------------------------------*
*       CLASS event_receiver DEFINITION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS event_receiver DEFINITION.

  PUBLIC SECTION.
    METHODS handler FOR EVENT break_statement OF lcl_test_class  IMPORTING count.

    endclass.

*----------------------------------------------------------------------*
*       CLASS event_receiver IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS event_receiver IMPLEMENTATION.
  METHOD handler.
*    count = count + 10.
    WRITE :/ count.
    WRITE :/ 'Event Raised'.
    endmethod.
ENDCLASS.                    "event_receiver IMPLEMENTATION


DATA:obj TYPE REF TO lcl_test_class,
     rec TYPE REF TO event_receiver.

START-OF-SELECTION.
CREATE OBJECT: obj,rec.

set handler rec->handler for obj." for all instances.

  DO 10 TIMES.
    CALL METHOD obj->increment_counter.

  ENDDO.

<b> hope it clears ur doubt</b>

regards

ravish

<b>plz dont forget to reward points if helpful</b>

Message was edited by:

ravish goyal

Read only

Former Member
0 Likes
1,145

thank u

Read only

Former Member
0 Likes
1,145

thank u