‎2006 Feb 09 5:37 AM
hi
i have created a dynamic internal table which has fields which is in the data of another table.
that is it1 has
data
new york 10
london 50
dynamic table has
field has new york london
how to put data in this format
new york london
10 50
sarangan r
‎2006 Feb 09 5:40 AM
for that u need to use ASSIGN COMPONENT
ex:
FIELD-SYMBOLS: <FS>,<FS1>.
ASSIGN COMPONENT city of itab to <FS>.
assign 10 to <fs1>.
<FS> = <FS1>.
‎2006 Feb 09 5:47 AM
field-symbols: <dyn_wa>.
create data new_line like line of <dyn_table>. "Work Area"
assign new_line->* to <dyn_wa>.
assign component fieldname of structure <dyn_wa> to <fs1>.
<fs1> = fieldvalue.
append <dyn_wa> to <dyn_table>.
‎2006 Feb 09 5:54 AM
Here is an example.
REPORT ztestaks.
TYPES: t_source(72).
DATA: v_program(8),
v_err_message(128),
v_error_line TYPE i.
DATA: i_subroutine_code TYPE table of t_source,
s_source TYPE t_source.
s_source = 'REPORT ZDYNAMICPROG'.
APPEND s_source TO i_subroutine_code.
*-- Now prepare the code for the dynamic subroutine
s_source = 'FORM DYNAMIC_SELECT.'.
APPEND s_source TO i_subroutine_code .
*-- Prepare the code for declaring the internal table
s_source = 'DATA: BEGIN OF T_LFA1,'.
APPEND s_source TO i_subroutine_code.
*-- this will dynamically build the fields of internal table
LOOP AT t_unique.
CLEAR s_source.
CONCATENATE t_unique-fname
'LIKE'
'LFA1-'
INTO s_source SEPARATED BY SPACE.
CONCATENATE s_source
t_unique-fname
','
INTO s_source.
APPEND s_source TO i_subroutine_code.
ENDLOOP.
s_source = 'END OF T_LFA1.'.
APPEND s_source TO i_subroutine_code.
*-- Now prepare the code for the select statement
s_source = 'SELECT'.
APPEND s_source TO i_subroutine_code.
LOOP AT t_unique.
s_source = t_unique-fname.
APPEND s_source TO i_subroutine_code.
ENDLOOP.
s_source = 'FROM LFA1'
APPEND s_source TO i_subroutine_code.
s_source = 'INTO TABLE T_LFA1'.
APPEND s_source TO i_subroutine_code.
s_source = 'WHERE LAND1 = 'BR'.
APPEND s_source TO i_subroutine_code.
s_source = 'ENDFORM.'.
APPEND s_source TO i_subroutine_code.
generate subroutine pool i_subroutine_code
name v_program
message v_err_message
line v_error_line.
if sy-subrc = 0.
perform DYNAMIC_SELECT in program (v_program).
else.
write:/ v_err_message.
endif.
‎2006 Feb 09 5:54 AM
‎2006 Feb 09 5:55 AM
dear Wenceslaus G
what is new_line. could u explain in detail
sarangan
‎2006 Feb 09 6:06 AM
data: new_table type ref to data,
field-symbols: <dyn_wa>.
do 10 times.
index = sy-index.
clear wa_it_fldcat.
concatenate 'Field' index into
wa_it_fldcat-fieldname .
condense wa_it_fldcat-fieldname no-gaps.
wa_it_fldcat-datatype = 'CHAR'.
wa_it_fldcat-intlen = 5.
append wa_it_fldcat to it_fldcat .
enddo.
call method cl_alv_table_create=>create_dynamic_table
exporting
it_fieldcatalog = it_fldcat
importing
ep_table = new_table.
create data new_line like line of <dyn_table>. "Work Area"
assign new_line->* to <dyn_wa>.
assign component fieldname of structure <dyn_wa> to <fs1>.
<fs1> = fieldvalue.
append <dyn_wa> to <dyn_table>.
‎2006 Feb 09 6:07 AM
assign component fieldname of structure <dyn_wa> to <fs1>.
you gave fieldname i do not know that is dynamic
how to do it
sarangan r
‎2006 Feb 09 6:18 AM
When creating the dynamic fields in the dynamic internal table name it as FIELD1, FIELD2 etc.
concatenate 'Field' index into wa_it_fldcat-fieldname.
condense wa_it_fldcat-fieldname no-gaps.
wa_it_fldcat-datatype = 'CHAR'.
wa_it_fldcat-intlen = 5.
append wa_it_fldcat to it_fldcat .Hence when you retrieve it back you can dynamically concatenate and get the field values.
concatenate 'FIELD' index into fieldname.
condense fieldname no-gaps.
* Set up field value
concatenate 'FLD' index into fieldvalue.
condense fieldvalue no-gaps.Ps: Reward points if helpful.
‎2006 Feb 09 6:20 AM
then instead of fieldname u can give index
ASSIGN COMPONENT INDEX OF ITAB TO <FS>
‎2006 Feb 09 6:20 AM
Hi Sarangan,
Check :
/people/subramanian.venkateswaran2/blog/2004/11/19/dynamic-internal-table
/people/rich.heilman2/blog/2005/07/27/dynamic-internal-tables-and-structures--abap
Thanks & Regards,
Ankur