2012 Oct 22 5:16 AM
Dear experts,
When an error occurs, my customer prefers going back to the selection screen rather than terminating the current program.
In the procedural programming style, I often use the STOP command to trigger the 'END OF SELECTION' event and go back to the selection screen. However, the STOP command is forbidden in ABAP OO.
Please tell me How to mimic the STOP command in ABAP OO and go back to the selection screen. Thanks a lot.
2012 Oct 22 6:00 AM
RAISE AN EXCEPTION from a method. Raising an exception is an elegant way, catch the exception in the main program, if caught then "exit" from main program.
parameters: pa type c.
class lcl definition.
public section.
methods return_to_screen exceptions error .
endclass. "lcl DEFINITION
class lcl implementation.
method return_to_screen.
raise error.
endmethod. "return_to_screen
endclass. "lcl IMPLEMENTATION
start-of-selection.
data:obj type ref to lcl.
create object obj.
obj->return_to_screen( exceptions error = 1 ).
if sy-subrc <> 0.
exit.
endif.
2012 Oct 22 6:00 AM
RAISE AN EXCEPTION from a method. Raising an exception is an elegant way, catch the exception in the main program, if caught then "exit" from main program.
parameters: pa type c.
class lcl definition.
public section.
methods return_to_screen exceptions error .
endclass. "lcl DEFINITION
class lcl implementation.
method return_to_screen.
raise error.
endmethod. "return_to_screen
endclass. "lcl IMPLEMENTATION
start-of-selection.
data:obj type ref to lcl.
create object obj.
obj->return_to_screen( exceptions error = 1 ).
if sy-subrc <> 0.
exit.
endif.
2012 Oct 22 7:39 AM
Hi Michael
Actualy As of my concern , you should used the class based exception concept by using this concept . we can break the execution for runtime error .or break the terminate of programe .
the code is given below . according to your requirement u can use it.
TRY.
CALL METHOD o1->m1.
PERFORM f1.
CATCH cx_root. "Handler for all exceptions
" ABAP code(What to do when error occures)........
ENDTRY.
FORM f1 RAISING cx_my.
TRY.
IF ...... RAISE EXCEPTION TYPE cx_my2. ENDIF.
CALL METHOD o1->m3.
CATCH cx_my1 cx_my3 INTO ex.
RAISE EXCEPTION TYPE cx_my4.
CATCH cx_my4.
"Handler for exceptions of type cx_my4
" ABAP code(What to do when error occures)........
CLEANUP.
"Cleanup section, used to restore to a consistant state
" ABAP code........
ENDTRY.
ENDFORM.
thanks & regard
suraj singh
Moderator Message: The similar code was found in different sources mentioned below, please try to include the source & suitable explanation instead of copying the content. Copy/Paste from different sources is not allowed in this forum and is against the forum rules.
http://www.sapdev.co.uk/error/error_new610.htm
http://www.saptechies.com/how-to-initiate-the-at-selection-screen-event/
Message was edited by: Kesavadas Thekkillath
2012 Oct 23 2:57 AM
Hi all,
Thanks for the kind reply. My colleague and I use "CALL TRANSACTION sy-tcode" yesterday. However, the RAISE AN EXCEPTION is a much nicer solution.