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: 

Get the values from Exception class

Former Member
0 Kudos
2,564

Hi all ..

In class i have raised one exception

when i catch this exception in my program i m able to get the

error message but i need to get all the parameters that i pass

when i raise the exception ...

i have raised like this

RAISE EXCEPTION TYPE cx_bapi_error

EXPORTING

textid = cx_bapi_error=>cx_bo_error

class_name = 'ZHS_'

log_no = wa_bapi_return-log_no

log_msg_no = wa_bapi_return-log_msg_no

t100_msgid = wa_bapi_return-id

t100_msgno = wa_bapi_return-number

t100_msgv1 = wa_bapi_return-message_v1

t100_msgv2 = wa_bapi_return-message_v2

t100_msgv3 = wa_bapi_return-message_v3

t100_msgv4 = wa_bapi_return-message_v4

STATUS = lt_status

.

and caught the exception like this in my program

CATCH cx_bapi_error INTO go_error.

gd_text = go_error->get_text( ).

EXIT.

ENDTRY.

in this i m just getting the class name which i have passed in exception

i need all other parameters that i have passed ..

if u have any idea pls let me know ..

Thanks in advance ...

1 ACCEPTED SOLUTION

uwe_schieferstein
Active Contributor
0 Kudos
594

Hello Jayakumar

Usually the attributes of standard exception classes are defines as <b>public</b> and <b>read-only</b>. Thus, you should be able to use the following coding:

DATA:
  go_error   TYPE REF TO cx_bapi_error.  " specific exception class !!!

TRY.
RAISE EXCEPTION TYPE cx_bapi_error
EXPORTING
textid = cx_bapi_error=>cx_bo_error
class_name = 'ZHS_'
log_no = wa_bapi_return-log_no
log_msg_no = wa_bapi_return-log_msg_no
t100_msgid = wa_bapi_return-id
t100_msgno = wa_bapi_return-number
t100_msgv1 = wa_bapi_return-message_v1
t100_msgv2 = wa_bapi_return-message_v2
t100_msgv3 = wa_bapi_return-message_v3
t100_msgv4 = wa_bapi_return-message_v4
STATUS = lt_status.

CATCH cx_bapi_error INTO go_error.
gd_text = go_error->get_text( ).

WRITE: go_error->t100_msgid,  " perhaps the attributes have different name
            go_error->t100_msgno, " check attribute names in SE24
            ...
EXIT.
ENDTRY.

Regards

Uwe

3 REPLIES 3

Former Member
0 Kudos
594

Hello Jayakumar,

In the exception class, under attributes create instance attributes with the same name as you are passing from the program (class_name, log_no etc) under raising statement.

Then in the cx_bo_error exception text, add the attributes between && (e.g. &class_name&, &log_no&) in the order you want them to be displayed.

Award points if found useful.

Regards

Indrajit

thomasalexander_ritter
Active Contributor
0 Kudos
594

Hi,

I would create private class attributes for all your parameters. Set the attributes in the constructor of your exception. Then create getter methods for the different parameters. This makes it very easy to access the parameters.

cheers

Thomas

uwe_schieferstein
Active Contributor
0 Kudos
595

Hello Jayakumar

Usually the attributes of standard exception classes are defines as <b>public</b> and <b>read-only</b>. Thus, you should be able to use the following coding:

DATA:
  go_error   TYPE REF TO cx_bapi_error.  " specific exception class !!!

TRY.
RAISE EXCEPTION TYPE cx_bapi_error
EXPORTING
textid = cx_bapi_error=>cx_bo_error
class_name = 'ZHS_'
log_no = wa_bapi_return-log_no
log_msg_no = wa_bapi_return-log_msg_no
t100_msgid = wa_bapi_return-id
t100_msgno = wa_bapi_return-number
t100_msgv1 = wa_bapi_return-message_v1
t100_msgv2 = wa_bapi_return-message_v2
t100_msgv3 = wa_bapi_return-message_v3
t100_msgv4 = wa_bapi_return-message_v4
STATUS = lt_status.

CATCH cx_bapi_error INTO go_error.
gd_text = go_error->get_text( ).

WRITE: go_error->t100_msgid,  " perhaps the attributes have different name
            go_error->t100_msgno, " check attribute names in SE24
            ...
EXIT.
ENDTRY.

Regards

Uwe