‎2010 May 05 11:23 AM
Hello,
As my programs miss this functionality (error processing , catch exceptions , generate messages) I would like to learn how to correctly use these things.
Can somebody give me few examples:
a. what kind of messages should be generated if execution of FM has failed
b. raise and process exceptions
c. how to pick up the error.
Thanks
‎2010 May 05 12:30 PM
Suggest search in articles, etc., for "class-based exception handling". It's discussed in newer ABAP manuals, such as ABAP Objects and Official ABAP Programming Guidelines as well as others.
‎2010 May 05 11:33 AM
a. what kind of messages should be generated if execution of FM has failedError messages/ Exceptions are generated if a FM has failed. For ex:
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
filename = l_flname
filetype = 'ASC'
write_field_separator = '#'
TABLES
data_tab = it_excel_dwnld
EXCEPTIONS
file_write_error = 1
no_batch = 2
gui_refuse_filetransfer = 3
invalid_type = 4
no_authority = 5
unknown_error = 6
header_not_allowed = 7
separator_not_allowed = 8
filesize_not_allowed = 9
header_too_long = 10
dp_error_create = 11
dp_error_send = 12
dp_error_write = 13
unknown_dp_error = 14
access_denied = 15
dp_out_of_memory = 16
disk_full = 17
dp_timeout = 18
file_not_found = 19
dataprovider_exception = 20
control_flush_error = 21
OTHERS = 22Above FM you can see the 22 exceptions which can arise while downloading a file is being failed.
b. raise and process exceptionsIF sy-subrc <> 0.
FORMAT COLOR COL_NEGATIVE.
CASE sy-subrc.
WHEN 1.
v_msg = file_write_error.
ENDCASEDisplays messages on screen.
how to pick up the errorYou can double click on the error and diagonise.
‎2010 May 05 11:50 AM
Hi,
If it is a REPORT program, and you want to generate ERROR messages,
collect all the Error message text in an Internal Table like below
wa_bdcmsgtab-pernr = p_summary-pernr.
"Employee Name
wa_bdcmsgtab-empname = p_summary-empname.
"Employee Personnel Subarea
wa_bdcmsgtab-psub = p_summary-psub.
"Get message text
wa_bdcmsgtab-msg = 'No data for BDC upload'(r29).
"Build BDC Message table
APPEND wa_bdcmsgtab TO it_bdcmsgtab.
then display the Internal table as an ALV pop-up or as an REPORT Output.
A single message can be displayed using MESSAGE statement like below:
lets say you hv to handle FM error messages:
then use
case sy-subrc.
when '0'.
MESSAGE i003 WITH 'Error in displaying top-of-page'(i01).
when '1'.
MESSAGE i003 WITH 'Error in displaying header''(i01).
endcase.
ags.
Edited by: ags on May 5, 2010 4:20 PM
‎2010 May 05 12:30 PM
Suggest search in articles, etc., for "class-based exception handling". It's discussed in newer ABAP manuals, such as ABAP Objects and Official ABAP Programming Guidelines as well as others.
‎2010 May 05 12:38 PM
for CLASS based Exception handling:
data OREF type ref to CX_ROOT. "For exception handling
TRY .
modify zht_dbtab FROM TABLE it_dbtab.
CATCH cx_sy_open_sql_db INTO oref.
IF sy-subrc NE 0.
ROLLBACK WORK.
ENDIF.
ENDTRY.
Use IF_MESSAGE~GET_TEXT method of Oref to get text of the ERROR message
ags.