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: 

CLEANUP issue

sunilsankar
Explorer
0 Kudos
427

Hello All,

Question, Class A has super class B. A method defined in B is called in A which has an exception raised. If we use cleanup statement in class A will the exception is cleared.

Code is like this:

  Class A:

  Try.

  Call Method B1

  Clean up.

  EndTry.

Class B:

  Try.

   If sy-subrc NE 0.

     raise exception type cx_os_object_not_found

      ----------

   Endtry.

Please provide your thoughts. Currently it dumps with UNCAUGHT_EXCEPTION.

1 ACCEPTED SOLUTION

Tomas_Buryanek
Active Contributor
0 Kudos
178

You are missing CATCH exception in "outer" TRY - ENDTRY (in class A).

EDIT: Matthew was faster 🙂

-- Tomas --
5 REPLIES 5

SwadhinGhatuary
Active Contributor
0 Kudos
178

Hi ,

share actual code instead of pseudo code which is bit confusing.

0 Kudos
178

Here you go:

In Class - CA_PT_ARQ_DEDUCTION


At line 90 method pm_load_and_set_attributes is called which is implemented in Super class CB_PT_ARQ_DEDUCTION.


TRY.
CALL METHOD pm_load_and_set_attributes
EXPORTING
i_business_key = business_key.
CLEANUP.
CALL METHOD os_internal_undo.
CALL METHOD os_clear_current.
CLEAR current_special_object_info.
ENDTRY.


In method - pm_load_and_set_attributes, an exception
cx_os_object_not_found is raised at line 60

* * 2. Load from Database
try.
append BUSINESS_KEY to BUSINESS_KEY_TAB.
call method MAP_LOAD_FROM_DATABASE_KEY
exporting I_BUSINESS_KEY_TAB = BUSINESS_KEY_TAB
receiving result = OBJECT_DATA_TAB.
catch cx_os_db_select into ex_os_db_select.
class cx_os_object_not_found definition load.
raise exception type cx_os_object_not_found
exporting
bkey = ex_os_db_select->bkey
textid = cx_os_object_not_found=>by_bkey.
endtry.





0 Kudos
178

Can I recommend using functional syntax - it's much less verbose. Or are you on a very old version of ABAP?

At line 90 method pm_load_and_set_attributes is called which is implemented in Super class CB_PT_ARQ_DEDUCTION.

TRY.
  pm_load_and_set_attributes( business_key ).

CLEANUP.
  os_internal_undo( ).
  os_clear_current( ).
  CLEAR current_special_object_info.
ENDTRY.


In method - pm_load_and_set_attributes, an exception
cx_os_object_not_found is raised at line 60

* * 2. Load from Database
try.
  append BUSINESS_KEY to BUSINESS_KEY_TAB.
  OBJECT_DATA_TAB = MAP_LOAD_FROM_DATABASE_KEY( BUSINESS_KEY_TAB ).
catch cx_os_db_select into ex_os_db_select.
  class cx_os_object_not_found definition load. "<----- Do you really need this?
  raise exception type cx_os_object_not_found
      exporting
       bkey = ex_os_db_select->bkey
       textid = cx_os_object_not_found=>by_bkey.
endtry.


Cleanup doesn't work in the way you seem to be trying to use it.   The cleanup works in nested trys. If an exception occurs in the inner try that's not caught by in the inner catch, but is caught by the outer catch, then the cleanup will execute.

TRY.

  TRY.

    do something that raises A.

  CATCH B.

    process exception B.

  CLEANUP.

   this will be executed for A.

ENDTRY.

 

CATCH A.

    process exception A.

ENDTRY:

Example here: http://help.sap.com/saphelp_470/helpdata/en/a9/b8eef8fe9411d4b2ee0050dadfb92b/content.htm



Tomas_Buryanek
Active Contributor
0 Kudos
179

You are missing CATCH exception in "outer" TRY - ENDTRY (in class A).

EDIT: Matthew was faster 🙂

-- Tomas --

0 Kudos
178

Thanks for the response.

This is happening in SAP standard code, so can't able to change it accordingly.

Raised an OSS message, unfortunately asked for steps to replicate the issue.

We are trying to see possibility of reproducing the dump but no luck yet.

I will keep you posted on SAP response.