‎2008 Oct 29 6:57 AM
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.
‎2008 Oct 29 7:02 AM
<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
‎2008 Oct 29 7:08 AM
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
‎2008 Oct 29 7:11 AM
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.
‎2008 Oct 29 7:15 AM
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.
‎2008 Oct 29 7:20 AM
Hi Eric, I assume object cannot be created unless it is placed in a event, Please paste a sample piece of code.
‎2008 Oct 29 7:34 AM
<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>
‎2008 Oct 29 9:17 AM
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.
‎2008 Oct 29 9:26 AM
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 IMPLEMENTATIONCheers,
Jose.
‎2008 Oct 29 9:41 AM
I gave it a try and realised the same... But I cannot explain...
‎2008 Oct 29 10:50 AM
Hello Navneeth
Irrespective of whether there is a coding solution for your problem with or without the
START-OF-SELECTIONstatement 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
‎2008 Oct 29 9:17 AM
‎2008 Nov 07 10:23 AM
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.