02-08-2008 10:45 AM
hi experts,
how to create exeptions in function module i want step by step.
regards,
chaitu
02-08-2008 11:58 AM
hi,
Raising Exceptions
There are two ABAP statements for raising exceptions. They can only be used in function modules:
RAISE except.
und
MESSAGE.....RAISING except.
The effect of these statements depends on whether the calling program handles the exception or not. The calling program handles an exception If the name of the except exception or OTHERS is specified after the EXCEPTION option of the CALL FUNCTION statement.
If the calling program does not handle the exception
· The RAISEstatement terminates the program and switches to debugging mode.
· The MESSAGE..... RAISING statement displays the specified message. Processing is continued in relation to the message type.
If the calling program handles the exception, both statements return control to the program. No values are transferred. The MESSAGE..... RAISING statement does not display a message. Instead, it fills the system fields sy-msgid, sy-msgty, sy-msgno , and SY-MSGV1 to SY-MSGV4.
Source Code of READ_SPFLI_INTO_TABLE
The entire source code of READ_SPFLI_INTO_TABLE looks like this:
FUNCTION read_spfli_into_table.
*"----
-
""Local Interface:
*" IMPORTING
*" VALUE(ID) LIKE SPFLI-CARRID DEFAULT 'LH '
*" EXPORTING
*" VALUE(ITAB) TYPE SPFLI_TAB
*" EXCEPTIONS
*" NOT_FOUND
*"----
-
SELECT * FROM spfli INTO TABLE itab WHERE carrid = id.
IF sy-subrc NE 0.
MESSAGE e007(at) RAISING not_found.
ENDIF.
ENDFUNCTION.
The function module reads all of the data from the database table SPFLI where the key field CARRID is equal to the import parameter ID and places the entries that it finds into the internal table spfli_tab. If it cannot find any entries, the exception NOT_FOUND is triggered with MESSAGE ... RAISING. Otherwise, the table is passed to the caller as an exporting parameter.
Calling READ_SPFLI_INTO_TABLE
The following program calls the function module READ_SPFLI_INTO_TABLE:
REPORT demo_mod_tech_fb_read_spfli.
PARAMETERS carrier TYPE s_carr_id.
DATA: jtab TYPE spfli_tab,
wa LIKE LINE OF jtab.
CALL FUNCTION 'READ_SPFLI_INTO_TABLE'
EXPORTING
id = carrier
IMPORTING
itab = jtab
EXCEPTIONS
not_found = 1
OTHERS = 2.
CASE sy-subrc.
WHEN 1.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno.
WHEN 2.
MESSAGE e702(at).
ENDCASE.
LOOP AT jtab INTO wa.
WRITE: / wa-carrid, wa-connid, wa-cityfrom, wa-cityto.
ENDLOOP.
The actual parameters carrier and jtab have the same data types as their corresponding interface parameters in the function module. The exception NOT_FOUND is handled in the program. It displays the same message that the function module would have displayed had it handled the error.
Hope this is helps,Do reward.
02-08-2008 11:04 AM
02-08-2008 11:58 AM
hi,
Raising Exceptions
There are two ABAP statements for raising exceptions. They can only be used in function modules:
RAISE except.
und
MESSAGE.....RAISING except.
The effect of these statements depends on whether the calling program handles the exception or not. The calling program handles an exception If the name of the except exception or OTHERS is specified after the EXCEPTION option of the CALL FUNCTION statement.
If the calling program does not handle the exception
· The RAISEstatement terminates the program and switches to debugging mode.
· The MESSAGE..... RAISING statement displays the specified message. Processing is continued in relation to the message type.
If the calling program handles the exception, both statements return control to the program. No values are transferred. The MESSAGE..... RAISING statement does not display a message. Instead, it fills the system fields sy-msgid, sy-msgty, sy-msgno , and SY-MSGV1 to SY-MSGV4.
Source Code of READ_SPFLI_INTO_TABLE
The entire source code of READ_SPFLI_INTO_TABLE looks like this:
FUNCTION read_spfli_into_table.
*"----
-
""Local Interface:
*" IMPORTING
*" VALUE(ID) LIKE SPFLI-CARRID DEFAULT 'LH '
*" EXPORTING
*" VALUE(ITAB) TYPE SPFLI_TAB
*" EXCEPTIONS
*" NOT_FOUND
*"----
-
SELECT * FROM spfli INTO TABLE itab WHERE carrid = id.
IF sy-subrc NE 0.
MESSAGE e007(at) RAISING not_found.
ENDIF.
ENDFUNCTION.
The function module reads all of the data from the database table SPFLI where the key field CARRID is equal to the import parameter ID and places the entries that it finds into the internal table spfli_tab. If it cannot find any entries, the exception NOT_FOUND is triggered with MESSAGE ... RAISING. Otherwise, the table is passed to the caller as an exporting parameter.
Calling READ_SPFLI_INTO_TABLE
The following program calls the function module READ_SPFLI_INTO_TABLE:
REPORT demo_mod_tech_fb_read_spfli.
PARAMETERS carrier TYPE s_carr_id.
DATA: jtab TYPE spfli_tab,
wa LIKE LINE OF jtab.
CALL FUNCTION 'READ_SPFLI_INTO_TABLE'
EXPORTING
id = carrier
IMPORTING
itab = jtab
EXCEPTIONS
not_found = 1
OTHERS = 2.
CASE sy-subrc.
WHEN 1.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno.
WHEN 2.
MESSAGE e702(at).
ENDCASE.
LOOP AT jtab INTO wa.
WRITE: / wa-carrid, wa-connid, wa-cityfrom, wa-cityto.
ENDLOOP.
The actual parameters carrier and jtab have the same data types as their corresponding interface parameters in the function module. The exception NOT_FOUND is handled in the program. It displays the same message that the function module would have displayed had it handled the error.
Hope this is helps,Do reward.
02-11-2008 4:32 AM
u just have to decide what exceptions u want and under what conditions.
then declarethese exeptions under the exceptions tab.
in the source code of ur function module.
if <condition eg. when su-ucomm = 3>
raise <excep1>
.
.
.
like this u can code .
now when u call the function module in tme mainprogram.
if some error occurs and u have declared a exception for this then it will set sy-subrc = value u give inthe call of this fm.
in the fm u can program these sy-subrc values and trigger the code for ur exception.
refer to any std fm.
u will get an idea.