Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

How to get text of exception in my program, exception is defined in FM?

Former Member
0 Kudos

I have written a function module where i have defined a couple of exceptions. If an error occurrs i raise the exception.

My issue is, in my calling program, i call the function module i have created and once the exception occurrs i need to get the text associated with that exception.

I dont know how to get the text of the exception. The short text is defined in exception tab of the function module.

Any help will be appreciated.

Thanks

7 REPLIES 7

Former Member
0 Kudos

Hi,

Use the FM format_message to this pass the errorr number or

after the FM you have used

if sy-subrc ne 0.

Message '......' with w_fiedname.// here declare the w_fieldname as char ot string type to have the text for that

generated exception or error number

endif.

check the ABAPDOCU on MESSAGE

DATA msgtext(72).

..

MESSAGE E004 WITH 'Hugo' INTO msgtext.

or

or

Uncomment the MESSAGE in the sy-surc cheking of the Fm, in that we have

MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

these are the varibles SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4 that contain the text message

Thanks & Regards,

Chandralekha.

Former Member
0 Kudos

hi check this example..

RECEIVE RESULTS FROM FUNCTION 'ZMARD_DATA'

IMPORTING

E_RECORDS = g_records

EXCEPTIONS

no_data = 1

open_dataset_no_authority = 2

convt_codepage_init = 3

dataset_too_many_files = 4

unknown_file_opening_error = 5

dataset_write_error = 6

dataset_not_open = 7

dataset_cant_close = 8

OTHERS = 9.

CASE sy-subrc.

WHEN 0.

error_rec-msg_text = 'Data Loaded'.

g_total_rec = g_total_rec + g_records.

WHEN 1.

error_rec-msg_text = c_no_data.

WHEN 2.

error_rec-msg_text = 'OPEN_DATASET_NO_AUTHORITY'.

WHEN 3.

error_rec-msg_text = 'CONVT_CODEPAGE_INIT'.

WHEN 4.

error_rec-msg_text = 'DATASET_TOO_MANY_FILES'.

WHEN 5.

error_rec-msg_text = 'UNKNOWN_FILE_OPENING_ERROR'.

WHEN 6.

error_rec-msg_text = 'DATASET_WRITE_ERROR'.

WHEN 7.

error_rec-msg_text = 'DATASET_NOT_OPEN'.

WHEN 8.

error_rec-msg_text = 'DATASET_CANT_CLOSE'.

WHEN 9.

error_rec-msg_text =

'Unknown error calling FM : ZMIO_GET_MARD_DATA'.

ENDCASE.

vinod_vemuru2
Active Contributor
0 Kudos

Hi,

Check the table FUNCT.

Pass FM name in field FUNCNAME,

Exception name in field PARAMETER

hardcoded value 'X' to field KIND

U will recieve the short text in field STEXT.

If u have multiple versions of FM(Changes to short text of exceptions) then u have to pass version number also to get the current text.

Hope it is clear.

Thanks,

Vinod.

Former Member
0 Kudos

hiiii

just take a case for sy-subrc for that FM

like

CASE sy-subrc.

when 1.

w_error = 'No_data Exist..'.

write w_error.

when 2.

w_error = ' '..

write w_error.

ENDCASE.

regards

twinkal

Former Member
0 Kudos

CALL FUNCTION

EXPORTING

IMPORTING

EXCEPTIONS

LOCK_ON_MARC = 1

LOCK_SYSTEM_ERROR = 2

WRONG_CALL = 3

NOT_FOUND = 4

OTHERS = 5

IF sy-subrc <> 0.

MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

write case for exception messages in function module.

case sy-subrc.

when 1.

error = 'error'.

....

...

...

..

.

.

.

.

.

when n.

error = 'last'.

Former Member
0 Kudos

I figured it out my self.

Thanks

0 Kudos

i am facing the same issue could please explain your way to get the text??