‎2008 Aug 29 11:09 AM
hi,
i want ot create a structure like:
types : begin of ty_struct,
col1 ,
col2,
......
......
......
end of ty_struct.
the no.of columns depend on a integre value....if the integer
value is 10 then structure will have 10 columns ,if 15 then 15 and so on.
how to create this structure.
‎2008 Aug 29 12:07 PM
Hi,
I think I have the solution for your requirement, just run the code below it will serve your purpose.
type-pools: slis.
field-symbols: <dyn_table> type standard table,
<dyn_wa>.
data: alv_fldcat type slis_t_fieldcat_alv,
it_fldcat type lvc_t_fcat.
selection-screen begin of block b1 with frame title text-001.
parameters: p_flds(5) type c.
selection-screen end of block b1.
start-of-selection.
*build the dynamic internal table
perform build_dyn_itab.
*write 5 records to the alv grid
do 5 times.
perform build_report.
enddo.
*call the alv grid.
perform call_alv.
************************************************************************
*Build_dyn_itab
************************************************************************
form build_dyn_itab.
data: new_table type ref to data,
new_line type ref to data,
wa_it_fldcat type lvc_s_fcat.
*Create fields .
clear wa_it_fldcat.
wa_it_fldcat-fieldname = 'name1'.
wa_it_fldcat-datatype = 'mara-matnr'.
wa_it_fldcat-intlen = 5.
append wa_it_fldcat to it_fldcat .
*
*clear wa_it_fldcat.
wa_it_fldcat-fieldname = sy-index.
wa_it_fldcat-datatype = 'CHAR'.
wa_it_fldcat-intlen = 5.
append wa_it_fldcat to it_fldcat .
*
do p_flds times.
clear wa_it_fldcat.
wa_it_fldcat-fieldname = sy-index.
wa_it_fldcat-datatype = 'CHAR'.
wa_it_fldcat-intlen = 6.
append wa_it_fldcat to it_fldcat .
enddo.
*Create dynamic internal table and assign to FS
call method cl_alv_table_create=>create_dynamic_table
exporting
it_fieldcatalog = it_fldcat
importing
ep_table = new_table.
assign new_table->* to <dyn_table>.
*Create dynamic work area and assign to FS
create data new_line like line of <dyn_table>.
assign new_line->* to <dyn_wa>.
endform.
*********************************************************************
*Form build_report
*********************************************************************
form build_report.
data: fieldname(20) type c.
data: fieldvalue(5) type c.
data: index(3) type c.
field-symbols: <fs1>.
do p_flds times.
index = sy-index.
*Set up fieldvalue
concatenate 'FLD' index into
fieldvalue.
condense fieldvalue no-gaps.
assign component index of structure <dyn_wa> to <fs1>.
<fs1> = fieldvalue.
enddo.
*Append to the dynamic internal table
append <dyn_wa> to <dyn_table>.
endform.
************************************************************************
*CALL_ALV
************************************************************************
form call_alv.
data: wa_cat like line of alv_fldcat.
do p_flds times.
clear wa_cat.
wa_cat-fieldname = sy-index.
wa_cat-seltext_s = sy-index.
wa_cat-outputlen = '6'.
append wa_cat to alv_fldcat.
enddo.
*Call ABAP List Viewer (ALV)
call function 'REUSE_ALV_GRID_DISPLAY'
exporting
it_fieldcat = alv_fldcat
tables
t_outtab = <dyn_table>.
endform.
-
With best wishes,
Rama.
‎2008 Aug 29 11:11 AM
‎2008 Aug 29 11:11 AM
‎2008 Aug 29 11:22 AM
hi rainer,
well main aim is to create a dynamic table....
i have created this dynamic table also which has a dynamic structure.(TABLE 1)
i am having other internal table of different known (declared) structure.(TABLE 2)
well my requirement is to map the data from TABLE 2 to TABLE 1.and list TABLE1 (the dynamic table) as output..
please give suggestions,don't give links .
‎2008 Aug 29 11:26 AM
Hi,
You can use Extracts(Dynamic internal tables).
or
Field-symbols: <it_fs> type any table," internal table
<wa_fs> type any. " work area
‎2008 Aug 29 11:28 AM
‎2008 Aug 29 11:31 AM
Field-symbols: <it_fs> type any table," internal table
<wa_fs> type any. " work area
<it_fs> can acquire attributes of any structure.
Actualy they are like pointers in c/c++
e.g.
select * from abc into table <it_fs>.
<it_fs> now will aquire attributes of abc
select * from xyz into table <it_fs>.
<it_fs> now will aquire attributes of xyz
likewise for <wa_fs>
‎2008 Aug 29 11:40 AM
hi amit,
************************************************************
select * from abc into table <it_fs>.
<it_fs> now will aquire attributes of abc
select * from xyz into table <it_fs>.
<it_fs> now will aquire attributes of xyz
likewise for <wa_fs>
**************************************************************
My case is:
data it_table2 type table of ty_struct.
select * from xyz into table it_table2.
dynamic table created by stmt:
call method cl_alv_table_create=>create_dynamic_table
is = <it_fs>
now ,how to move data from it_table2 to <it_fs>.
‎2008 Aug 29 12:04 PM
‎2008 Aug 29 12:16 PM
‎2008 Aug 29 12:07 PM
Hi,
I think I have the solution for your requirement, just run the code below it will serve your purpose.
type-pools: slis.
field-symbols: <dyn_table> type standard table,
<dyn_wa>.
data: alv_fldcat type slis_t_fieldcat_alv,
it_fldcat type lvc_t_fcat.
selection-screen begin of block b1 with frame title text-001.
parameters: p_flds(5) type c.
selection-screen end of block b1.
start-of-selection.
*build the dynamic internal table
perform build_dyn_itab.
*write 5 records to the alv grid
do 5 times.
perform build_report.
enddo.
*call the alv grid.
perform call_alv.
************************************************************************
*Build_dyn_itab
************************************************************************
form build_dyn_itab.
data: new_table type ref to data,
new_line type ref to data,
wa_it_fldcat type lvc_s_fcat.
*Create fields .
clear wa_it_fldcat.
wa_it_fldcat-fieldname = 'name1'.
wa_it_fldcat-datatype = 'mara-matnr'.
wa_it_fldcat-intlen = 5.
append wa_it_fldcat to it_fldcat .
*
*clear wa_it_fldcat.
wa_it_fldcat-fieldname = sy-index.
wa_it_fldcat-datatype = 'CHAR'.
wa_it_fldcat-intlen = 5.
append wa_it_fldcat to it_fldcat .
*
do p_flds times.
clear wa_it_fldcat.
wa_it_fldcat-fieldname = sy-index.
wa_it_fldcat-datatype = 'CHAR'.
wa_it_fldcat-intlen = 6.
append wa_it_fldcat to it_fldcat .
enddo.
*Create dynamic internal table and assign to FS
call method cl_alv_table_create=>create_dynamic_table
exporting
it_fieldcatalog = it_fldcat
importing
ep_table = new_table.
assign new_table->* to <dyn_table>.
*Create dynamic work area and assign to FS
create data new_line like line of <dyn_table>.
assign new_line->* to <dyn_wa>.
endform.
*********************************************************************
*Form build_report
*********************************************************************
form build_report.
data: fieldname(20) type c.
data: fieldvalue(5) type c.
data: index(3) type c.
field-symbols: <fs1>.
do p_flds times.
index = sy-index.
*Set up fieldvalue
concatenate 'FLD' index into
fieldvalue.
condense fieldvalue no-gaps.
assign component index of structure <dyn_wa> to <fs1>.
<fs1> = fieldvalue.
enddo.
*Append to the dynamic internal table
append <dyn_wa> to <dyn_table>.
endform.
************************************************************************
*CALL_ALV
************************************************************************
form call_alv.
data: wa_cat like line of alv_fldcat.
do p_flds times.
clear wa_cat.
wa_cat-fieldname = sy-index.
wa_cat-seltext_s = sy-index.
wa_cat-outputlen = '6'.
append wa_cat to alv_fldcat.
enddo.
*Call ABAP List Viewer (ALV)
call function 'REUSE_ALV_GRID_DISPLAY'
exporting
it_fieldcat = alv_fldcat
tables
t_outtab = <dyn_table>.
endform.
-
With best wishes,
Rama.