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

klasse innerhalb ein Form Implementieren

aboooood86
Participant
0 Likes
1,906

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.

1 ACCEPTED SOLUTION
Read only

aboooood86
Participant
0 Likes
1,845

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.

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.

7 REPLIES 7
Read only

FredericGirod
Active Contributor
1,845

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

Read only

aboooood86
Participant
0 Likes
1,845

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?

Read only

FredericGirod
Active Contributor
0 Likes
1,845
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.
Read only

Sandra_Rossi
Active Contributor
1,845

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.

Read only

aboooood86
Participant
0 Likes
1,845

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?

Read only

FredericGirod
Active Contributor
1,845

cant i implement the class inside the FORM?

--> No

Read only

aboooood86
Participant
0 Likes
1,846

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.