Application Development and Automation 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: 
Read only

Dynamic Internal table problem

Former Member
0 Likes
901

Hi all,

I created program for creating dynamic internal table as below :

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.

xfc-fieldname = 'LIFNR'.

xfc-datatype = 'C'.

xfc-inttype = 'C'.

xfc-intlen = '10'.

xfc-decimals = '0'.

append xfc to ifc.

xfc-fieldname = 'EBELN'.

xfc-datatype = 'C'.

xfc-inttype = 'C'.

xfc-intlen = '10'.

xfc-decimals = '0'.

append xfc to ifc.

xfc-fieldname = 'MATKL'.

xfc-datatype = 'C'.

xfc-inttype = 'C'.

xfc-intlen = '9'.

xfc-decimals = '0'.

append xfc to ifc.

xfc-fieldname = 'WERKS'.

xfc-datatype = 'C'.

xfc-inttype = 'C'.

xfc-intlen = '4'.

xfc-decimals = '0'.

append xfc to ifc.

xfc-fieldname = 'MATNR'.

xfc-datatype = 'C'.

xfc-inttype = 'C'.

xfc-intlen = '18'.

xfc-decimals = '0'.

append xfc to ifc.

xfc-fieldname = 'MAKTX'.

xfc-datatype = 'C'.

xfc-inttype = 'C'.

xfc-intlen = '40'.

xfc-decimals = '0'.

append xfc to ifc.

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.

The problem now that I am unable to access the fields of internal table as as "<dyn_table>-lifnr" nor the work area as "<dyn_wa>-lifnr" .It says structure does not have the field.

Its also not accessible in the debug mode.

How do I access the field to populate data to the table?

Pls post ur ideas.

Thanks,

stock

10 REPLIES 10
Read only

Former Member
0 Likes
825

Hi

You can only use the field symbol (just as you're doing) but use the field name instead of the number:

assign component 'LIFNR'

of structure <dyn_wa> to <dyn_field>.

Max

Read only

0 Likes
825

Hi,

I do I write a statement like

<dyn_table>-lifnr = 1000010452.

<dyn_table>-matnr = v_matnr....

append <dyn_table>.

and so on ?

It does not accept the value for the internal table <dyn_table>.

Thanks,

stock

Read only

0 Likes
825

Do like this

FIELD-SYMBOLS : <FS_ANY> TYPE ANY.

ASSIGN COMPONENT 'LIFNR' OF STRUCTURE <dyn_table> TO <FS_ANY>.

<FS_ANY> = 1000010452.

ASSIGN COMPONENT 'MATNR' OF STRUCTURE <dyn_table> TO <FS_ANY>.

<FS_ANY> = V_MATNR ....

APPEND <DYN_TABLE>

This will work.

The error is becuase its dynamic and at design time while compiling the code it does not kow the name of the columns in DYN_TABLE.

Regards,

Ravi

Note :Please mark all the helpful answers

Message was edited by: Ravikumar Allampallam

Read only

0 Likes
825

Hi,

you can do some thing like this.....,

assign r_dyn_table->* to <t_dyn_table>.
create data r_wa_dyn_table like line of <t_dyn_table>.
assign r_wa_dyn_table->* to <wa_dyn_table>.
assign component 'FIELD1' of structure <wa_dyn_table> to <w_field>.
<w_field> = '10'.
assign component 'FIELD2' of structure <wa_dyn_table> to <w_field>.
<w_field> = '10'.
append <wa_dyn_table> to <t_dyn_table>.
assign component 'FIELD1' of structure <wa_dyn_table> to <w_field>.
<w_field> = '10'.
assign component 'FIELD2' of structure <wa_dyn_table> to <w_field>.
<w_field> = '10'.
append <wa_dyn_table> to <t_dyn_table>.

regards

vijay

Read only

0 Likes
825

Hi

DATA: WA_LINE TYPE REF TO DATA.

create data WA_LINE like line of <dyn_table>.

ASSIGN WA_LINE->* TO <dyn_wa>.

LOOP AT xfc.

ASSIGN COMPONENT xfc-FIELDNAME OF STRUCTURE <dyn_wa> TO <FS_ANY>.

CASE xfc-FIELDNAME.

WHEN 'LIFNR'. <FS_ANY> = '1000010452'

WHEN 'MATNR'. <FS_ANY> = V_MATNR.

............

ENDCASE.

ENDLOOP.

APPEND <dyn_wa> to <dyn_table>.

Max

ENDLOOP.

Read only

0 Likes
825

Hi again,

1. <dyn_table>-lifnr = 1000010452.

It will not work.

2. We have to do it in two steps, for each field assignment.

varname = 'ITAB-LIFNR'.

ASSIGN (VARNAME) TO <fs>.

<FS> = '10000010452'.

varname = 'ITAB-matnr'.

ASSIGN (VARNAME) TO <fs>.

<FS> = v_matnr.

regards,

amit m.

Read only

0 Likes
825

Hi ,

One more obstacle.

How do I read from the dynamic internal table?

If I write as

loop at i_itab.

ASSIGN COMPONENT 'MATNR' OF STRUCTURE <fs_dyn_wa> TO <FS_ANY>.

read table <fs_dyn_table> with key <fs_any> = i_itab-matnr

into <fs_dyn_wa>.

.

.

.

.

.

endloop.

It gives error.

pls help with ur ideas.

Thanks,

Stock

Read only

0 Likes
825

Hi,

check this....

loop at <t_dyn_table> into <wa_dyn_table>.

assign component 'FIELD2' of structure <wa_dyn_table> to <w_field>.

assign component 'T_CELLCOLORS'
of structure <wa_dyn_table> to <t_cellcolors>.

clear wa_cellcolors.

wa_cellcolors-fname = 'FIELD2'.

if <w_field> = '10'.
wa_cellcolors-color-col = '7'.
else.
wa_cellcolors-color-col = '5'.
endif.

append wa_cellcolors to <t_cellcolors>.

modify <t_dyn_table> from <wa_dyn_table>.

endloop.

Regards

Vijay

Read only

0 Likes
825

Hi,

FIELD-SYMBOLS : <FS_TAB> TYPE ANY.

LOOP AT <DYN_TAB> ASSIGNING <FS_TAB>.

ASSIGN COMPONENT 'LIFNR' OF STRUCTURE <FS_TAB> TO <FS_ANY>.

Now, <fs_any> will have the value of LIFNR field.

You can do the same with READ TABLE as well.

ENDLOOP.

Regards,

Ravi

Note : Please mark the helpful answers

Read only

Former Member
0 Likes
825

Hi,

FIELD-SYMBOLS : <FS_ANY> TYPE ANY.

ASSIGN COMPONENT 'LIFNR' OF STRUCTURE <dyn_table> TO <FS_ANY>.

Now <FS_ANY> will have the value of <DYN_TABLE>-LIFNR.

Regards,

Ravi