我正在尝试在abap中创建一个类及其定义和实现:
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.
您会看到我为另一个实现创建了两次类。
我收到这个无法解决的奇怪错误:
不能在当前环境中使用语句"endclass"。 但是,您可以使用类似的语句类
知道为什么会出现错误以及如何修复吗?
似乎您只是复制粘贴了全局类源并想要激活它。它不会那样工作,因为全局类在定义上总是公共的,而本地不是。
SAP 文档摘录:
对于本地和全局类和接口,定义类和接口的语法基本相同。唯一的区别是添加 PUBLIC,它区分了全局类和接口以及本地声明。
如果要将类用作本地类,请按照 Jagger 的建议删除PUBLIC
声明,并将该类放入类池中,以便它可用于此池的所有全局分类。
如果您希望 ABAP 存储库的所有类都可以访问它,请将其设置为全局。