04-02-2008 9:40 AM
i have created a dynmic table .now i want to assign value to the certain field,how can i do that?
for eg,
<dyn_table> contains fields of name age ,now i want assign 'jack' to this internal talbe's field name ,
04-02-2008 9:47 AM
Hi
See the Following code.
data: dy_table type ref to data,
dy_line type ref to data,
xfc type lvc_s_fcat,
ifc type lvc_t_fcat.
data : <dyn_wa> type any .
xfc-fieldname = 'LIFNR'.
xfc-datatype = 'C'.
xfc-intlen = 18.
xfc-seltext = 'Vendor'.
xfc-outputlen = 10.
xfc-fix_column = 'X'.
append xfc to ifc.
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>.
assign component 'LIFNR' of structure <dyn_wa> to <fs>.
<fs> = '30000'.
append <dyn_wa> to <dyn_table>.
clear <dyn_wa>.
Regards,
Morris Bond.
Reward Points if Helpful.
04-02-2008 9:45 AM
Hi,
You must use a field symbol.
If your table is dynamic :
FIELD-SYMBOLS: <itab> TYPE ANY TABLE.
Best regards
04-02-2008 9:46 AM
hi,
this is the way to do:
FIELD-SYMBOLS : <field> TYPE ANY.
LOOP AT <dyn_table> INTO <dyn_line>.
ASSIGN COMPONENT 'AGE' OF STRUCTURE <dyn_line> TO <field>.
<field> = 'jack'.
MODIFY <dyn_table> FROM <dyn_line>.
ENDLOOP.
Pls. note that you'll need a dynamic line as well (<dyn_line>) to the dynamic internal table.
hope this helps
ec
04-02-2008 9:47 AM
Hi
See the Following code.
data: dy_table type ref to data,
dy_line type ref to data,
xfc type lvc_s_fcat,
ifc type lvc_t_fcat.
data : <dyn_wa> type any .
xfc-fieldname = 'LIFNR'.
xfc-datatype = 'C'.
xfc-intlen = 18.
xfc-seltext = 'Vendor'.
xfc-outputlen = 10.
xfc-fix_column = 'X'.
append xfc to ifc.
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>.
assign component 'LIFNR' of structure <dyn_wa> to <fs>.
<fs> = '30000'.
append <dyn_wa> to <dyn_table>.
clear <dyn_wa>.
Regards,
Morris Bond.
Reward Points if Helpful.
04-02-2008 10:16 AM
04-02-2008 9:58 AM
DATA: lp_data TYPE REF TO DATA.
FIELD-SYMBOLS: <wa> TYPE ANY,
<nm> TYPE ANY. " Better to give it the real type
CREATE DATA lp_data LIKE LINE OF <dyn_table>.
ASSIGN lp_data->* TO <wa>.
ASSIGN COMPONENT 'NAME' OF STRUCTURE <wa> TO <nm>.
<nm> = 'Jack'.
INSERT <nm> INTO TABLE <dyn_table>.
matt
04-02-2008 10:05 AM
Hi,
try this:
FIELD-SYMBOLS: <GT_ITAB> TYPE TABLE,
<GS_ITAB>,
<FS>, <FS1>.
*
DATA: GT_DATA TYPE REF TO DATA.
DATA: GS_DATA TYPE REF TO DATA.
*
************************************************************************
*
START-OF-SELECTION.
*
CREATE DATA GT_DATA TYPE TABLE OF PA0002.
ASSIGN GT_DATA->* TO <GT_ITAB>.
*
CREATE DATA GS_DATA LIKE LINE OF <GT_ITAB>.
ASSIGN GS_DATA->* TO <GS_ITAB>.
*
ASSIGN COMPONENT 'NACHN' OF STRUCTURE <GS_ITAB> TO <FS>.
<FS> = 'Smith'.
ASSIGN COMPONENT 'VORNA' OF STRUCTURE <GS_ITAB> TO <FS>.
<FS> = 'Paul'.
APPEND <GS_ITAB> TO <GT_ITAB>.
*
ASSIGN COMPONENT 'NACHN' OF STRUCTURE <GS_ITAB> TO <FS>.
<FS> = 'Jones'.
ASSIGN COMPONENT 'VORNA' OF STRUCTURE <GS_ITAB> TO <FS>.
<FS> = 'Martin'.
APPEND <GS_ITAB> TO <GT_ITAB>.
*
LOOP AT <GT_ITAB> INTO <GS_ITAB>.
ASSIGN COMPONENT 'NACHN' OF STRUCTURE <GS_ITAB> TO <FS>.
ASSIGN COMPONENT 'VORNA' OF STRUCTURE <GS_ITAB> TO <FS1>.
WRITE: / <FS>, <FS1>.
ENDLOOP.
Regards, Dieter