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: 

Syntax Error

Former Member
0 Kudos
162

Hi,

I'm getting a syntax error in the following code at last line saying 'Statemetn is not accessible'. Can some one tell me why it is not accessabile & what wrong in the code?



REPORT  ztest_classes.
*&---------------------------------------------------------------------*


*----------------------------------------------------------------------*
*       CLASS class1 DEFINITION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS class1 DEFINITION.
  PUBLIC SECTION.
    METHODS: fun1.
    DATA: var1.
ENDCLASS.                    "class1 DEFINITION

*----------------------------------------------------------------------*
*       CLASS class1 IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS class1 IMPLEMENTATION.
  METHOD fun1.
    WRITE:/ 'Inside FUN1 of class1'.
  ENDMETHOD.                                                "fun1
ENDCLASS.                    "class1 IMPLEMENTATION


DATA: ref1 TYPE REF TO class1.

CREATE OBJECT ref1.

Regards,

Naga Sai Swapna

1 ACCEPTED SOLUTION

Former Member
0 Kudos
132

Hi,

Try

START-OF-SELECTION.

CREATE OBJECT ref1.

or INITIALIZATION

CREATE OBJECT ref1.

5 REPLIES 5

Former Member
0 Kudos
133

Hi,

Try

START-OF-SELECTION.

CREATE OBJECT ref1.

or INITIALIZATION

CREATE OBJECT ref1.

0 Kudos
132

Or you an move your implementations to the end of the program.

REPORT  ztest_classes.
*&---------------------------------------------------------------------*
 
 
*----------------------------------------------------------------------*
*       CLASS class1 DEFINITION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS class1 DEFINITION.
  PUBLIC SECTION.
    METHODS: fun1.
    DATA: var1.
ENDCLASS.                    "class1 DEFINITION
 

 
 
DATA: ref1 TYPE REF TO class1.
 
CREATE OBJECT ref1.
 ref1->fun1( ).


*----------------------------------------------------------------------*
*       CLASS class1 IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS class1 IMPLEMENTATION.
  METHOD fun1.
    WRITE:/ 'Inside FUN1 of class1'.
  ENDMETHOD.                                                "fun1
ENDCLASS.                    "class1 IMPLEMENTATION

Regards,

Rich Heilman

0 Kudos
132

Thank you Gary & Rich.

Both of your solutions have solved the problem. Could you please let me know the reason why start-of-selection has to be mentioned or why the implemention should be moved to the end of the code.

Regards,

Naga Sai Swapna

0 Kudos
132

>

> Could you please let me know the reason why....

Because otherwise, you will get a syntax error.

Basically it is a qwirk of the ABAP syntax checker.

Regards,

Rich Heilman

former_member555112
Active Contributor
0 Kudos
132

Hi,

Basically you should have some event such as START-OF-SELECTION after your class implementation.

Otherwise anything declared is considered as a part of the class and if it is not declared within the implementation you get this syntax error.

Regards,

Ankur Parab