Application Development and Automation 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: 
Read only

Try and Catch

Former Member
0 Likes
923

Hi experts,

I am trying to catch the exception CX_SY_REF_IS_INITIAL.

The current syntax are as below :-

DATA: lr_view_manager TYPE REF TO cl_bsp_wd_view_manager

, lr_cucobdc TYPE REF TO cl_crm_ic_cucobdc_impl.

lr_view_manager ?= zl_2007_ic_tools_impl=>get_view_manager( ).

lr_cucobdc ?= lr_view_manager->get_custom_controller( 'CuCoBDC' ).

Currently the statement

lr_cucobdc ?= lr_view_manager->get_custom_controller( 'CuCoBDC' ). is pointing to nothing.

Can anyone show me how to write the codes.

Regards,

JH

1 ACCEPTED SOLUTION
Read only

Former Member
6 REPLIES 6
Read only

Former Member
Read only

0 Likes
863

Hi Shiva,

I've tried the syntax but there are still error. Can you tell me whether this is correct?

TRY

lr_cucobdc ?= lr_view_manager->get_custom_controller( 'CuCoBDC' )

CATCH cx_sy_ref_is_initial.

ENDTRY

Thanks,

JH

Read only

seshatalpasai_madala
Product and Topic Expert
Product and Topic Expert
0 Likes
863

Hi,


DATA: lr_view_manager TYPE REF TO cl_bsp_wd_view_manager
, lr_cucobdc TYPE REF TO cl_crm_ic_cucobdc_impl.

TRY.
lr_view_manager ?= zl_2007_ic_tools_impl=>get_view_manager( ).
lr_cucobdc ?= lr_view_manager->get_custom_controller( 'CuCoBDC' ).
CATCH CX_SY_REF_IS_INITIAL.
 " Code here to handle the exception
ENDTRY.

Regards,

Sesh

Read only

0 Likes
863

Hi Sesh,

I tried the syntax but this error pops out.

TRY.

lr_view_manager ?= zl_2007_ic_tools_impl=>get_view_manager( )

lr_cucobdc ?= lr_view_manager->get_custom_controller( 'CuCoBDC' )

CATCH CX_SY_REF_IS_INITIAL.

If sy-subrc = 0.

ENDTRY.

"out-field?=method" can only be specified once.-----

Can you please advice.

Regards,

JH

Read only

0 Likes
863

Hi,


TRY.
lr_view_manager ?= zl_2007_ic_tools_impl=>get_view_manager( ). " Dot is missing here
lr_cucobdc ?= lr_view_manager->get_custom_controller( 'CuCoBDC' ). " Dot is missing here
CATCH CX_SY_REF_IS_INITIAL.
If sy-subrc = 0.
ENDTRY.

Regards,

Sesh

Read only

Former Member
0 Likes
863

hI

PARAMETERS number TYPE i.

DATA: result TYPE p LENGTH 8 DECIMALS 2,

oref TYPE REF TO cx_root,

text TYPE string.

TRY.

IF ABS( number ) > 100.

RAISE EXCEPTION TYPE cx_demo_abs_too_large.

ENDIF.

PERFORM calculation USING number

CHANGING result

text.

CATCH cx_sy_arithmetic_error INTO oref.

text = oref->get_text( ).

CATCH cx_root INTO oref.

text = oref->get_text( ).

ENDTRY.

IF NOT text IS INITIAL.

WRITE / text.

ENDIF.

WRITE: / 'Final result:', result.

FORM calculation USING p_number LIKE number

CHANGING p_result LIKE result

p_text LIKE text

RAISING cx_sy_arithmetic_error.

DATA l_oref TYPE REF TO cx_root.

TRY.

p_result = 1 / p_number.

WRITE: / 'Result of division:', p_result.

p_result = SQRT( p_number ).

WRITE: / 'Result of square root:', p_result.

CATCH cx_sy_zerodivide INTO l_oref.

p_text = l_oref->get_text( ).

CLEANUP.

CLEAR p_result.

ENDTRY.

ENDFORM.

please see this link for detailed explaination of the TRY & ENDTRY ...

http://help.sap.com/saphelp_nw04/helpdata/en/a9/b8eef8fe9411d4b2ee0050dadfb92b/content.htm

<b>REWARD IF USEFULL</b>