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

pass on the exception when i use class methods

former_member383962
Participant
0 Likes
1,467

Hello experts,

Here i have a table with single column which contains "views name". Based on the view name I tried to create a table.

Code:


loop itab into wa.
lv_vname = wa-view_name.
* Get a structure of view name 

    ro_struc_descr ?= cl_abap_typedescr=>describe_by_name( lv_vname ).
    lt_comp = ro_struc_descr->get_components( ).
    APPEND LINES OF lt_comp TO lt_tot_comp.

* Create new type from component table
    lo_new_type = cl_abap_structdescr=>create( lt_tot_comp ).

* Create new table type
    lo_table_type = cl_abap_tabledescr=>create( lo_new_type ).

* Create dynamic internal table and assign to Field Symbol
    CREATE DATA w_tref TYPE HANDLE lo_table_type.

<---some logic---------->
endloop.

from the above code, "lv_vname" is a view name.

suppose if my table has a invalid view name means my program through the dump error.

error:

EXCEPTION CONDITION " Type_NOT_Found"

it won't process other values.

i want to capture that error and except that i want to process all the data to create dynamic table.

Any suggestions please...

Thanks in advance

1 ACCEPTED SOLUTION
Read only

Muthu_raja
Active Participant
1,135

Hi,

If the method has any exception, you can catch the exception by below format.

ro_struc_descr ?= cl_abap_typedescr=>describe_by_name( lv_vname ).

Replace above one with below one,

    cl_abap_typedescr=>describe_by_name( exporting p_name           = lv_vname
                                         receiving p_descr_ref      = ro_struc_descr
                                         exceptions type_not_found  = 1
                                                    others          = 2              ).
    if ( sy-subrc <> 0 ).
        " process your exception
    else.
        " main logic when subrc eq 0
    endif.

Thanks..

Hi,

If the method has any exception, you can catch the exception by below format.

ro_struc_descr ?= cl_abap_typedescr=>describe_by_name( lv_vname ).

Replace above one with below one,

    cl_abap_typedescr=>describe_by_name( exporting p_name           = lv_vname
                                         receiving p_descr_ref      = ro_struc_descr
                                         exceptions type_not_found  = 1
                                                    others          = 2              ).
    if ( sy-subrc <> 0 ).
        " process your exception
    else.
        " main logic when subrc eq 0
    endif.

Thanks..

2 REPLIES 2
Read only

Muthu_raja
Active Participant
1,136

Hi,

If the method has any exception, you can catch the exception by below format.

ro_struc_descr ?= cl_abap_typedescr=>describe_by_name( lv_vname ).

Replace above one with below one,

    cl_abap_typedescr=>describe_by_name( exporting p_name           = lv_vname
                                         receiving p_descr_ref      = ro_struc_descr
                                         exceptions type_not_found  = 1
                                                    others          = 2              ).
    if ( sy-subrc <> 0 ).
        " process your exception
    else.
        " main logic when subrc eq 0
    endif.

Thanks..

Read only

RaymondGiuseppi
Active Contributor
1,135

What did you try, from try/catch/endtry wrapping the call to use of addition exceptions in the method call?