2005 Dec 14 2:18 PM
Hi,
Would you know of way to add additional fields/columns to an existing internal table at runtime?
I know how to generate a table dynamically from scratch, but here I want to add fields to an <B>EXISTING INTERNAL TABLE</B>. Even it is WAS 6.40 let me know.
Any idea will be appreciated ..
Regards,
Ravi
The only way is to build it from the beginning, once you create an instance of the internal table, you can't change it.
Here is a small sample program which uses a dynamic internal table.
report zrich_0003
no standard page heading.
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_check type c.
selection-screen end of block b1.
start-of-selection.
perform build_dyn_itab.
perform build_report.
loop at <dyn_table> into <dyn_wa>.
write:/ <dyn_wa>.
endloop.
************************************************************************
* Build_dyn_itab
************************************************************************
form build_dyn_itab.
data: index(3) type c.
data: new_table type ref to data,
new_line type ref to data,
wa_it_fldcat type lvc_s_fcat.
* Create fields
clear index.
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.
* 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 10 times.
index = sy-index.
* Set up fieldname
concatenate 'FIELD' index into
fieldname .
condense fieldname no-gaps.
* Set up fieldvalue
concatenate 'FLD' index into
fieldvalue.
condense fieldvalue no-gaps.
assign component fieldname of structure <dyn_wa> to <fs1>.
<fs1> = fieldvalue.
enddo.
* Append to the dynamic internal table
append <dyn_wa> to <dyn_table>.
endform.Regards,
Rich Heilman
2005 Dec 14 2:23 PM
The only way is to build it from the beginning, once you create an instance of the internal table, you can't change it.
Here is a small sample program which uses a dynamic internal table.
report zrich_0003
no standard page heading.
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_check type c.
selection-screen end of block b1.
start-of-selection.
perform build_dyn_itab.
perform build_report.
loop at <dyn_table> into <dyn_wa>.
write:/ <dyn_wa>.
endloop.
************************************************************************
* Build_dyn_itab
************************************************************************
form build_dyn_itab.
data: index(3) type c.
data: new_table type ref to data,
new_line type ref to data,
wa_it_fldcat type lvc_s_fcat.
* Create fields
clear index.
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.
* 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 10 times.
index = sy-index.
* Set up fieldname
concatenate 'FIELD' index into
fieldname .
condense fieldname no-gaps.
* Set up fieldvalue
concatenate 'FLD' index into
fieldvalue.
condense fieldvalue no-gaps.
assign component fieldname of structure <dyn_wa> to <fs1>.
<fs1> = fieldvalue.
enddo.
* Append to the dynamic internal table
append <dyn_wa> to <dyn_table>.
endform.Regards,
Rich Heilman
2005 Dec 14 2:32 PM
Rich,
I know this.
Remember my weblog about the new BADI.
/people/ravikumar.allampallam/blog/2005/12/05/need-a-way-to-change-appearance-of-a-standard-existing-alv-report
I want to add more fields to the output of the report here. I am able to fields to the FIELDCAT, however the actual internal table is not being changed.
regards,
Ravi
2005 Dec 14 2:36 PM
2005 Dec 14 2:40 PM
create a dynamic table(it_new) and fieldcatalog for the additional fields
<b>as u had told that fieldcatalog is ready</b>
by using field symbols
Assign component 'fieldname' of structure it_fieldcat
to <fld_symbol>
this will work
if u want sample code i will send
2005 Dec 14 2:48 PM
pls let me know if there any clarifications
as i had got the same problem few days ago and solved it
lets say fld1 , fld2 and fld3 are the additional fields
these 3 flds can be updated to fieldcatalog.
now ur problem is to update the values for these 3 fields in the internal table , right??
Assign componet 'FLD1' of structure it_fielcat to <fld_symbol>
<fld_symbol> = your internal table value for the field
this will update the internal table field with the value in fld1
| User | Count |
|---|---|
| 3 | |
| 2 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |