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

addition missing

Former Member
0 Likes
1,214

Dear Experts,

which syntax is the correct one. According to Abap OOP Tutorials is Example 1 the common kind of syntax, isn' it?

Because I am getting this error massage with example1: PUBLIC addition of the CLASS statement is missing

-----------------------------------------------------------------------------------------------

Example 1

CLASS ZCL_EMPLOYEE definition.

* compare this section with below example 2


   public section.
    TYPES:
       BEGIN OF t_employee,
         no  TYPE i,
         name TYPE string,
      END OF t_employee.

   METHODS:
       constructor
         IMPORTING im_employee_no TYPE i
                   im_employee_name TYPE string,

      display_employee.
   protected section.
       CLASS-DATA: g_no_of_employees TYPE i.
   private section.
       DATA: g_employee TYPE t_employee.
ENDCLASS.

-----------------------------------------------------------------------------------------------

This works well with the part after DEFINITION.

Example 2

CLASS ZCL_EMPLOYEE definition

   public

   final

   create public .

 

 

   public section.

      TYPES:

       BEGIN OF t_employee,

         no  TYPE i,

         name TYPE string,

      END OF t_employee.

   METHODS:
       constructor
         IMPORTING im_employee_no TYPE i
                   im_employee_name TYPE string,

      display_employee.
   protected section.
       CLASS-DATA: g_no_of_employees TYPE i.
   private section.
       DATA: g_employee TYPE t_employee.
ENDCLASS.

-----------------------------------------------------------------------------------------------

Best Regards

Hakan

1 ACCEPTED SOLUTION
Read only

Tomas_Buryanek
Product and Topic Expert
Product and Topic Expert
0 Likes
876

The difference is that example 1 is local class and example 2 is global class.

I guess you are getting error because you are writing example 1 in either SE24 (code view) or in ADT, right?

F1 on CLASS .. DEFINITION PUBLIC.. :


The PUBLIC addition specifies that the class class is a global class in the Class Library. You can only apply the PUBLIC addition to one class in a class pool. This addition is generated by the Class Builder when a global class is created. Any class that does not have the PUBLIC addition applied to it is a local class in its program.

-- Tomas --
2 REPLIES 2
Read only

Tomas_Buryanek
Product and Topic Expert
Product and Topic Expert
0 Likes
877

The difference is that example 1 is local class and example 2 is global class.

I guess you are getting error because you are writing example 1 in either SE24 (code view) or in ADT, right?

F1 on CLASS .. DEFINITION PUBLIC.. :


The PUBLIC addition specifies that the class class is a global class in the Class Library. You can only apply the PUBLIC addition to one class in a class pool. This addition is generated by the Class Builder when a global class is created. Any class that does not have the PUBLIC addition applied to it is a local class in its program.

-- Tomas --
Read only

0 Likes
876

Thx.

Example 2 is wirtten in ADT and not Example 1