2005 Oct 20 3:05 PM
Hi,
We have created dynamic internal table with some fields.
for the above how to create structure or internal table like dynamic internal table structure .
Scenario: internal table itab1 ( with header line) have 5 fields.
Based on some of the conditions in layout of the report.
we have to create dynamic internal table.
field-symbols: <FS> type standard table.
we are able to create dynamic internal table with 3 fields
with assignment <fs> = itab1[]
the columns are not appearing but data appearing in next column.
how to solve this one
Thanks
Ramesh
Hi,
We have created dynamic internal table with some fields.
for the above how to create structure or internal table like dynamic internal table structure .
Scenario: internal table itab1 ( with header line) have 5 fields.
Based on some of the conditions in layout of the report.
we have to create dynamic internal table.
field-symbols: <FS> type standard table.
we are able to create dynamic internal table with 3 fields
with assignment <fs> = itab1[]
the columns are not appearing but data appearing in next column.
how to solve this one
Thanks
Ramesh
2005 Oct 20 3:13 PM
HI Ramesh
Follow the weblog posted by - Subramanian Venkateswaran
-
/people/subramanian.venkateswaran2/blog/2004/11/19/dynamic-internal-table
-
This will help you alot.
Cheers,
Vijay Raheja
2005 Oct 20 3:23 PM
If I understand you correctly, you want to create a dynamic internal table just like another dynamic internal table. Is this correct? If so, then you would just create two instances of the same dynamic internal table.
field-symbols: <dyn_table> type standard table,
<dyn_table2> type standard table,
<dyn_wa>
<dyn_wa2>.
data: alv_fldcat type slis_t_fieldcat_alv,
it_fldcat type lvc_t_fcat.
data: index(3) type c.
data: new_table type ref to data,
new_table2 type ref to data,
new_line type ref to data,
new_line2 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.
call method cl_alv_table_create=>create_dynamic_table
exporting
it_fieldcatalog = it_fldcat
importing
ep_table = new_table2.
assign new_table->* to <dyn_table>.
assign new_table2->* to <dyn_table2>.
* Create dynamic work area and assign to FS
create data new_line like line of <dyn_table>.
assign new_line->* to <dyn_wa>.
create data new_line2 like line of <dyn_table2>.
assign new_line2->* to <dyn_wa2>.
Regards,
Rich Heilman
2005 Oct 20 3:52 PM
Hi Ramesh,
I hope this code works...
report yup_alv_datbase .
*-Display Database table contents in ALV Grid Format
>********************************************************************
This report displays data from SAP tables, views (like SE16) *
FM : REUSE_ALV_GRID_DISPLAY *
----
tables:
dd02l, " SAP tables
dd03l. " Table Fields
type-pools: slis. " ALV Global Types
selection-screen :
begin of line, comment 1(35) v_1 for field p_table. "#EC NEEDED
parameters p_table like dd03l-tabname obligatory memory id dtb.
selection-screen end of line.
selection-screen :
begin of line, comment 1(35) v_2 for field p_max. "#EC NEEDED
parameters p_max(2) type n default '20' obligatory.
selection-screen end of line.
----
at selection-screen.
select single * from dd02l where tabname = p_table
and as4local = 'A'
and as4vers = '0000'.
if sy-subrc ne 0.
Table & is not active in the Dictionary
message e402(mo) with p_table.
elseif dd02l-tabclass = 'INTTAB'.
& is a structure, not a table
message e403(mo) with p_table.
endif.
----
initialization.
v_1 = 'Table'.
v_2 = 'Maximum of records'.
----
start-of-selection.
perform f_display_data.
----
Form F_DISPLAY_DATA
----
form f_display_data.
Macro definition
define m_sort.
add 1 to ls_sort-spos.
ls_sort-fieldname = &1.
ls_sort-up = 'X'.
append ls_sort to lt_sort.
end-of-definition.
data:
l_long type i,
lp_struct type ref to data,
lp_table type ref to data, " Pointer to dynamic table
of_sdescr type ref to cl_abap_structdescr,
ls_lvc_cat type lvc_s_fcat,
lt_lvc_cat type lvc_t_fcat, " Field catalog
ls_fieldcat type slis_fieldcat_alv,
lt_fieldcat type slis_t_fieldcat_alv, " Field catalog
ls_layout type slis_layout_alv,
lt_sort type slis_t_sortinfo_alv, " Sort table
ls_sort type slis_sortinfo_alv.
field-symbols :
<fieldcat> type slis_fieldcat_alv,
<lt_data> type table, " Data to display
<fs> type any,
<components> type abap_compdescr.
Dynamic creation of a structure
create data lp_struct type (p_table).
assign lp_struct->* to <fs>.
Fields Structure
of_sdescr ?= cl_abap_typedescr=>describe_by_data( <fs> ).
loop at of_sdescr->components assigning <components>.
Field MANDT not displayed
if sy-tabix = 1 and <components>-name = 'MANDT'.
continue. " Next loop
endif.
Build Fieldcatalog
ls_lvc_cat-fieldname = <components>-name.
ls_lvc_cat-ref_table = p_table.
append ls_lvc_cat to lt_lvc_cat.
Build Fieldcatalog
ls_fieldcat-fieldname = <components>-name.
ls_fieldcat-ref_tabname = p_table.
append ls_fieldcat to lt_fieldcat.
endloop.
Create internal table
call method cl_alv_table_create=>create_dynamic_table
exporting it_fieldcatalog = lt_lvc_cat
importing ep_table = lp_table.
assign lp_table->* to <lt_data>.
Read data
select * from (p_table) up to p_max rows
into corresponding fields of table <lt_data>
order by primary key.
if <lt_data>[] is initial.
No table entries found for specified key
message i429(mo).
exit.
endif.
Read key field to Build Sort Table
select * from dd03l where tabname = p_table
and fieldname <> '.INCLUDE'
and as4vers = '0000'
and as4local = 'A'
order by position.
read table lt_fieldcat assigning <fieldcat>
with key fieldname = dd03l-fieldname.
check sy-subrc eq 0.
add dd03l-leng to l_long.
if dd03l-keyflag = 'X'.
Build Sort Table
m_sort dd03l-fieldname.
<fieldcat>-key = 'X'.
elseif l_long > 150.
<fieldcat>-tech = 'X'.
endif.
endselect.
ls_layout-zebra = 'X'.
ls_layout-colwidth_optimize = 'X'.
call function 'REUSE_ALV_GRID_DISPLAY'
exporting
is_layout = ls_layout
it_fieldcat = lt_fieldcat
it_sort = lt_sort
tables
t_outtab = <lt_data>.
endform. " F_DISPLAY_DATA
END OF PROGRAM Z_ALV_DYNAMIC_DATA *********************
Regards,
Sampath
2005 Oct 20 4:49 PM
Thank you for all quick responses
here is in detail i am giving my scenario.
data: begin of itab1 occurs 0,
field1 type c,
field2(2) type c,
field3(2) type c,
field4 type c,
field5 type c,
end of itab1.
based on some conditions i have created dynamic internal table with fields of field1, field2, field5
after that i have done as below
<dyn_table> = itab1[]. (problem is happening here)
in <dyn_table> field1, field2 appering correctly but in field 5 value of fiedl3 is appearing.
now i think it is clear
please help me regarding this.
Thanks
Ramesh
2005 Oct 22 11:48 AM
you cannot use
<dyn_table> = itab1[].
as itab and <dyn_table> are of different structure .
try the following code.
DATA: new_line TYPE REF TO data.
FIELD-SYMBOLS: <l_line> TYPE ANY .
CREATE DATA new_line LIKE LINE OF <dyn_table>.
ASSIGN new_line->* TO <l_line>.
loop at itab .
move-corresponding itab to <l_line> .
INSERT <l_line> INTO TABLE <dyn_table>.
endloop .
Regards
Raja
2005 Oct 22 11:49 AM
reward the helpful answers and mark it answered if so.
Regards
Raja
| User | Count |
|---|---|
| 6 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |