‎2007 Apr 11 6:32 AM
Hi
I want to create dynamic table. The problem that i am facing is with field catalog population. The below is the entire scenario mentioned:
TYPES: BEGIN OF ty_map,
charname TYPE char30, "Characteristics Name
doc TYPE char30, "Document Info Record
charvalue TYPE char30, "Characteristics Value
END OF ty_map.
Data: i_map type standard table of ty_map initial size 0.
This internal table is populated with data.My dynamic table will contain the number of colums which will be equal to number of rows in internal table.
were as the dynamic table field label will be same as that of the i_map-doc.
When I am doing the above there is problem with field catalog population as a result when the dynamic table creation method is called it is giving dump.
So how shohld I populate field catalog.
‎2007 Apr 11 6:40 AM
Hi..
go through this..
Please use this code.
for above WAS 6.20 .
report yes_tjung_sflight_test.
Data Declaration
data: sflighttype type ref to cl_abap_structdescr,
tabletype type ref to cl_abap_tabledescr,
comp_tab type cl_abap_structdescr=>component_table,
new_comp_tab like comp_tab,
linetype type ref to cl_abap_structdescr,
dref type ref to data.
Field Symbols
field-symbols: <wa_comp> like line of comp_tab.
field-symbols: <table> type any table.
sflighttype ?= cl_abap_typedescr=>describe_by_name('SFLIGHT').
comp_tab = sflighttype->get_components( ).
loop at comp_tab assigning <wa_comp>.
case <wa_comp>-name.
when 'CARRID' or 'CONNID' or 'FLDATE' or 'PRICE' or 'CURRENCY'.
append <wa_comp> to new_comp_tab.
endcase.
endloop.
linetype = cl_abap_structdescr=>create( new_comp_tab ).
tabletype = cl_abap_tabledescr=>create(
p_line_type = linetype
p_table_kind = cl_abap_tabledescr=>tablekind_std ).
create data dref type handle tabletype.
assign dref->* to <table>.
select * from sflight into corresponding fields of table <table>.
field-symbols: <wa_data> type any.
field-symbols: <wa_field> type any.
loop at <table> assigning <wa_data>.
write: /.
loop at new_comp_tab assigning <wa_comp>.
assign component sy-tabix of structure <wa_data> to <wa_field>.
write: <wa_field>.
endloop.
endloop.
For was 6.20
Tables
DATA: LT_DATA type ref to DATA.
DATA: LT_FIELDCATALOG type LVC_T_FCAT.
Structure
DATA: LS_FIELDCATALOG type LVC_S_FCAT.
Data References
DATA: NEW_LINE type ref to data.
Field Symbols
FIELD-SYMBOLS: <FS_DATA> type ref to DATA,
<FS_1> type any table,
<FS_2>,
<FS_3>.
LS_FIELDCATALOG-FIELDNAME = 'MANDT'.
append LS_FIELDCATALOG to LT_FIELDCATALOG.
LS_FIELDCATALOG-FIELDNAME = 'CARRID'. "Fieldname
LS_FIELDCATALOG-INTTYPE = 'C'. "Internal Type C-> Character
append LS_FIELDCATALOG to LT_FIELDCATALOG.
LS_FIELDCATALOG-FIELDNAME = 'CONNID'.
LS_FIELDCATALOG-INTTYPE = 'N'.
append LS_FIELDCATALOG to LT_FIELDCATALOG.
LS_FIELDCATALOG-FIELDNAME = 'FLDATE'.
LS_FIELDCATALOG-INTTYPE = 'D'.
append LS_FIELDCATALOG to LT_FIELDCATALOG.
LS_FIELDCATALOG-FIELDNAME = 'PRICE'.
LS_FIELDCATALOG-INTTYPE = 'P'.
append LS_FIELDCATALOG to LT_FIELDCATALOG.
LS_FIELDCATALOG-FIELDNAME = 'CURRENCY'.
LS_FIELDCATALOG-INTTYPE = 'C'.
append LS_FIELDCATALOG to LT_FIELDCATALOG.
assign LT_DATA to <FS_DATA>.
call method cl_alv_table_create=create_dynamic_table
exporting
it_fieldcatalog = LT_FIELDCATALOG
importing
ep_table = FS_DATA
exceptions
generate_subpool_dir_full = 1
others = 2
.
if sy-subrc <> 0.
endif.
So <FS_1> now points to our dynamic internal table.
assign <FS_DATA>->* to <FS_1>.
Next step is to create a work area for our dynamic internal table.
create data NEW_LINE like line of <FS_1>.
A field-symbol to access that work area
assign NEW_LINE->* to <FS_2>.
And to put the data in the internal table
select MANDT CARRID CONNID FLDATE PRICE CURRENCY
from SFLIGHT
into corresponding fields of table <FS_1>.
Access contents of internal table
loop at <FS_1> assigning <FS_2>.
assign component 1 of structure <FS_2> to <FS_3>.
write: / <FS_3>.
endloop.
data: lv_tablename type string value 'SFLIGHT'.
data: lv_dref type ref to DATA.
CREATE DATA lv_dref type table of (lv_tablename).
FIELD-SYMBOLS: <FS> TYPE STANDARD TABLE.
ASSIGN lv_dref->* TO <FS>.
select *
from sflight
into table <FS>.
‎2007 Apr 11 6:44 AM
Hi Praveen,
Just click here for complete details about Dynamic Internal table:
http://www.saptechnical.com/Tutorials/ABAP/DynamicInternaltable/DynamicInternalTable.htm
<b>Reward,if helpful.</b>
Regards,
V.Raghavender.
‎2007 Apr 11 6:47 AM
Praveen,
You can acheive this through Macro.
Regards,
Ramganesan K.
‎2007 Apr 11 6:51 AM
Hi Praveen,
Go through the following link.
http://saptechnical.com/Tutorials/ABAP/DynamicInternaltable/DynamicInternalTable.htm
Regards,
Sandhya
‎2007 Apr 11 7:04 AM
hi,
PLS GO THROUGH THIS CODE
TYPE-POOLS: slis.
DATA: it_fcat TYPE slis_t_fieldcat_alv,
is_fcat LIKE LINE OF it_fcat.
DATA: it_fieldcat TYPE lvc_t_fcat,
is_fieldcat LIKE LINE OF it_fieldcat.
DATA: new_table TYPE REF TO data.
DATA: new_line TYPE REF TO data.
FIELD-SYMBOLS: <l_table> TYPE ANY TABLE,
<l_line> TYPE ANY,
<l_field> TYPE ANY.
Build fieldcat
CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
EXPORTING
i_structure_name = 'SYST'
CHANGING
ct_fieldcat = it_fcat[].
LOOP AT it_fcat INTO is_fcat WHERE NOT reptext_ddic IS initial.
MOVE-CORRESPONDING is_fcat TO is_fieldcat.
is_fieldcat-fieldname = is_fcat-fieldname.
is_fieldcat-ref_field = is_fcat-fieldname.
is_fieldcat-ref_table = is_fcat-ref_tabname.
APPEND is_fieldcat TO it_fieldcat.
ENDLOOP.
Create a new Table
CALL METHOD cl_alv_table_create=>create_dynamic_table
EXPORTING
it_fieldcatalog = it_fieldcat
IMPORTING
ep_table = new_table.
Create a new Line with the same structure of the table.
ASSIGN new_table->* TO <l_table>.
CREATE DATA new_line LIKE LINE OF <l_table>.
ASSIGN new_line->* TO <l_line>.
Test it...
DO 30 TIMES.
ASSIGN COMPONENT 'SUBRC' OF STRUCTURE <l_line> TO <l_field>.
<l_field> = sy-index.
INSERT <l_line> INTO TABLE <l_table>.
ENDDO.
LOOP AT <l_table> ASSIGNING <l_line>.
ASSIGN COMPONENT 'SUBRC' OF STRUCTURE <l_line> TO <l_field>.
WRITE <l_field>.
ENDLOOP.
PLS REWARD IF IT HELPFUL
REGARDS
Vana