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

Creating objects ?

Former Member
0 Likes
1,660

Hi All,

I have create a local class definition and its corresponding implementation in my custom program. When i tried to create a object of this class it gave a error "Statement is not accessible" line pointing to the the create object statement. But when i placed the create object statement under START-OF-SELECTION event, the error went away and the code executed successfully.

Can you please let me know the reason behing this and generally under which event the local class definition and implementation should be placed and why ?

Thanks & Regards,

Navneeth K.

12 REPLIES 12
Read only

Former Member
0 Likes
1,579

<copy&paste_from_SAPHelp_removed_by_moderator>

Edited by: Julius Bussche on Oct 29, 2008 10:18 AM

If you do this again, your user ID will be deleted. This is your first warning

Read only

Former Member
0 Likes
1,579

Hello,

Generally, the Local Class definition & Implementation is an independant block of code that doesn't require to be placed under a specific event. For example, check the below code.

REPORT YVEN_LOCAL_CLASS no standard page heading.

class lcl_clas Definition.

Public Section.

methods: Write_hello.

Endclass.

class lcl_clas Implementation.

method Write_hello.

write:/ 'Hello from Local Class'.

Endmethod.

Endclass.

Data: ws_obj type ref to lcl_clas.

Start-of-selection.

create object ws_obj.

Call method ws_obj->Write_hello.

A simple code in which the Create Object Statement is placed under the Start-of-Selection Event. If you place it outside the Start-of-Selection, then you'll get the same error what you've got in your Custom Program. The reason is that an Object is required to be created under any particular event rather than simply issuing the CREATE Object Statement.

Copy & Paste the above code in your ABAP editor and see what happens when you comment out the Start-of-Selection Statement. Try the same code with the Create Object Statement being placed under Initialization Event.

Hope it was clear.

Thanks and Regards,

Venkat Phani Prasad Konduri

Read only

0 Likes
1,579

Thanks Venkat, If i am not wrong if we dont specify any event in the program, by default system takes all the statements under 'START-OF-SELECTION' event. So why we need to put this event explicitly.

Read only

0 Likes
1,579

The object can be created without the START-OF-SELECTION event (I tried). I guess it was rather a period error, a dot was missing from the end of the line or something like that.

Read only

0 Likes
1,579

Hi Eric, I assume object cannot be created unless it is placed in a event, Please paste a sample piece of code.

Read only

0 Likes
1,579

<Spoonfeeding>

just create a test program and paste the following two lines, it works without any problem:

DATA : gc TYPE REF TO cl_gui_frontend_services.
CREATE OBJECT gc.

</Spoonfeeding>

Read only

0 Likes
1,579

Eric, I have created a a local class definition and implimentation, your source code relates to a standard SAP class. Please check out is it possible to create a object for a local class without any event.

Read only

0 Likes
1,579

Hi Navneeth,

If u move ur implementation part below the create statement it works...but dono y

EX :

Here it asks for a START-OF-SELECTION event.

CLASS xyz DEFINITION.
  PUBLIC SECTION.
    METHODS hi.
ENDCLASS.                    "xyz DEFINITION

CLASS xyz IMPLEMENTATION.
  METHOD hi.
  ENDMETHOD.                    "hi
ENDCLASS.                    "xyz IMPLEMENTATION

DATA abc TYPE REF TO xyz.

START-OF-SELECTION.
CREATE OBJECT abc.

Here it working fine

CLASS xyz DEFINITION.
  PUBLIC SECTION.
    METHODS hi.
ENDCLASS.                    "xyz DEFINITION

DATA abc TYPE REF TO xyz.
CREATE OBJECT abc.

CLASS xyz IMPLEMENTATION.
  METHOD hi.
  ENDMETHOD.                    "hi
ENDCLASS.                    "xyz IMPLEMENTATION

Cheers,

Jose.

Read only

0 Likes
1,579

I gave it a try and realised the same... But I cannot explain...

Read only

0 Likes
1,579

Hello Navneeth

Irrespective of whether there is a coding solution for your problem with or without the

START-OF-SELECTION

statement EVERY DECENT report should contain this statement.

Why?

In my report this statement clearly separates the data definition parts from the main program, e.g.

Thus, it is a structural element of the report which enhances transparency and facilitates maintenance of the report.

It may be of academic interest to find out under which conditions local classes can be instantiated without the

START-OF-SELECTION statement yet for me its absence is just a sign of poor software quality.

Regards

Uwe

Read only

Former Member
0 Likes
1,579

Moved to ABAP Objects...

Read only

Former Member
0 Likes
1,579

Dear Navneeth K,

please, place CLASS IMPLEMENTATION at the end of code. In this case you should get what you want without START-OF-SELECTION statement.

The reason is that the CLASS IMPLEMENTATION is the processing block. If you write another statement like CREATE OBJECT after this processing block you should assign it to another processign block, for instance, START-OF-SELECTION.

Best regards,

John.