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: 

Problem by using type ABAP_METHDESCR_TAB in class CL_ABAP_OBJECTDESCR

Former Member
0 Kudos

Attribute METHODS of class CL_ABAP_OBJECTDESCR is type to ABAP_METHDESCR_TAB, now we want to create one import parameter in FM to use this associated type.

But in SE37, system error show, the type ABAP_METHDESCR_TAB is unknown when created parameter.

So why this happen? and if we want to create a parameter by using this type, how can we realize? thanks for your kind hlep.!!

1 ACCEPTED SOLUTION

uwe_schieferstein
Active Contributor
0 Kudos

Hello

You did not mention that your function module is RFC-enabled. Since ABAP_METHDESCR_TAB is a <b>complex </b>itab this cannot be used as RFC parameter.

However, there is a very simple trick available: transform your complex itab into an <b>XML string</b>!!!

The following two function module show you how to achieve this:

FUNCTION zus_sdn_abap_type .
*"----------------------------------------------------------------------
*"*"Local Interface:
*"  IMPORTING
*"     VALUE(ID_CLSNAME) TYPE  SEOCLSNAME DEFAULT 'CL_GUI_ALV_GRID'
*"  EXPORTING
*"     VALUE(ET_METHODS) TYPE  ABAP_METHDESCR_TAB
*"----------------------------------------------------------------------

" NOTE: type-pool abap defined in TOP include

* define local data
  DATA:
    ld_xml_string       TYPE string.


* initialization
  REFRESH: et_methods.


" Call RFC function module
  CALL FUNCTION 'ZUS_SDN_ABAP_TYPE_RFC'
    DESTINATION 'NONE'
    EXPORTING
      id_clsname     = id_clsname
    IMPORTING
      ed_xml_methods = ld_xml_string.


" Re-tranfrom XML to complex itab !!!
  CALL TRANSFORMATION id
    SOURCE XML ld_xml_string
    RESULT itab = et_methods.

ENDFUNCTION.

FUNCTION zus_sdn_abap_type_rfc .
*"----------------------------------------------------------------------
*"*"Local Interface:
*"  IMPORTING
*"     VALUE(ID_CLSNAME) TYPE  SEOCLSNAME
*"  EXPORTING
*"     VALUE(ED_XML_METHODS) TYPE  STRING
*"----------------------------------------------------------------------

* define local data
  DATA:
    lo_typedescr    TYPE REF TO cl_abap_typedescr,
    lo_objdescr     TYPE REF TO cl_abap_objectdescr.


* initialization
  CLEAR: ed_xml_methods.

  CALL METHOD cl_abap_objectdescr=>describe_by_name
    EXPORTING
      p_name         = id_clsname
    RECEIVING
      p_descr_ref    = lo_typedescr
    EXCEPTIONS
      type_not_found = 1
      OTHERS         = 2.
  IF sy-subrc <> 0.
*   MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*              WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.

  lo_objdescr ?= lo_typedescr.  " casting


" XML transformation for RFC !!!
  CALL TRANSFORMATION id
    SOURCE itab = lo_objdescr->methods
    RESULT XML ed_xml_methods.

ENDFUNCTION.

Regards

Uwe

5 REPLIES 5

uwe_schieferstein
Active Contributor
0 Kudos

Hello

You have to add the following statement to the global data (<b>TOP </b>include) of your function group:

TYPE-POOLS: abap.

Regards

Uwe

0 Kudos

Thanks Uwe, I had tried this before, add the type group abap to the global data (TOP include) or add it in the FM directly, but neither of these work. still the error message "Type ABAP_METHDESCR is unknown".

0 Kudos

Then I have to create my own structure/type that is same as ABAP_METHDESCR starting with "Z*" and use it in my FM??? No other ways??

uwe_schieferstein
Active Contributor
0 Kudos

Hello

You did not mention that your function module is RFC-enabled. Since ABAP_METHDESCR_TAB is a <b>complex </b>itab this cannot be used as RFC parameter.

However, there is a very simple trick available: transform your complex itab into an <b>XML string</b>!!!

The following two function module show you how to achieve this:

FUNCTION zus_sdn_abap_type .
*"----------------------------------------------------------------------
*"*"Local Interface:
*"  IMPORTING
*"     VALUE(ID_CLSNAME) TYPE  SEOCLSNAME DEFAULT 'CL_GUI_ALV_GRID'
*"  EXPORTING
*"     VALUE(ET_METHODS) TYPE  ABAP_METHDESCR_TAB
*"----------------------------------------------------------------------

" NOTE: type-pool abap defined in TOP include

* define local data
  DATA:
    ld_xml_string       TYPE string.


* initialization
  REFRESH: et_methods.


" Call RFC function module
  CALL FUNCTION 'ZUS_SDN_ABAP_TYPE_RFC'
    DESTINATION 'NONE'
    EXPORTING
      id_clsname     = id_clsname
    IMPORTING
      ed_xml_methods = ld_xml_string.


" Re-tranfrom XML to complex itab !!!
  CALL TRANSFORMATION id
    SOURCE XML ld_xml_string
    RESULT itab = et_methods.

ENDFUNCTION.

FUNCTION zus_sdn_abap_type_rfc .
*"----------------------------------------------------------------------
*"*"Local Interface:
*"  IMPORTING
*"     VALUE(ID_CLSNAME) TYPE  SEOCLSNAME
*"  EXPORTING
*"     VALUE(ED_XML_METHODS) TYPE  STRING
*"----------------------------------------------------------------------

* define local data
  DATA:
    lo_typedescr    TYPE REF TO cl_abap_typedescr,
    lo_objdescr     TYPE REF TO cl_abap_objectdescr.


* initialization
  CLEAR: ed_xml_methods.

  CALL METHOD cl_abap_objectdescr=>describe_by_name
    EXPORTING
      p_name         = id_clsname
    RECEIVING
      p_descr_ref    = lo_typedescr
    EXCEPTIONS
      type_not_found = 1
      OTHERS         = 2.
  IF sy-subrc <> 0.
*   MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*              WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.

  lo_objdescr ?= lo_typedescr.  " casting


" XML transformation for RFC !!!
  CALL TRANSFORMATION id
    SOURCE itab = lo_objdescr->methods
    RESULT XML ed_xml_methods.

ENDFUNCTION.

Regards

Uwe

0 Kudos

Hi Uwe,

I just only marked codes "DESTINATION 'NONE'" in FM to avoid the run time error "The function module "ZUS_SDN_ABAP_TYPE_RFC" cannot be used for 'remote'. And both the FM work, the output table itab is just what I needed. Thank you very much !!!