cancel
Showing results for 
Search instead for 
Did you mean: 

Function Module to get all feild names in a structure

Former Member
0 Kudos

Hello Friends,

Is there a function module,where i give the structure name and get all the feild names within that structure.

regards

kaushik

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Use FM NAMETAB_GET and pass structure name in parameter for tabname

You will get the complete list of fields with all their attributes.

Revert if u need more.

Edited by: Ankesh on Jan 19, 2009 8:59 PM

former_member209920
Active Participant
0 Kudos

This message was moderated.

Answers (7)

Answers (7)

Former Member
0 Kudos

Hi,

You can use the for run time type descriptor classes to do this :

Here is a simple example :


REPORT  z_assign_comp.

TYPE-POOLS : slis.

include <icon>.

"&   Dynamic Programming ! Using Structure Descriptior Class.          *

DATA: BEGIN OF line OCCURS 0,
        col1 TYPE i,
        col2(10) TYPE c,
        col3 TYPE i,
      END OF line.

FIELD-SYMBOLS : <fs> TYPE ANY.

FIELD-SYMBOLS : <itab_line> TYPE ANY.


DATA : BEGIN OF t_comp OCCURS 0,
        comp(5) TYPE c,
       END OF t_comp.

DATA : l_struc TYPE REF TO cl_abap_structdescr.
DATA : l_typedesc TYPE REF TO cl_abap_typedescr.
DATA : lt_comp TYPE abap_compdescr_tab,
       w_comp LIKE LINE OF lt_comp.


line-col1 = 11.line-col2 = 'SAP'.line-col3 = 33.
APPEND line.

line-col1 = 44.line-col2 = 'P.I.'.line-col3 = 66.
APPEND line.

ASSIGN line TO <itab_line>.


"Call the static method of the structure descriptor describe_by_data
CALL METHOD cl_abap_structdescr=>describe_by_data
  EXPORTING
    p_data      = <itab_line>
  RECEIVING
    p_descr_ref = l_typedesc.

"The method returns a reference of  a type descriptor class therefore we
"need to Cast the type descriptor to a more specific class i.e
"Structure Descriptor.
l_struc ?= l_typedesc.

"Use the Attribute COMPONENTS of the structure Descriptor class to get
"the field names of the structure
lt_comp = l_struc->components.

LOOP AT line.

  WRITE 😕 'Row : ', sy-tabix.

  LOOP AT lt_comp INTO w_comp.

"   Using the ASSIGN component ,assigns a data object to a field symbol.

    ASSIGN COMPONENT w_comp-name OF STRUCTURE line TO <fs>.
    WRITE 😕 w_comp-name, ' ', <fs>.

  ENDLOOP.

ENDLOOP.

Hope this helps.

regards,

Advait

Former Member
0 Kudos

Hi,

Use this FM 'DDIF_FIELDINFO_GET'.

Regards,

Jyothi CH.

Former Member
0 Kudos

Hi,

FM for that..

DB_GET_TABLE_FIELDS

DDIF_NAMETAB_GET

NAMETAB_GET

Former Member
0 Kudos

Hello Kaushik,

FM "NAMETAB_GET " is obselete now,so better use any of the below mentioned options:

1. Table DD03L that stores the field of the structure of Data Dictionary(Put Structure name in the TABNAME field).

OR

2.you can use fm DDIF_FIELDINFO_GET.

OR

3. A link that will be a great help to your query: read the last post in this link...that give you the sample code as well

Pooja

Former Member
0 Kudos

Hi Kaushik,

Use FM NAMETAB_GET and pass the structure name for TABNAME parameter. Return internal table NAMETAB will contain all the fields with attributes.

Regards

Anki

Former Member
0 Kudos

Hi Kaushik,

Use function module KL_TABLE_INFO_GET to get the fields names of a structure/table. Please provide structure name to I_TABNAME import parametes and you will all field details into E_IT_TABFIELDS export parameter.

Thanks,

Vinay

SuhaSaha
Advisor
Advisor
0 Kudos

Hello,

Check the table DD03L. Here you give the table / structure name & get the fieldnames.

Search SDN for further details.

BR,

Suhas