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: 

Function module to get Structure components

Former Member
0 Kudos
1,534

Hi friends,

is there a function module to get structure components,if we give a structure name.

regards

kaushik

4 REPLIES 4

RichHeilman
Developer Advocate
Developer Advocate
0 Kudos
293

Try function module GET_COMPONENT_LIST

Regards,

Rich Heilman

0 Kudos
293

Sample program using the function module.



report zrich_0003.

types: begin of type_item,
       f1(3),
       f2(3),
       f3(3),
       f4(3),
       end of type_item.

types: begin of type_data,
       data(800),
       end of type_data.

data:  lineitems type table of type_item with header line,
       t_output type table of type_data with header line,
       fieldlist type table of rstrucinfo with header line,
       fieldsym  type table of rfieldlist with header line.

data:  syrepid type sy-repid.

data:  fieldname like fieldlist-compname,
       data_line type type_data.

field-symbols : <fs1> type any,
                <fs2> type any.

lineitems-f1 = 'a1'.
lineitems-f2 = 'a2'.
lineitems-f3 = 'a3'.
lineitems-f4 = 'a4'.
append lineitems.

lineitems-f1 = 'b1'.
lineitems-f2 = 'b2'.
lineitems-f3 = 'b3'.
lineitems-f4 = 'b4'.
append lineitems.

lineitems-f1 = 'c1'.
lineitems-f2 = 'c2'.
lineitems-f3 = 'c3'.
lineitems-f4 = 'c4'.
append lineitems.

lineitems-f1 = 'd1'.
lineitems-f2 = 'd2'.
lineitems-f3 = 'd3'.
lineitems-f4 = 'd4'.
append lineitems.

syrepid = sy-repid.

* Gets all of the global data types.
call function 'GET_GLOBAL_SYMBOLS'
     exporting
          program   = syrepid
     tables
          fieldlist = fieldsym.

* gets all of the components of a structure
call function 'GET_COMPONENT_LIST'
     exporting
          program    = syrepid
          fieldname  = 'lineitems'
     tables
          components = fieldlist.

format color 3.

loop at lineitems assigning <fs2> .

  loop at fieldlist.
    fieldname = fieldlist-compname .
    assign component  fieldname  of structure <fs2> to <fs1>.
    concatenate data_line <fs1> into data_line .
  endloop.
  append data_line to t_output.
  clear data_line.
endloop.

loop at t_output.
  write:/ t_output.
endloop.

Regards,

Rich Heilman

Former Member
0 Kudos
293

<b>Hi

Use

FM DDIF_FIELDINFO_GET by giving the structure name/table name,

u will get all field names along with data types and everything.

Regs

Manas Ranjan Panda</b>

Message was edited by:

MANAS PANDA

Former Member
0 Kudos
293

Hi,

I am not sure of any function module. You can use table DD03L. This table contains the details of the fields for a SAP table/ Strucutre. The input to the select statement would be the name of the structure in your case. You can create your own function module.

Select * from DD03L

into <itab>

where tabname = <Structure-name>.

Regards,

Vara