2022 Jun 28 11:39 AM
Hallo zusammen mein problem ist dass ich eine klasse innerhalb ein form und try nicht Implementieren kann. wenn ich das mach kommt folgende fehlermeldung: "Die Schachtelung ist nicht korrekt: Vor der Anweisung "Class" muss die mit "try" begonnen Kontrollstruktur durch "endtry" abgeschlossen werden " wenn ich try vor dem klasse mach dann riagiert nicht und der fehler bleibt noch. ich würde mich freuen wenn jemand mir damit hilft. so sieht mein code aus:
FORM output CHANGING ct_out TYPE tty_rseg.
TRY.
CALL METHOD cl_salv_table=>factory
IMPORTING
r_salv_table = DATA(lr_salv_report) " Basisklasse einfache ALV Tabellen
CHANGING
t_table = ct_out.
DATA(lr_salv_funktions) = lr_salv_report->get_functions( ).
DATA(lr_salv_columns) = lr_salv_report->get_columns( ).
lr_salv_funktions->set_all(
value = if_salv_c_bool_sap=>true
).
CREATE OBJECT lo_alv.
lo_alv->set_hotspot_beleg( CHANGING co_alv = lr_salv_report ).
lr_salv_report->display( ).
CLASS lcl_alv IMPLEMENTATION.
METHOD set_hotspot_beleg.
* Set Hotspot
DATA: lo_cols_tab TYPE REF TO cl_salv_columns_table,
lo_col_tab TYPE REF TO cl_salv_column_table.
* Get columns object
lo_cols_tab = co_alv->get_columns( ).
TRY.
lo_col_tab ?= lo_cols_tab->get_column( 'EINKAUFSBELEG' ).
CATCH cx_salv_not_found.
ENDTRY.
* Set the hotspot for MATNR column
TRY.
CALL METHOD lo_col_tab->set_cell_type
EXPORTING
value = if_salv_c_cell_type=>hotspot.
CATCH cx_salv_data_error .
ENDTRY.
DATA: lo_events TYPE REF TO cl_salv_events_table.
* All events
lo_events = lr_salv_report->get_event( ).
* Event handler
SET HANDLER me->on_beleg_click FOR lo_events.
*
ENDMETHOD.
ENDCLASS.
ENDTRY.
ENDFORM.
2022 Jun 28 4:26 PM
so jetzt habe ich die iplementierung außerhalb try und form und jetzt klappt danke für jeder hilfe
FORM output CHANGING ct_out TYPE tty_rseg.
TRY.
CALL METHOD cl_salv_table=>factory
IMPORTING
r_salv_table = DATA(lr_salv_report) " Basisklasse einfache ALV Tabellen
CHANGING
t_table = ct_out.
DATA(lr_salv_funktions) = lr_salv_report->get_functions( ).
DATA(lr_salv_columns) = lr_salv_report->get_columns( ).
lr_salv_funktions->set_all( if_salv_c_bool_sap=>true ).
CREATE OBJECT lo_alv.
lo_alv->set_hotspot_beleg( CHANGING co_alv = lr_salv_report ).
lr_salv_report->display( ).
ENDTRY.
ENDFORM.
CLASS lcl_alv IMPLEMENTATION.
METHOD set_hotspot_beleg.
* Set Hotspot
DATA: lo_cols_tab TYPE REF TO cl_salv_columns_table,
lo_col_tab TYPE REF TO cl_salv_column_table.
* Get columns object
lo_cols_tab = co_alv->get_columns( ).
TRY.
lo_col_tab ?= lo_cols_tab->get_column( 'EBELN' ).
CATCH cx_salv_not_found.
" <-- Need to do something here
ENDTRY.
* Set the hotspot for MATNR column
TRY.
CALL METHOD lo_col_tab->set_cell_type
EXPORTING
value = if_salv_c_cell_type=>hotspot.
CATCH cx_salv_data_error .
" <-- Need to do something here
ENDTRY.
* All events
DATA lo_events TYPE REF TO cl_salv_events_table.
lo_events = lr_salv_report->get_event( ).
* Event handler
SET HANDLER me->on_beleg_click FOR lo_events.
*
ENDMETHOD.
ENDCLASS.
When you create programs, either use subroutines (form ... endform) or methods but not both. Note that subroutines have been obsolete for a long time and should be used only if no other choice.
2022 Jun 28 12:04 PM
You cannot set a CLASS IMPLEMETATION in a TRY // ENDTRY.
You have to close the ENDTRY and to set a CATH before the statement CLASS ... IMPLEMENTATION.
The exception raised during the METHOD set_hotspot have to be catched during the call of this method.
And you have to add to the method set_hotspot_beleg a RAISING with your exception class
2022 Jun 28 12:32 PM
im sorry i couldnt understand u, i closed the try before the class statement. the second sentence i couldnt understand it could u please tell me how to do that?
2022 Jun 28 12:39 PM
FORM output CHANGING ct_out TYPE tty_rseg.
TRY.
CALL METHOD cl_salv_table=>factory
IMPORTING
r_salv_table = DATA(lr_salv_report) " Basisklasse einfache ALV Tabellen
CHANGING
t_table = ct_out.
DATA(lr_salv_funktions) = lr_salv_report->get_functions( ).
DATA(lr_salv_columns) = lr_salv_report->get_columns( ).
lr_salv_funktions->set_all( if_salv_c_bool_sap=>true ).
CREATE OBJECT lo_alv.
lo_alv->set_hotspot_beleg( CHANGING co_alv = lr_salv_report ).
lr_salv_report->display( ).
ENDTRY. " <-- Need to add an ENDTRY.
CLASS lcl_alv IMPLEMENTATION.
METHOD set_hotspot_beleg.
* Set Hotspot
DATA: lo_cols_tab TYPE REF TO cl_salv_columns_table,
lo_col_tab TYPE REF TO cl_salv_column_table.
* Get columns object
lo_cols_tab = co_alv->get_columns( ).
TRY.
lo_col_tab ?= lo_cols_tab->get_column( 'EINKAUFSBELEG' ).
CATCH cx_salv_not_found.
" <-- Need to do something here
ENDTRY.
* Set the hotspot for MATNR column
TRY.
CALL METHOD lo_col_tab->set_cell_type
EXPORTING
value = if_salv_c_cell_type=>hotspot.
CATCH cx_salv_data_error .
" <-- Need to do something here
ENDTRY.
* All events
DATA lo_events TYPE REF TO cl_salv_events_table.
lo_events = lr_salv_report->get_event( ).
* Event handler
SET HANDLER me->on_beleg_click FOR lo_events.
*
ENDMETHOD.
ENDCLASS.
*ENDTRY. " <-- Need to kill this
ENDFORM.
2022 Jun 28 12:46 PM
When you create programs, either use subroutines (form ... endform) or methods but not both. Note that subroutines have been obsolete for a long time and should be used only if no other choice.
2022 Jun 28 12:48 PM
i did that already and thought i did somthing wrong cuz now the same error but with the FORM
cant i implement the class inside the FORM?
2022 Jun 28 12:50 PM
2022 Jun 28 4:26 PM
so jetzt habe ich die iplementierung außerhalb try und form und jetzt klappt danke für jeder hilfe
FORM output CHANGING ct_out TYPE tty_rseg.
TRY.
CALL METHOD cl_salv_table=>factory
IMPORTING
r_salv_table = DATA(lr_salv_report) " Basisklasse einfache ALV Tabellen
CHANGING
t_table = ct_out.
DATA(lr_salv_funktions) = lr_salv_report->get_functions( ).
DATA(lr_salv_columns) = lr_salv_report->get_columns( ).
lr_salv_funktions->set_all( if_salv_c_bool_sap=>true ).
CREATE OBJECT lo_alv.
lo_alv->set_hotspot_beleg( CHANGING co_alv = lr_salv_report ).
lr_salv_report->display( ).
ENDTRY.
ENDFORM.
CLASS lcl_alv IMPLEMENTATION.
METHOD set_hotspot_beleg.
* Set Hotspot
DATA: lo_cols_tab TYPE REF TO cl_salv_columns_table,
lo_col_tab TYPE REF TO cl_salv_column_table.
* Get columns object
lo_cols_tab = co_alv->get_columns( ).
TRY.
lo_col_tab ?= lo_cols_tab->get_column( 'EBELN' ).
CATCH cx_salv_not_found.
" <-- Need to do something here
ENDTRY.
* Set the hotspot for MATNR column
TRY.
CALL METHOD lo_col_tab->set_cell_type
EXPORTING
value = if_salv_c_cell_type=>hotspot.
CATCH cx_salv_data_error .
" <-- Need to do something here
ENDTRY.
* All events
DATA lo_events TYPE REF TO cl_salv_events_table.
lo_events = lr_salv_report->get_event( ).
* Event handler
SET HANDLER me->on_beleg_click FOR lo_events.
*
ENDMETHOD.
ENDCLASS.
| User | Count |
|---|---|
| 3 | |
| 2 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |