08-22-2007 3:53 PM
Hi,
I'm trying to update a dynamic created itab(<dyn_tab> from values from another itab(i_names). I use a dynamic created work area for reading i_names, however, when I read the i_names table using the dynamic <dyn_wa>-id, it's complaining about <dyn_wa> has no structure and therefore no component called ID, also there aren't any components called FNAME or LNAME either.
I've inserted my code below and would really appreciate some advice.
Thanks in advance,
C
DATA: dy_table TYPE REF TO data,
dy_line TYPE REF TO data,
xfc TYPE lvc_s_fcat,
ifc TYPE lvc_t_fcat.
FIELD-SYMBOLS: <dyn_tab> TYPE STANDARD TABLE,
<dyn_wa>.
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_tab>.
Create dynamic work area and assign to FS
CREATE DATA dy_line LIKE LINE OF <dyn_tab>.
ASSIGN dy_line->* TO <dyn_wa>.
Get data.
SELECT (lt_fieldlist)
FROM DBTAB
INTO CORRESPONDING FIELDS OF TABLE <dyn_tab>
WHERE F1 = 'F1'
AND F2 = 'F2'.
Update <dyn_tab> table with names.
LOOP AT <dyn_tab> INTO <dyn_wa>.
Read names table using ID.
READ TABLE i_names ASSIGNING <names>
WITH TABLE KEY name_id = <dyn_wa>-id.
IF sy-subrc = 0 AND <names> IS ASSIGNED.
<dyn_wa>-fname = <names>-fname.
<dyn_wa-lname = <names>-lname.
ENDIF.
ENDLOOP.
08-22-2007 4:00 PM
DATA: dy_table TYPE REF TO data,
dy_line TYPE REF TO data,
xfc TYPE lvc_s_fcat,
ifc TYPE lvc_t_fcat.
<b>data : begin of wa ,
id(4) type c,
fname(10),
lname(10),
end of wa.</b>
FIELD-SYMBOLS: <dyn_tab> TYPE STANDARD TABLE,
<dyn_wa>.
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_tab>.
Create dynamic work area and assign to FS
CREATE DATA dy_line LIKE LINE OF <dyn_tab>.
ASSIGN dy_line->* TO <dyn_wa>.
Get data.
SELECT (lt_fieldlist)
FROM DBTAB
INTO CORRESPONDING FIELDS OF TABLE <dyn_tab>
WHERE F1 = 'F1'
AND F2 = 'F2'.
Update <dyn_tab> table with names.
LOOP AT <dyn_tab> INTO <dyn_wa>.
Read names table using ID.
<b>move corresponding <dyn_wa> to wa.
READ TABLE i_names ASSIGNING <names>
WITH TABLE KEY name_id = wa-id.</b>
IF sy-subrc = 0 AND <names> IS ASSIGNED.
wa-fname = <names>-fname.
wa-lname = <names>-lname.
move corresponding wa to <dyn_wa>.
ENDIF.
ENDLOOP.
08-22-2007 4:00 PM
DATA: dy_table TYPE REF TO data,
dy_line TYPE REF TO data,
xfc TYPE lvc_s_fcat,
ifc TYPE lvc_t_fcat.
<b>data : begin of wa ,
id(4) type c,
fname(10),
lname(10),
end of wa.</b>
FIELD-SYMBOLS: <dyn_tab> TYPE STANDARD TABLE,
<dyn_wa>.
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_tab>.
Create dynamic work area and assign to FS
CREATE DATA dy_line LIKE LINE OF <dyn_tab>.
ASSIGN dy_line->* TO <dyn_wa>.
Get data.
SELECT (lt_fieldlist)
FROM DBTAB
INTO CORRESPONDING FIELDS OF TABLE <dyn_tab>
WHERE F1 = 'F1'
AND F2 = 'F2'.
Update <dyn_tab> table with names.
LOOP AT <dyn_tab> INTO <dyn_wa>.
Read names table using ID.
<b>move corresponding <dyn_wa> to wa.
READ TABLE i_names ASSIGNING <names>
WITH TABLE KEY name_id = wa-id.</b>
IF sy-subrc = 0 AND <names> IS ASSIGNED.
wa-fname = <names>-fname.
wa-lname = <names>-lname.
move corresponding wa to <dyn_wa>.
ENDIF.
ENDLOOP.
08-23-2007 10:38 AM
Thanks Mahesh, that's solved that issue but leads me on to another question.
Further down the line I'm writing the contents of the dynaminc table <dyn_tab> to the Application server as an excel file. I feel that I'm going to have the same problem, i.e. "Data object has no structure" when I try to do this. Is there any way I can assign all components from the dynamic <dyn_tab> or <dyn_wa> to another <FS> that does have a structure that is based on the <dyn_tab> structure.
Thanks,
C
08-22-2007 4:04 PM
Try something like this. When defining a dynamic internal table or structure, there is no structure at design time, so of course you can not reference them at design time, so you need to do it dynamically using the ASSIGN COMPONENT statement.
IF sy-subrc = 0 AND <names> IS ASSIGNED.
field-symbols: <fs>.
assign component 'FNAME' of structure <dyn_wa> to <fs>.
if sy-subrc = 0.
<fs> = <names>-fname.
endif.
assign component 'LNAME' of structure <dyn_wa> to <fs>.
if sy-subrc = 0.
<fs> = <names>-lname.
endif.
ENDIF.
Regards,
RIch Heilman