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: 

Any way to catch exceptions from asynchronous call that short dumps?

Former Member
0 Kudos

Hi,

We have a requirement for a program that we know will occasionally short dump under normal conditions. We want to use an asynchronous call to let it plow ahead. To that end I've created a test program that calls a divide by zero func that short dumps. It tests fine because it proceeds afterward. Better yet would be a way to capture some information from the function where the dump happens and raise it to the calling program. Any ideas?

Thanks,

Doug

Example:

REPORT ZJUNK2

data: junkdone TYPE c VALUE space,

write: / 'before'.

CALL FUNCTION 'ZJUNK2'

STARTING NEW TASK 'z_junktask'

PERFORMING junk ON END OF TASK

EXCEPTIONS

communication_failure = 1

system_failure = 2

other_exception = 3.

  • Receive remaining asynchronous replies

wait until junkdone = 'X'.

write: / 'after'.

FORM junk USING taskname.

RECEIVE RESULTS FROM FUNCTION 'ZJUNK2'

EXCEPTIONS

communication_failure = 1

system_failure = 2

other_exception = 3.

junkdone = 'X'.

ENDFORM.

FUNCTION ZJUNK2.

*"----


""Local Interface:

*"----


data: i type i.

i = 1 / 0.

ENDFUNCTION.

1 ACCEPTED SOLUTION

RichHeilman
Developer Advocate
Developer Advocate
0 Kudos

Hey Doug. You need to catch the class exception cx_root in your function, then pass back the message. This will catch a lot of system exceptions, but probably not all.

DATA: junkdone TYPE c VALUE space.
DATA: lv_message TYPE char255.

WRITE: / 'before'.

CALL FUNCTION 'ZJUNK2'
  STARTING NEW TASK 'z_junktask'
  PERFORMING junk ON END OF TASK
  EXCEPTIONS
    communication_failure = 1
    system_failure        = 2
    other_exception       = 3.

* Receive remaining asynchronous replies
WAIT UNTIL junkdone = 'X'.

WRITE: / 'after'.

IF lv_message IS NOT INITIAL.    "<-- Check for error and write message
  WRITE:/ lv_message.
ENDIF.

*&---------------------------------------------------------------------*
*&      Form  junk
*&---------------------------------------------------------------------*
FORM junk USING taskname.


  RECEIVE RESULTS FROM FUNCTION 'ZJUNK2'
       IMPORTING
            e_message = lv_message   "<-- Import the message
       EXCEPTIONS
            communication_failure = 1
            system_failure = 2
            other_exception = 3.

  junkdone = 'X'.

ENDFORM.                    "junk



FUNCTION zjunk2.
*"----------------------------------------------------------------------
*"*"Local Interface:
*"  EXPORTING
*"     VALUE(E_MESSAGE) TYPE  CHAR255
*"----------------------------------------------------------------------

  DATA: lo_exception TYPE REF TO cx_root.
  DATA: i TYPE i.

  TRY.
      i = 1 / 0.
    CATCH cx_root INTO lo_exception.
      e_message = lo_exception->get_text( ).
  ENDTRY.

ENDFUNCTION.

Regards,

Rich Heilman

7 REPLIES 7

RichHeilman
Developer Advocate
Developer Advocate
0 Kudos

Hey Doug. You need to catch the class exception cx_root in your function, then pass back the message. This will catch a lot of system exceptions, but probably not all.

DATA: junkdone TYPE c VALUE space.
DATA: lv_message TYPE char255.

WRITE: / 'before'.

CALL FUNCTION 'ZJUNK2'
  STARTING NEW TASK 'z_junktask'
  PERFORMING junk ON END OF TASK
  EXCEPTIONS
    communication_failure = 1
    system_failure        = 2
    other_exception       = 3.

* Receive remaining asynchronous replies
WAIT UNTIL junkdone = 'X'.

WRITE: / 'after'.

IF lv_message IS NOT INITIAL.    "<-- Check for error and write message
  WRITE:/ lv_message.
ENDIF.

*&---------------------------------------------------------------------*
*&      Form  junk
*&---------------------------------------------------------------------*
FORM junk USING taskname.


  RECEIVE RESULTS FROM FUNCTION 'ZJUNK2'
       IMPORTING
            e_message = lv_message   "<-- Import the message
       EXCEPTIONS
            communication_failure = 1
            system_failure = 2
            other_exception = 3.

  junkdone = 'X'.

ENDFORM.                    "junk



FUNCTION zjunk2.
*"----------------------------------------------------------------------
*"*"Local Interface:
*"  EXPORTING
*"     VALUE(E_MESSAGE) TYPE  CHAR255
*"----------------------------------------------------------------------

  DATA: lo_exception TYPE REF TO cx_root.
  DATA: i TYPE i.

  TRY.
      i = 1 / 0.
    CATCH cx_root INTO lo_exception.
      e_message = lo_exception->get_text( ).
  ENDTRY.

ENDFUNCTION.

Regards,

Rich Heilman

0 Kudos

Thanks Rich, This was what I am looking for. I am an ABAP novice so forgive the simple questions. I ran this and wasn't able to generate the message. I ran in debug and watched the message populate in the function...

CATCH cx_root INTO lo_exception.

e_message = lo_exception->get_text( ). <-- e_message = Divide by Zero here

...

but when I wind up in the callback lv_message is still INITIAL.

FORM junk USING taskname.

RECEIVE RESULTS FROM FUNCTION 'ZJUNK2'

IMPORTING

*e_message = lv_message "<-- Import the message*

EXCEPTIONS

communication_failure = 1

system_failure = 2

other_exception = 3.

junkdone = 'X'. <-- With Break here lv_message = Null

ENDFORM. "junk

Is there something different about callbacks where this isn't being populated?

Thanks,

Doug

0 Kudos

Hey Doug. I was running into that issue when developing that prototype as well. I think it only worked when the variable was global. So make sure that it is and try again.

Regards,

Rich Heilman

0 Kudos

Thanks Rich, That should do it. for the benefit of those reading this later also be sure to RFC enable your called function or expect a bunch of comunication_failure exceptions.

Thanks All!

0 Kudos

Hello everyone,

I too have a similar use case of implementing asynchronous calls. I've defined by FM to be remote enabled. Whatever examples I've seen till now they all use a report to make these calls. Is it not possible to call an FM asynchronously from within a method? I want to do this and at the same time I want to collect a couple of parameters as results. Should the 'RECEIVE... ' statement be written only in FORM? Is yes, then in my case, how do I achieve this from a method? Thank you in advance.

0 Kudos

Hi All,

After looking at the document carefully I've found that we can have a method to receive results. This has solved my problem.

Regards,

Raghavendra D

Sandra_Rossi
Active Contributor
0 Kudos

As Rich says, you definitely can't catch ALL exceptions.

Moreover, when the call is using SUBMIT, asynchronous RFC, CALL TRANSACTION and a few others (when a internal session is started, in fact), you can't catch exceptions from the calling program. You always have to catch exceptions in the internal session where they occur (as Rich did).

These are known behaviors (and already discussed in the forum if you want more information).