Archived discussions are read-only. Learn more about SAP Q&A

Try-Catch exceptionin ABAP....

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,

replied

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.

0 View this answer in context
Not what you were looking for? View more on this topic or Ask a question