cancel
Showing results for 
Search instead for 
Did you mean: 

raising an exception in a class and losing contents of a table

Former Member
0 Kudos

Hi,

I have instantiated the BADI CRM_ICSS_PRODUCT_REG with the method check consistency. It has import parameters, one changing parameter, and exceptions.

The changing parameter is the standard BAPI return table. The invoking code will only check the return table if the sy-subrc isn't 0.

My problem is that I can fill out the BAPI return table and its contents get returned just fine, unless I raise an exception. If I raise an exception, my table has values in the method but in the invoking method it is empty. I can comment out the raise and see the contents of the return table or I can do the raise and not get the contents. To get the error recognized, I need both.

The code is

append lh_return to ct_return.

raise not_consistent.

endif.

endmethod.

With a breakpoint at the append, ct_return has one line in it after the append. If I comment out the raise, the invoking method will have that line in its corresponding table. However, if I execute the raise, the table will be empty on return.

Accepted Solutions (0)

Answers (1)

Answers (1)

Former Member
0 Kudos

From the post, I assume that, you want to return the table with the values (why it failed) and at that point, stop processing further in that method.

For this , you should , perhaps use <b>EXIT</b>, instead of raising exceptions.

When you raise an exception, parameters which are passed as EXPORTING, CHANGING, RETURNING are only filled if they are <b>passed with reference</b>. I assume, you are not <b>passing values by reference</b> but <b>by value</b>.

Therefore, the value in the internal table is not captured.

Hope this helps.

Regards,

Subramanian V.

Former Member
0 Kudos

Thank you for the information. I didn't know pass by value parameters wouldn't be filled.

Unfortunately, I don't control the interface so I can't change that. I must get the sy-subrc set to a non-zero value. I can't just set it. The only way I know to do that is to do the raise. The invoking method will only check the return structure if a non-zero sy-subrc is returned.

Is there a way to set the sy-subrc to non-zero without using the raise?

I am not sure that will solve my problem anyway. The wrapper class does a raise if I return a non-zero sy-subrc. I've used the debugger to set the sy-subrc on return and kept the tables only to have them disappear when the wrapper class raises the exception

Former Member
0 Kudos

Hi Deborah,

Well now you do know.

You can do this :

a) Fill the table and use the <b>EXIT</b> statement as I had said in my earlier post.

b) If , you cannot do a, use


EXPORT BAPIRETURNTABLE TO MEMORY ID 'TABLE'.

and then do an IMPORT to recover that table.

For more information regarding usage of EXPORT/IMPORT , refer

http://help.sap.com/saphelp_46c/helpdata/en/d3/2e974d35c511d1829f0000e829fbfe/frameset.htm

BC- ABAP Programming -> ABAP Programming Language -> Saving Data Externally -> Saving Data Objects as Clusters

-> Data Clusters in ABAP Memory

However, if I were you, I would use <b>option 1</b> and try to <b>avoid option 2</b> as far as possible.

Regards,

Subramanian V.