10-09-2007 4:26 AM
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.!!
10-09-2007 9:46 PM
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
10-09-2007 5:28 AM
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
10-09-2007 6:45 AM
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".
10-09-2007 7:42 AM
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??
10-09-2007 9:46 PM
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
10-10-2007 4:39 AM
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 !!!