mj1261829
mj1261829

Reputation: 1319

"Cannot use statement endclass" when activating local class

I am trying to create a class in abap with its definition and implementation:

class ZCL_GUI_ALV_GRID_MERGE definition
  public
  final
  inheriting from CL_GUI_ALV_GRID
  create public .

*"* public components of class ZCL_GUI_ALV_GRID_MERGE
*"* do not include other source files here!!!
public section.

methods Z_SET_MERGE_HORIZ
    importing
      ROW type I
    changing
      TAB_COL_MERGE type LVC_T_CO01 .
  methods Z_SET_MERGE_VERT
    importing
      ROW type I
    changing
      TAB_COL_MERGE type LVC_T_CO01 .
  methods Z_DISPLAY .
  methods Z_SET_CELL_STYLE
    importing
      ROW type I optional
      COL type I optional
      STYLE type LVC_STYLE
      STYLE2 type LVC_STYLE optional .
  methods Z_SET_FIXED_COL_ROW
    importing
      COL type I
      ROW type I .
  methods Z_INIT_CELL_STYLES .

endclass.

class ZCL_GUI_ALV_GRID_MERGE implementation.

************************************************** **********************
* Method attributes. *
******************************************************************************** *************************
"Instantiation: Public
************************************************** ************************

method Z_SET_MERGE_HORIZ.

* ROW - Row whose columns are to be merged
* tab_col_merge - Columns to be merged
   FIELD-SYMBOLS <fs_cols> TYPE lvc_s_co01.
   FIELD-SYMBOLS <fs_data> TYPE lvc_s_data.
   DATA outputlen TYPE i.

   SORT tab_col_merge.
* The columns to be merged
   LOOP AT tab_col_merge ASSIGNING <fs_cols>.
* a few tests
     if <fs_cols>-col_id le 0. continue. endif.
     if <fs_cols>-outputlen le <fs_cols>-col_id. continue. endif.
     outputlen = <fs_cols>-outputlen - <fs_cols>-col_id.
     LOOP AT mt_data ASSIGNING <fs_data>
          WHERE row_pos = row AND col_pos BETWEEN <fs_cols>-col_id AND <fs_cols>-outputlen.
* Set how far should be merged From column in length
* and that is begun at the 1 column
       IF <fs_data>-col_pos = <fs_cols>-col_id.
         <fs_data>-mergehoriz = outputlen.
* with all others, which zusammengehangeren
* the value out, since it comes from the 1. Column
* and the mergekennzeichen must also away!
       ELSE.
         CLEAR <fs_data>-mergehoriz.
         CLEAR <fs_data>-value.
       ENDIF.
     ENDLOOP.

   ENDLOOP.

ENDMETHOD.

method Z_SET_MERGE_VERT.

* ROW - Row whose columns are to be merged 
* tab_col_merge - Columns to be merged
   FIELD-SYMBOLS <fs_cols> TYPE lvc_s_co01. 
   FIELD-SYMBOLS <fs_data> TYPE lvc_s_data. 
   DATA outputlen TYPE i. 

   SORT tab_col_merge.
* The columns to be merged
   LOOP AT tab_col_merge ASSIGNING <fs_cols>.
* a few tests
     if <fs_cols>-col_id le 0. continue. endif. 
     if <fs_cols>-outputlen le <fs_cols>-col_id. continue. endif. 
     outputlen = <fs_cols>-outputlen - <fs_cols>-col_id. 
     LOOP AT mt_data ASSIGNING <fs_data> 
          WHERE row_pos = row AND 
                col_pos between <fs_cols>-col_id AND 
                                  <fs_cols>-outputlen.
* Set how far should be merged From column in length 
* and that is begun at the 1 column
       IF <fs_data>-col_pos = <fs_cols>-col_id. 
         <fs_data>-mergevert = outputlen.
* with all others, which zusammengehangeren 
* the value out, since it comes from the 1. Column 
* and the mergekennzeichen must also away!
       ELSE. 
         CLEAR <fs_data>-mergevert. 
         CLEAR <fs_data>-value. 
       ENDIF. 
     ENDLOOP. 

   ENDLOOP. 

ENDMETHOD.

METHOD z_display.

  DATA lv_stable TYPE lvc_s_stbl.
  DATA lv_soft   TYPE c.

**** Prepare refresh
*  lv_stable-row = 'X'.
*  lv_stable-col = 'X'.
*  lv_soft       = 'X'.
*
**** Refresh table because Z_SET_CELL_STYLE adds style-values
**** Refresh initializes mt_data
*  CALL METHOD refresh_table_display
*    EXPORTING
*      is_stable      = lv_stable
*      i_soft_refresh = lv_soft
*    EXCEPTIONS
*      OTHERS         = 1.

* Jetzt noch  �bertragen der ge�nderten Daten
  CALL METHOD me->set_data_table
    CHANGING
      data_table = mt_data[].

  CALL METHOD set_auto_redraw
    EXPORTING
      enable = 1.

ENDMETHOD.

METHOD z_set_cell_style.

  FIELD-SYMBOLS <fs_data> TYPE lvc_s_data.
  IF row IS INITIAL.
    IF col IS INITIAL.
* Beides leer -> nichts zu tun.
      EXIT.
    ELSE.
* Nur Spalte setze komplette Spalte
      LOOP AT mt_data ASSIGNING <fs_data>
            WHERE col_pos = col.
        <fs_data>-style  = <fs_data>-style + style.
        <fs_data>-style2 = <fs_data>-style2 + style2.
      ENDLOOP.
    ENDIF.
  ELSE.
    IF col IS INITIAL.
* Nur Zeile eingegeben -> komplette Zeile setzen
      LOOP AT mt_data ASSIGNING <fs_data>
            WHERE row_pos = row.
        <fs_data>-style  = <fs_data>-style + style.
        <fs_data>-style2 = <fs_data>-style2 + style2.
      ENDLOOP.
    ELSE.
      READ TABLE mt_data ASSIGNING <fs_data>
          WITH KEY row_pos = row
                   col_pos = col.
      IF sy-subrc EQ 0.
        <fs_data>-style  = <fs_data>-style + style.
        <fs_data>-style2 = <fs_data>-style2 + style2.
      ELSE.
        EXIT.
      ENDIF.
    ENDIF.
  ENDIF.

ENDMETHOD.

method Z_SET_FIXED_COL_ROW.

  me->set_fixed_cols( col ).
  me->set_fixed_rows( row ).

endmethod.

METHOD z_init_cell_styles.

  FIELD-SYMBOLS <fs_data> TYPE lvc_s_data.
* Nur Spalte setze komplette Spalte
  LOOP AT mt_data ASSIGNING <fs_data>.
    <fs_data>-style = 0.
  ENDLOOP.

ENDMETHOD.

endclass.

You see I created the class twice once for the other for the implementation.

I am getting this weird error which I cannot resolve:

You cannot use the statement "endclass" in the current environment. However you can use the similar statement class

Any idea why the error shows up and how to fix?

Upvotes: 1

Views: 1173

Answers (1)

Suncatcher
Suncatcher

Reputation: 10621

It seems that you just copy-pasted global class source and want to activate it. It won't work that way, as global class are always public by definition and local are not.

SAP documentation excerpt:

The syntax for defining classes and interfaces is essentially the same for local and global classes and interfaces. The only difference is in the addition PUBLIC, which makes a distinction between the global classes and interfaces and local declarations.

If you want to use the class as local, remove PUBLIC declaration as suggested by Jagger, and put the class into class pool, so it will be available to all global classed of this pool.

If you want it to be accessible by all classes of ABAP repository, make it global.

Upvotes: 2

Related Questions