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

Exception handling for a standard SAP Function Module - the OO way

Former Member
0 Likes
18,328

Hello,

I was wondering what is the correct way to call a standard SAP function module inside a method of global class.

I want to display the error via the:

get_text( ) and get_longtext( ) methods.

I don't want to use the sy-subrc check. Is this possible?

My example doesn't seem to work...

See example bellow:

DATA: ex_object_cx_root TYPE REF TO cx_root,
      ex_text TYPE string,
      ex_text_long TYPE string.
 
 TRY.
      CALL FUNCTION 'L_TO_CONFIRM'
        EXPORTING
          i_lgnum                        = i_lgnum      " Warehouse number
          i_tanum                        = i_tanum      " Transfer order number
          i_quknz                        = '1'          " '1' - confirm withdrawal only (picking )
          i_commit_work                  = 'X'          " Indicator whether COMMIT WORK in function module
        TABLES
          t_ltap_conf                    = it_ltap_conf " Table of items to be confirmed
        EXCEPTIONS
          to_confirmed                   = 1    " Transfer order already confirmed
          to_doesnt_exist                = 2
          item_confirmed                 = 3
          item_subsystem                 = 4
		  ...
          to_item_split_not_allowed      = 51
          input_wrong                    = 52
          OTHERS                         = 53.

    CATCH cx_root INTO ex_object_cx_root.

      ex_text = ex_object_cx_root->get_text( ).
      ex_text_long = ex_object_cx_root->get_longtext( ).

      " Error:
      RAISE EXCEPTION TYPE zcx_transfer_order
        EXPORTING textid = zcx_transfer_order=>zcx_transfer_order
             err_class = 'ZCL_WM_TRANSFER_ORDER'
             err_method = 'CONFIRM_TO_2STEP_PICKING'
             err_message_text = ex_text
             err_message_text_long = ex_text_long.

  ENDTRY.

Thank you very much in advance

1 ACCEPTED SOLUTION
Read only

SuhaSaha
Product and Topic Expert
Product and Topic Expert
0 Likes
6,082

Hello Marko,

If i understand correctly you've enclosed the call to the FM 'L_TO_CONFIRM' inside the TRY ... CATCH ... ENDTRY block.

CATCH cx_root INTO ex_object_cx_root.
 
      ex_text = ex_object_cx_root->get_text( ).
      ex_text_long = ex_object_cx_root->get_longtext( ).

You can't do this because the FM 'L_TO_CONFIRM' doesn't propagate OO exceptions!

Your approach is almost correct, what you've to do is goes like this:

CALL FUNCTION 'L_TO_CONFIRM'
  EXPORTING
    i_lgnum                        = i_lgnum      " Warehouse number
    i_tanum                        = i_tanum      " Transfer order number
    i_quknz                        = '1'          " '1' - confirm withdrawal only (picking )
    i_commit_work                  = 'X'          " Indicator whether COMMIT WORK in function module
  TABLES
    t_ltap_conf                    = it_ltap_conf " Table of items to be confirmed
  EXCEPTIONS
    to_confirmed                   = 1    " Transfer order already confirmed
    to_doesnt_exist                = 2
    item_confirmed                 = 3
    item_subsystem                 = 4
...
    to_item_split_not_allowed      = 51
    input_wrong                    = 52
    OTHERS                         = 53.

IF sy-subrc <> 0.
  MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
          WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4
          INTO ex_text. "Get the ex_text by this technique & not by CX_ROOT->GET_TEXT()
ENDIF.

I'll have to check how to fetch the long text of the message

BR,

Suhas

5 REPLIES 5
Read only

SuhaSaha
Product and Topic Expert
Product and Topic Expert
0 Likes
6,083

Hello Marko,

If i understand correctly you've enclosed the call to the FM 'L_TO_CONFIRM' inside the TRY ... CATCH ... ENDTRY block.

CATCH cx_root INTO ex_object_cx_root.
 
      ex_text = ex_object_cx_root->get_text( ).
      ex_text_long = ex_object_cx_root->get_longtext( ).

You can't do this because the FM 'L_TO_CONFIRM' doesn't propagate OO exceptions!

Your approach is almost correct, what you've to do is goes like this:

CALL FUNCTION 'L_TO_CONFIRM'
  EXPORTING
    i_lgnum                        = i_lgnum      " Warehouse number
    i_tanum                        = i_tanum      " Transfer order number
    i_quknz                        = '1'          " '1' - confirm withdrawal only (picking )
    i_commit_work                  = 'X'          " Indicator whether COMMIT WORK in function module
  TABLES
    t_ltap_conf                    = it_ltap_conf " Table of items to be confirmed
  EXCEPTIONS
    to_confirmed                   = 1    " Transfer order already confirmed
    to_doesnt_exist                = 2
    item_confirmed                 = 3
    item_subsystem                 = 4
...
    to_item_split_not_allowed      = 51
    input_wrong                    = 52
    OTHERS                         = 53.

IF sy-subrc <> 0.
  MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
          WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4
          INTO ex_text. "Get the ex_text by this technique & not by CX_ROOT->GET_TEXT()
ENDIF.

I'll have to check how to fetch the long text of the message

BR,

Suhas

Read only

Former Member
0 Likes
6,082

Thank you for fast response.

a) How do you know which standard SAP FM does propagate OO exceptions and which doesn't?

b) If you know how to fetch the long text - that would be superb.

Read only

SuhaSaha
Product and Topic Expert
Product and Topic Expert
0 Likes
6,082

> a) How do you know which standard SAP FM does propagate OO exceptions and which doesn't?

Check in the "Exceptions" tab, "Exception Class" checkbox is not checked.

b) If you know how to fetch the long text - that would be superb.

You can get the long text using DOCU_GET_FOR_F1HELP FM.

BR,

Suhas

Read only

Former Member
0 Likes
6,082

Halo Marko,

One thing you could do is to have an exception object as an exporting parameter in the FM.

if there is an exception condition you can fill that exception object inside the FM.

So you call the Fm and get back the exception object.

call FM

importing e_exception = lx_exception.

if lx_exception is bound.

lx_exception->get_Text( ).

lx_exception->get_long_text( ).

endif.

Regards

Arshad

Read only

0 Likes
6,082

Thank you both for your answers!