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

BCS Exceptions

Former Member
0 Likes
2,475

Hi

How to catch BCS Exceptions raised by FM in the calling program.

I tried Sy-subrc but unable to do so.

Can anyone sample code for the same

1 ACCEPTED SOLUTION
Read only

uwe_schieferstein
Active Contributor
0 Likes
1,836

Hello Nihi

Either you catch the BCS exception within the function module (as shown above) or you forward (THROW) the exception to the calling program. In this case you need to define the exception class as exception of the fm interface.

Regards

Uwe

7 REPLIES 7
Read only

Former Member
0 Likes
1,836

Hi Nihi,

Like this...

DATA eo_bcs TYPE REF TO cx_bcs.

TRY.
    " write ur code here....
  CATCH cx_bcs INTO eo_bcs.
    " error handling code...
ENDTRY.

Cheers,

Jose.

Read only

uwe_schieferstein
Active Contributor
0 Likes
1,837

Hello Nihi

Either you catch the BCS exception within the function module (as shown above) or you forward (THROW) the exception to the calling program. In this case you need to define the exception class as exception of the fm interface.

Regards

Uwe

Read only

0 Likes
1,836

HI Uwe and Jose,

I am raising the exception in FM as below.

I am having problem in catching them in the program.

i defined cx_bcs in the FM(Exceptions Tab) too.

DATA eo_bcs TYPE REF TO cx_bcs.

TRY.

" write ur code here....

CATCH cx_bcs INTO eo_bcs.

RAISE eo_bcs.

ENDTRY.

Read only

0 Likes
1,836

HI,

I am raising the exception from custom FM as below.

i have declared cx_bcd uder exceptions tab too and checked exception classes too..

DATA eo_bcs TYPE REF TO cx_bcs.

TRY.

" my process

CATCH cx_bcs INTO eo_bcs.

RAISE eo_bcs.

ENDTRY.

I am calling the FM from my custom program. i am having trouble in coding to catch the exceptions(class-based) raised by the custom FM.

My program is working fine if everythign is alright but getting dump if get any exception from FM.i need to handle those kind of scenarios.

Does any one help me in this regard.

Read only

0 Likes
1,836

Hi

One more thing is when i do source extended check i am getting this message..

The exception CX_BCS is neither caught nor is it declared in the RAISING clause of "FM_SEND_EMAIL".

what does it indicate! any ideas..

Read only

0 Likes
1,836

Hello Nihi

You misunderstood the meaning of defining the class-based exception in the fm signature. Have a look at sample report ZUS_SDN_CX_EXCEPTION_RAISE which demonstrates how to throw and catch class-based exceptions.

Custom function module with class-based exception in its signature:


FUNCTION zus_sdn_cx_exception_raise.
*"----------------------------------------------------------------------
*"*"Local Interface:
*"  IMPORTING
*"     REFERENCE(ID_FLAG) TYPE  BOOLE_D DEFAULT SPACE
*"  RAISING
*"      CX_BCS   " <<< Flag  'Exceptn. Class' checked
*"----------------------------------------------------------------------


  IF ( id_flag = 'X' ).
    " Simulate exception raised by class cl_bcs
    RAISE EXCEPTION TYPE cx_send_req_bcs
      EXPORTING
        error_type = cx_send_req_bcs=>allready_released.
  ENDIF.

  " NOTE: Here we do not catch the exception but throw it,
  "       i.e. the class-based exception is defined at the
  " fm signature which causes the exception to be propagated
  " to the caller.


ENDFUNCTION.

And here is the sample report:


*&---------------------------------------------------------------------*
*& Report  ZUS_SDN_CX_EXCEPTION_RAISE
*&
*&---------------------------------------------------------------------*
*& Thread: BCS Exceptions
*& <a class="jive_macro jive_macro_thread" href="" __jive_macro_name="thread" modifiedtitle="true" __default_attr="1104287"></a>
*&---------------------------------------------------------------------*

REPORT  zus_sdn_cx_exception_raise.


DATA: go_error    TYPE REF TO cx_bcs.

PARAMETERS:
  p_flag  TYPE boole_d  DEFAULT ' '.



START-OF-SELECTION.

BREAK-POINT.

  TRY.
      CALL FUNCTION 'ZUS_SDN_CX_EXCEPTION_RAISE'
        EXPORTING
          id_flag = p_flag.

    CATCH cx_bcs INTO go_error.
      MESSAGE 'Exception Raised -> Thrown -> Caught' TYPE 'I'.
      LEAVE PROGRAM.
  ENDTRY.

  MESSAGE 'No exception raised' TYPE 'S'.

END-OF-SELECTION.

Regards

Uwe

Read only

0 Likes
1,836

God Bless Uwi..

Learnt lesson and resolved my long standing issue.