02-25-2009 10:40 PM
Hello,
In my code I am submitting another program. Now the programn that should be submitted is based in a configuration. So if the program is not present in the configuration, then I would like to catch error using try-catch execption stuff isntead of giving dump. Can somebody help on this ?
Regards,
Jainam,
02-26-2009 4:59 AM
Hello Jainam,
The best solution would be to implement how Narendran has specified. The TRY-CATCH-ENDTRY block will not work in a SUMBIT statement because LOAD_PROGRAM_NOT_FOUND is a non-catchable exception. I quote from ABAP documentation for SUBMIT statement:
Exceptions
Non-Catchable Exceptions
Cause: The specified program was not found.
Runtime Error: LOAD_PROGRAM_NOT_FOUND
Cause: You tried to transfer an invalid value to a selection using the addition SIGN.
Runtime Error: SUBMIT_WRONG_SIGN
Cause: The specified program is not a report.
Runtime Error: SUBMIT_WRONG_TYPE
Cause: You tried to transfer more than one value to a report parameter.
Runtime Error: SUBMIT_IMPORT_ONLY_PARAMETER
Cause: You tried to use WITH sel IN itab to transfer a table that does not have the appropriate structure to a selection.
Runtime Error: SUBMIT_IN_ITAB_ILL_STRUCTURE
Cause: You tried to transfer a parameter that cannot be converted to the target field to the selection screen.
Runtime Error: SUBMIT_PARAM_NOT_CONVERTIBLE
Do not even try to CATCH the SUBMIT as some of the others have suggested out because it is a NON-CATCHABLE Exception. As soon as the ABAP run-time hits the SUBMIT, it will immediately short-dump even if you have a TRY-CATCH block with an exception class.... so better to check it against table TRDIR before SUMBIT. I recently had to do a similar check before SUBMIT, so this is how I did it:
Calling Program
............................ .....................
read table lt_zft_buff_vers into ls_vers index 1.
ev_prog_name = ls_vers-prog_name.
" Config was found - now check if the program name is valid and it is Type '1'
if zcl_f_buff_config=>check_veh_prog_name( ev_prog_name ) is not initial. "<---- check
ev_prog_name = ls_vers-vr_abap_name.
submit (ev_prog_name)
with pa_bukrs eq pa_bukrs
with pa_email eq pa_email
with pa_herm eq pa_herm
with pa_msg1 eq pa_msg1
with pa_msg2 eq pa_msg2
with pa_optio eq pa_optio
with pa_mthyr eq pa_mthyr
and return.
else.
" Program not found in program directory - (could be a typo in the customizing table)
" OR the program name entered is not an executable program (Type '1')
" we handle this here so that it does not short-dump
message a011(zf_vr_messages)
with ev_prog_name
raising program_not_found.
endif.
Method
method check_veh_prog_name.
" RV_EXIST = X -> program exists and program type = '1' (Executable)
" RV_EXIST = space -> program does not exist or program type <> '1'
data: ls_trdir type trdir.
select single * from trdir into ls_trdir
where name = iv_program.
check sy-subrc = 0.
check ls_trdir-subc = '1'.
rv_exist = lcl_gc=>gc_true.
endmethod.
Hope this helps.
Cheers,
Sougata.
02-25-2009 11:04 PM
Hi,
check if the program exists in TRDIR table before using it in SUBMIT.
DATA: v_program TYPE syrepid.
v_program = 'ZTEST122'.
SELECT SINGLE name INTO v_program
FROM trdir
WHERE name = v_program.
IF sy-subrc = 0.
SUBMIT (v_program) AND RETURN.
ENDIF.
Thanks
Naren
02-26-2009 1:36 AM
Hi Jainam
Try this .
TRY.
SUBMIT <ZPROGRAM> AND RETURN.
CATCH <EXCEPTION ID>.
ENDTRY.
This will solve your problem.
Regards
Hareesh.
02-26-2009 3:59 AM
Hello Jainam,
Please use the following code.
DATA: oref TYPE REF TO cx_root,
text TYPE string.
TRY.
Submit <your Report Name> with < parameters> and return.
CATCH <the exception name> INTO oref.
text = oref->get_text( ).
CATCH cx_root INTO oref.
text = oref->get_text( ).
ENDTRY.
IF NOT text IS INITIAL.
WRITE / text.
ENDIF.
02-26-2009 4:59 AM
Hello Jainam,
The best solution would be to implement how Narendran has specified. The TRY-CATCH-ENDTRY block will not work in a SUMBIT statement because LOAD_PROGRAM_NOT_FOUND is a non-catchable exception. I quote from ABAP documentation for SUBMIT statement:
Exceptions
Non-Catchable Exceptions
Cause: The specified program was not found.
Runtime Error: LOAD_PROGRAM_NOT_FOUND
Cause: You tried to transfer an invalid value to a selection using the addition SIGN.
Runtime Error: SUBMIT_WRONG_SIGN
Cause: The specified program is not a report.
Runtime Error: SUBMIT_WRONG_TYPE
Cause: You tried to transfer more than one value to a report parameter.
Runtime Error: SUBMIT_IMPORT_ONLY_PARAMETER
Cause: You tried to use WITH sel IN itab to transfer a table that does not have the appropriate structure to a selection.
Runtime Error: SUBMIT_IN_ITAB_ILL_STRUCTURE
Cause: You tried to transfer a parameter that cannot be converted to the target field to the selection screen.
Runtime Error: SUBMIT_PARAM_NOT_CONVERTIBLE
Do not even try to CATCH the SUBMIT as some of the others have suggested out because it is a NON-CATCHABLE Exception. As soon as the ABAP run-time hits the SUBMIT, it will immediately short-dump even if you have a TRY-CATCH block with an exception class.... so better to check it against table TRDIR before SUMBIT. I recently had to do a similar check before SUBMIT, so this is how I did it:
Calling Program
............................ .....................
read table lt_zft_buff_vers into ls_vers index 1.
ev_prog_name = ls_vers-prog_name.
" Config was found - now check if the program name is valid and it is Type '1'
if zcl_f_buff_config=>check_veh_prog_name( ev_prog_name ) is not initial. "<---- check
ev_prog_name = ls_vers-vr_abap_name.
submit (ev_prog_name)
with pa_bukrs eq pa_bukrs
with pa_email eq pa_email
with pa_herm eq pa_herm
with pa_msg1 eq pa_msg1
with pa_msg2 eq pa_msg2
with pa_optio eq pa_optio
with pa_mthyr eq pa_mthyr
and return.
else.
" Program not found in program directory - (could be a typo in the customizing table)
" OR the program name entered is not an executable program (Type '1')
" we handle this here so that it does not short-dump
message a011(zf_vr_messages)
with ev_prog_name
raising program_not_found.
endif.
Method
method check_veh_prog_name.
" RV_EXIST = X -> program exists and program type = '1' (Executable)
" RV_EXIST = space -> program does not exist or program type <> '1'
data: ls_trdir type trdir.
select single * from trdir into ls_trdir
where name = iv_program.
check sy-subrc = 0.
check ls_trdir-subc = '1'.
rv_exist = lcl_gc=>gc_true.
endmethod.
Hope this helps.
Cheers,
Sougata.
02-26-2009 5:04 AM
Hi,
try like this
submit <report> with <parameters> and return.
CATCH <exceptions>.
Regards,
Jyothi CH.