2008 Oct 06 7:44 PM
I have a custom Function Module which has 3 different exceptions in it's exceptions section. I need to get the text for the raised exception in the caller program, how to do that ?
here is a sample call to the FM:
call function 'ZGET_YEAR'
exporting
pernr = l_pernr
importing
year = l_year
exceptions
emp_not_valid = 1
year_not_found = 2
others = 3.
Now, if the emp_not_valid is raised by the FM then I need to get the text stored in that exception.
Appreciate any inputs on it. Thank you.
2008 Oct 06 8:27 PM
Hello
It seems you are having a wrong perception of exception handling of function modules.
Basically you have to define the messages sent with the exceptions yourself, e.g.:
FUNCTION ZGET_YEAR.
...
IF ( PERNR is not valid ).
MESSAGE e398(00) with 'PersNr' pernr 'not valid'
RAISING emp_not_valid.
ENDIF.
ENDFUNCTION.
The error message is stored in the corresponding syst variables. In order to get the long version of the error message you can use fm BALW_BAPIRETURN_GET2.
call function 'ZGET_YEAR'
exporting
pernr = l_pernr
importing
year = l_year
exceptions
emp_not_valid = 1
year_not_found = 2
others = 3.
IF ( syst-subrc NE 0 ).
data: ls_return TYPE bapiret2.
CLEAR: ls_return.
" ls_return-id = syst-msgid.
" ls_return-type = syst-msgty.
" ls_return-number = syst.-msgno.
ls_return-message_v1 = syst-msgv1.
ls_return-message_v2 = syst-msgv2.
ls_return-message_v3 = space.
ls_return-message_v4 = space.
CALL FUNCTION 'BALW_BAPIRETURN_GET2'
EXPORTING
type = syst-msgty
cl = syst-msgid
number = syst-msgno
par1 = ls_return-message_v1
par2 = ls_return-message_v2
par3 = ls_return-message_v3
par4 = ls_return-message_v4
* LOG_NO = ' '
* LOG_MSG_NO = ' '
* PARAMETER = ' '
* ROW = 0
* FIELD = ' '
IMPORTING
return = ls_return.
MESSAGE ls_return-message TYPE ls_return-type.
ENDIF.
Regards
Uwe
2008 Oct 06 7:47 PM
Use the standard SY variables for the message data in the calling program
2008 Oct 06 7:54 PM
2008 Oct 06 7:59 PM
2008 Oct 06 8:02 PM
2008 Oct 06 8:04 PM
It is giving me...
I have tried with the
FM: GUI_DOWNLOAD
Exception: ACCESS_DENIED
Language: EN
And I got:
Access to File Denied
Check if there is any typo..
Regards,
Naimesh Patel
2008 Oct 06 8:10 PM
oh ok that way by passing the exception name? The coding standards here ask to use the exception number for everything. Nobody else has used any exception.
Is there a way to get it done through SY-SUBRC ?
2008 Oct 06 8:24 PM
Based on the SY-SUBRC, First you have to select the Exception Name from the table FUPARAREF.
Enter:
FUNCNAME = fm
PARAMTYPE = 'X'
PPOSITION = SY-SUBRC.
Get the PARAMETER (which is the exception)
Put it into the FM SWO_TEXT_FUNCTION_EXCEPTION and get the Text.
Regards,
Naimesh Patel
2008 Oct 06 8:38 PM
In the connection with the Uwe's answer, you can use the MESSAGE .. INTO L_TEXT to avoid using the FM 'BALW_BAPIRETURN_GET2'.
data: l_file type string,
t_data type standard table of t001,
lf_message type string.
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
filename = l_File
tables
data_tab = t_data
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 = 22
.
IF sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
into lF_MESSAGE " <<
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
message lf_message type sy-msgty .
ENDIF.
Regards,
Naimesh Patel
2008 Oct 06 7:47 PM
Check table FUNCT.
Pass FUNCNAME = your FM name
PARAMETER = Exception
STEXT = Exception Text
Regards,
Naimesh Patel
2008 Oct 06 7:53 PM
2008 Oct 06 8:27 PM
Hello
It seems you are having a wrong perception of exception handling of function modules.
Basically you have to define the messages sent with the exceptions yourself, e.g.:
FUNCTION ZGET_YEAR.
...
IF ( PERNR is not valid ).
MESSAGE e398(00) with 'PersNr' pernr 'not valid'
RAISING emp_not_valid.
ENDIF.
ENDFUNCTION.
The error message is stored in the corresponding syst variables. In order to get the long version of the error message you can use fm BALW_BAPIRETURN_GET2.
call function 'ZGET_YEAR'
exporting
pernr = l_pernr
importing
year = l_year
exceptions
emp_not_valid = 1
year_not_found = 2
others = 3.
IF ( syst-subrc NE 0 ).
data: ls_return TYPE bapiret2.
CLEAR: ls_return.
" ls_return-id = syst-msgid.
" ls_return-type = syst-msgty.
" ls_return-number = syst.-msgno.
ls_return-message_v1 = syst-msgv1.
ls_return-message_v2 = syst-msgv2.
ls_return-message_v3 = space.
ls_return-message_v4 = space.
CALL FUNCTION 'BALW_BAPIRETURN_GET2'
EXPORTING
type = syst-msgty
cl = syst-msgid
number = syst-msgno
par1 = ls_return-message_v1
par2 = ls_return-message_v2
par3 = ls_return-message_v3
par4 = ls_return-message_v4
* LOG_NO = ' '
* LOG_MSG_NO = ' '
* PARAMETER = ' '
* ROW = 0
* FIELD = ' '
IMPORTING
return = ls_return.
MESSAGE ls_return-message TYPE ls_return-type.
ENDIF.
Regards
Uwe
2008 Oct 06 11:10 PM
Uwe, you seem to have got my problem. I have never used the exceptions like this before. This is first time I need the text of the exception, which I thought would be a couple of statements away.
Nimaish, your solution did not work. It will not fetch the text stored in Exception. Like when you go to SE37 and define exception for the FM, on exceptions tabm, you give some Short Text and Long Text. I needed that Short Text.
I will be changing the FM to not throw exception. I will pass the text like 'Year not valid' from within the FM as an expotr parameter.
2008 Oct 07 12:44 AM
At first point of time, I thought you are accustomed with the Exception Handling and you want to read the text of the Exception to avoid givig the speicifc message. So, I have suggested the Function Module Tables which stores the information.
Anyways, I have created a Small Tutorial on : [Function Module Exception Handling|http://help-abap.blogspot.com/2008/10/function-module-exception-handling.html] on my professional blog.
Regards,
Naimesh Patel
2014 May 15 9:18 AM
I had the same question today and the blog above is not available anymore.
So I searched myself and found table FUBAREF.
Example:
SELECT SINGLE parameter FROM fupararef
INTO sy_text
WHERE funcname = 'EPS2_GET_DIRECTORY_LISTING'
AND paramtype = 'X'
AND pposition = sy-subrc.
(I am on a SAP 7.31)