2006 Nov 17 2:16 PM
Please explain about thr Try statement.
give some example.
2006 Nov 17 2:18 PM
Basic form
TRY.
Effect
You catch class-based exceptions in the statement block enclosed by the TRY and ENDTRY statements. To catch these exceptions, you define handlers within the specified TRY block. You introduce a handler using a CATCH statement, followed by the exception classes to be caught and the associated handler code. After the CATCH clauses, you can declare a CLEANUP clause. The statements in the latter clause will be executed if an exception is caught outsidethe TRY block. The structure of the TRY block is as follows:
TRY.
... guarded section
CATCH cx11 ... cx1n [INTO ex1].
... handlers for exceptions cx11 to cx1n
CATCH cx21 ... cx2m [INTO ex2].
... handlers for exceptions cx21 bis cx2m
... other handlers
CLEANUP.
... cleanup block
ENDTRY. The TRY block is split into different sections using the CATCH and CLEANUP clauses.
2006 Nov 17 2:18 PM
Hi
Please check this thread
https://forums.sdn.sap.com/click.jspa?searchID=93818&messageID=2288302
It explains many more similar commands also...
2006 Nov 17 2:21 PM
Hi John,
TRY statement is used when you expect some error/exception condition but not sure of which type of error may be present in a code block.
in that case just wrap the code block in <b>TRY</b> ..<b>ENDTRY</b> block
see this sample code.
TRY.
SORT T_ERGEB-MSG_T_SAP_ACTIVITY-ITEM DESCENDING.
DELETE ADJACENT DUPLICATES FROM T_ERGEB-MSG_T_SAP_ACTIVITY-ITEM.
CALL METHOD ZCO_SAP_ACTIVITY_TOMX=>EXECUTE_ASYNCHRONOUS
EXPORTING
OUTPUT = T_ERGEB
CONTROLLER = L_CONTROLLER.
COMMIT WORK.
CATCH CX_AI_SYSTEM_FAULT INTO L_SYS_EXCEPTION.
SY-MSGV1 = L_SYS_EXCEPTION->ERRORTEXT.
SUBRC = 1.
EXIT.
ENDTRY.
Here we are expecting that this code may generate a CX_AI_SYSTEM_FAULT type of exception. to handle this we have written a catch block.
error of type CX_AI_SYSTEM_FAULT will be handled by this catch block
| User | Count |
|---|---|
| 6 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |