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: 

How to assign values to dynamic table

Former Member
0 Kudos

Hi All,

I am working with a dynamic table and an internal table. My internal table looks like this.

*****************************************************************

Projno Cust Opt Status

g1234 kkkkk p1 I001

g1234 kkkkk p2 I004

g1234 kkkkk p3 I001

g1234 kkkkk p5 I002

g1256 lmnvw p1 I003

g1256 lmnvw p3 I004

g1256 lmnvw p5 I005

g1256 lmnvw p7 I001

***********************************************************

My Dynamic table struture looks like this

Projno Cust p1 p2 p3 p4 p5 p6 p7

I need data in my dynamic table from my internal table as follows

Projno Cust p1 p2 p3 p4 p5 p6 p7

g1234 kkkkk I001 I004 I001 I002

g1256 lmnvw I003 I004 I005 I001.

The problem is these operations may vary thats why i am using dynamic table. Even i cannot use case statement as the operations may vary.

Is it possible to do using Assign component or some other way.

Thanks

3 REPLIES 3

former_member191735
Active Contributor
0 Kudos

This program creates dynamic internal table

copy and paste in your program and test it .. debug it to know how it is creating dynamic internal table and values into that table.

report z_dynamic.

type-pools : abap.

field-symbols: <dyn_table> type standard table,

<dyn_wa>,

<dyn_field>.

data: dy_table type ref to data,

dy_line type ref to data,

xfc type lvc_s_fcat,

ifc type lvc_t_fcat.

&----


selection-screen begin of block b1 with frame.

parameters: p_table(30) type c default 'T001'.

selection-screen end of block b1.

&----


start-of-selection.

perform get_structure.

perform create_dynamic_itab.

perform get_data.

perform write_out.

&----


form get_structure.

data : idetails type abap_compdescr_tab,

xdetails type abap_compdescr.

data : ref_table_des type ref to cl_abap_structdescr.

  • Get the structure of the table.

ref_table_des ?=

cl_abap_typedescr=>describe_by_name( p_table ).

idetails[] = ref_table_des->components[].

loop at idetails into xdetails.

clear xfc.

xfc-fieldname = xdetails-name .

xfc-datatype = xdetails-type_kind.

xfc-inttype = xdetails-type_kind.

xfc-intlen = xdetails-length.

xfc-decimals = xdetails-decimals.

append xfc to ifc.

endloop.

endform.

&----


form create_dynamic_itab.

  • Create dynamic internal table and assign to FS

call method cl_alv_table_create=>create_dynamic_table

exporting

it_fieldcatalog = ifc

importing

ep_table = dy_table.

assign dy_table->* to <dyn_table>.

  • Create dynamic work area and assign to FS

create data dy_line like line of <dyn_table>.

assign dy_line->* to <dyn_wa>.

endform.

&----


form get_data.

  • Select Data from table.

select * into table <dyn_table>

from (p_table).

endform.

&----


form write_out .

  • Write out data from table.

loop at <dyn_table> into <dyn_wa>.

do.

assign component sy-index

of structure <dyn_wa> to <dyn_field>.

if sy-subrc <> 0.

exit.

endif.

if sy-index = 1.

write:/ <dyn_field>.

else.

write: <dyn_field>.

endif.

enddo.

endloop.

endform. " write_out

&----


0 Kudos

Thanks for the reply,

But the problem here is i already has dynamic internal table. I need to fill the dynamic table from my internal table based on the operations which i have in the internal table.

0 Kudos

Try something like this:

LOOP AT ITAB.
  ASSIGN COMPONENT 'PROJ' OF STRUCTURE <F_HEAD> TO <F_FLD>.
  <F_FLD> = ITAB-PROJ.
  ASSIGN COMPONENT 'KUNNR' OF STRUCTURE <F_HEAD> TO <F_FLD>.
  <F_FLD> = ITAB-KUNNR.
  ASSIGN COMPONENT ITAB-OPT OF STRUCTURE <F_HEAD> TO <F_FLD>.
  <F_FLD> = ITAB-STATUS.
  AT END OF KUNNR.
    APPEND <F_HEAD> TO <F_TAB>.
    CLEAR  <F_HEAD>.
  ENDAT.
ENDLOOP.

Regards,

Naimesh Patel