‎2008 Nov 21 1:46 PM
Hi all,
I need one function module for catching field names in a structure.
i am calling that structure as an import parameter in a Function module.
I need to get field names of that structur. is there any function module exists?
Regards,
sarath
‎2008 Nov 21 2:09 PM
Hi,
You can use the structure descriptor class as well. See the code below
REPORT z_struc_describe .
DATA type_desc TYPE REF TO cl_abap_typedescr.
DATA : l_struc TYPE REF TO cl_abap_structdescr.
DATA : lt_comp TYPE abap_compdescr_tab,
w_comp LIKE LINE OF lt_comp.
PARAMETERS : p_table TYPE tabname.
CALL METHOD cl_abap_complexdescr=>describe_by_name
EXPORTING
p_name = p_table
RECEIVING
p_descr_ref = type_desc
* 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.
l_struc ?= type_desc.
lt_comp = l_struc->components.
WRITE : 5 'Field',
25 'Data type',
40 'Length',
50 'Decimals'.
LOOP AT lt_comp INTO w_comp.
WRITE : /5 w_comp-name,
30 w_comp-type_kind,
35 w_comp-length RIGHT-JUSTIFIED ,
45 w_comp-decimals RIGHT-JUSTIFIED .
CLEAR w_comp.
ENDLOOP.
Remember with oops its much faster then using function modules. So go with the oops approach.
regards,
Advait
‎2008 Nov 21 1:54 PM
‎2008 Nov 21 2:00 PM
Hi,
You can write that yourself using DD03L table, or use this FM F4_DD_STRUCTURE_FIELDS.
Regards
Marcin
‎2008 Nov 21 2:09 PM
Hi,
You can use the structure descriptor class as well. See the code below
REPORT z_struc_describe .
DATA type_desc TYPE REF TO cl_abap_typedescr.
DATA : l_struc TYPE REF TO cl_abap_structdescr.
DATA : lt_comp TYPE abap_compdescr_tab,
w_comp LIKE LINE OF lt_comp.
PARAMETERS : p_table TYPE tabname.
CALL METHOD cl_abap_complexdescr=>describe_by_name
EXPORTING
p_name = p_table
RECEIVING
p_descr_ref = type_desc
* 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.
l_struc ?= type_desc.
lt_comp = l_struc->components.
WRITE : 5 'Field',
25 'Data type',
40 'Length',
50 'Decimals'.
LOOP AT lt_comp INTO w_comp.
WRITE : /5 w_comp-name,
30 w_comp-type_kind,
35 w_comp-length RIGHT-JUSTIFIED ,
45 w_comp-decimals RIGHT-JUSTIFIED .
CLEAR w_comp.
ENDLOOP.
Remember with oops its much faster then using function modules. So go with the oops approach.
regards,
Advait
‎2008 Nov 21 2:16 PM
Hello,
Use this FM 'CATSXT_GET_DDIC_FIELDINFO'.
Hope it helps.
Thanks,
Jayant
‎2008 Nov 21 2:54 PM