Code: Alles auswählen.
REPORT.
CLASS lcl_report DEFINITION CREATE PRIVATE.
PUBLIC SECTION.
CLASS-METHODS main.
PRIVATE SECTION.
CLASS-DATA tadir1 TYPE SORTED TABLE OF tadir WITH NON-UNIQUE KEY obj_name.
CLASS-DATA tadir2 TYPE SORTED TABLE OF tadir WITH NON-UNIQUE KEY obj_name.
CLASS-METHODS do_assign.
CLASS-METHODS do_value.
CLASS-METHODS do_exception.
CLASS-METHODS do_exception_type.
CLASS-METHODS do_exception_new.
CLASS-METHODS do_exception_with_into.
CLASS-METHODS do_exception_type_with_into.
CLASS-METHODS do_exception_new_with_into.
CLASS-METHODS do_line_exists.
CLASS-METHODS do_read_table_no_fields.
CLASS-METHODS do_read_table_into.
CLASS-METHODS do_read_table_fs_into.
CLASS-METHODS do_read_table_ref_into.
CLASS-METHODS do_ref.
ENDCLASS.
CLASS lcl_report IMPLEMENTATION.
METHOD main.
SELECT * FROM tadir INTO TABLE tadir1 UP TO 1000000 ROWS.
tadir2 = tadir1.
do_line_exists( ).
do_assign( ).
do_value( ).
do_ref( ).
do_read_table_no_fields( ).
do_exception( ).
do_exception_type( ).
do_exception_new( ).
do_exception_with_into( ).
do_exception_type_with_into( ).
do_exception_new_with_into( ).
do_read_table_into( ).
do_read_table_fs_into( ).
do_read_table_ref_into( ).
ENDMETHOD.
METHOD do_assign.
LOOP AT tadir1 ASSIGNING FIELD-SYMBOL(<line>).
ASSIGN tadir2[ obj_name = |{ <line>-obj_name }1| ] TO FIELD-SYMBOL(<fs1>).
IF sy-subrc <> 0.
" do error handling
ENDIF.
ENDLOOP.
ENDMETHOD.
METHOD do_value.
LOOP AT tadir1 ASSIGNING FIELD-SYMBOL(<line>).
DATA(line) = VALUE #( tadir2[ obj_name = |{ <line>-obj_name }1| ] OPTIONAL ).
IF line IS INITIAL.
" do error handling
ENDIF.
ENDLOOP.
ENDMETHOD.
METHOD do_exception.
LOOP AT tadir1 ASSIGNING FIELD-SYMBOL(<line>).
TRY.
DATA(line) = VALUE #( tadir2[ obj_name = |{ <line>-obj_name }1| ] ).
CATCH cx_sy_itab_line_not_found.
" do error handling
ENDTRY.
ENDLOOP.
ENDMETHOD.
METHOD do_exception_new.
LOOP AT tadir1 ASSIGNING FIELD-SYMBOL(<line>).
ASSIGN tadir2[ obj_name = |{ <line>-obj_name }1| ] TO FIELD-SYMBOL(<fs1>).
IF sy-subrc <> 0.
TRY.
RAISE EXCEPTION NEW cx_sy_itab_line_not_found( ).
CATCH cx_sy_itab_line_not_found.
" do error handling
ENDTRY.
ENDIF.
ENDLOOP.
ENDMETHOD.
METHOD do_exception_type.
LOOP AT tadir1 ASSIGNING FIELD-SYMBOL(<line>).
ASSIGN tadir2[ obj_name = |{ <line>-obj_name }1| ] TO FIELD-SYMBOL(<fs1>).
IF sy-subrc <> 0.
TRY.
RAISE EXCEPTION type cx_sy_itab_line_not_found.
CATCH cx_sy_itab_line_not_found.
" do error handling
ENDTRY.
ENDIF.
ENDLOOP.
ENDMETHOD.
METHOD do_line_exists.
LOOP AT tadir1 ASSIGNING FIELD-SYMBOL(<line>).
IF NOT line_exists( tadir2[ obj_name = |{ <line>-obj_name }1| ] ).
" do error handling
ENDIF.
ENDLOOP.
ENDMETHOD.
METHOD do_read_table_no_fields.
LOOP AT tadir1 ASSIGNING FIELD-SYMBOL(<line>).
READ TABLE tadir1 WITH KEY obj_name = |{ <line>-obj_name }1| TRANSPORTING NO FIELDS.
if sy-subrc <> 0.
" do error handling
ENDIF.
ENDLOOP.
ENDMETHOD.
METHOD do_ref.
LOOP AT tadir1 ASSIGNING FIELD-SYMBOL(<line>).
DATA(line) = REF #( tadir2[ obj_name = |{ <line>-obj_name }1| ] OPTIONAL ).
IF line IS NOT BOUND.
" do error handling
ENDIF.
ENDLOOP.
ENDMETHOD.
METHOD do_exception_new_with_into.
LOOP AT tadir1 ASSIGNING FIELD-SYMBOL(<line>).
ASSIGN tadir2[ obj_name = |{ <line>-obj_name }1| ] TO FIELD-SYMBOL(<fs1>).
IF sy-subrc <> 0.
TRY.
RAISE EXCEPTION NEW cx_sy_itab_line_not_found( ).
CATCH cx_sy_itab_line_not_found into DATA(e).
" do error handling
ENDTRY.
ENDIF.
ENDLOOP.
ENDMETHOD.
METHOD do_exception_type_with_into.
LOOP AT tadir1 ASSIGNING FIELD-SYMBOL(<line>).
ASSIGN tadir2[ obj_name = |{ <line>-obj_name }1| ] TO FIELD-SYMBOL(<fs1>).
IF sy-subrc <> 0.
TRY.
RAISE EXCEPTION type cx_sy_itab_line_not_found.
CATCH cx_sy_itab_line_not_found into DATA(e).
" do error handling
ENDTRY.
ENDIF.
ENDLOOP.
ENDMETHOD.
METHOD do_exception_with_into.
LOOP AT tadir1 ASSIGNING FIELD-SYMBOL(<line>).
TRY.
DATA(line) = VALUE #( tadir2[ obj_name = |{ <line>-obj_name }1| ] ).
CATCH cx_sy_itab_line_not_found into DATA(e).
" do error handling
ENDTRY.
ENDLOOP.
ENDMETHOD.
METHOD do_read_table_into.
LOOP AT tadir1 ASSIGNING FIELD-SYMBOL(<line>).
READ TABLE tadir1 WITH KEY obj_name = |{ <line>-obj_name }1| INTO DATA(line).
if sy-subrc <> 0.
" do error handling
ENDIF.
ENDLOOP.
ENDMETHOD.
METHOD do_read_table_fs_into.
LOOP AT tadir1 ASSIGNING FIELD-SYMBOL(<line>).
READ TABLE tadir1 WITH KEY obj_name = |{ <line>-obj_name }1| ASSIGNING FIELD-SYMBOL(<fs>).
if sy-subrc <> 0.
" do error handling
ENDIF.
ENDLOOP.
ENDMETHOD.
METHOD do_read_table_ref_into.
LOOP AT tadir1 ASSIGNING FIELD-SYMBOL(<line>).
READ TABLE tadir1 WITH KEY obj_name = |{ <line>-obj_name }1| REFERENCE INTO DATA(line).
if sy-subrc <> 0.
" do error handling
ENDIF.
ENDLOOP.
ENDMETHOD.
ENDCLASS.
START-OF-SELECTION.
lcl_report=>main( ).
Folgende Benutzer bedankten sich beim Autor rob_abc für den Beitrag (Insgesamt 5):
a-dead-trousers • tar • black_adept • qyurryus • Romaniac
Diese Möglichkeit hat man im vorliegenden Fall aber nicht. Das geht nur, wenn Du "mutwillig" per RAISE eine Exception wirfst. Wenn Du aber - wie in dem Problem, um das es in diesem Thread geht - eine Zuweisung hast und diese mit einer Exception auf die Bretter gehen lässt und diese Exception dann mit einem CATCH abfängst, dann hast Du keinen Einfluss darauf, um was für eine Art Exception es sich handelt.rob_abc hat geschrieben:Wenn man RAISE EXCEPTION TYPE nutzt