2007 Jul 10 10:01 AM
Hi folks!
Does anybody know whether it is possible to build an internal table from DDIC-structures dynamically?
I have a deep structured itab_upload(whose structure is defined in the DDIC), which contains 2 fields(Number Name) and a third field which contains itab_desc.
This itab_desc can contain either 2 fields(Number Name) and a third field which contains another itab_desc or 3 fields for numbers(without any other itab).If itab_desc contains another itab_desc, the second itab_desc contains only 3 fields for numbers and names...
help will be very appreciated and points will be rewarded!
Felix
2007 Jul 10 10:06 AM
hi,
check this link,
https://forums.sdn.sap.com/click.jspa?searchID=3750707&messageID=3487864
regards,
seshu.
2007 Jul 10 10:06 AM
hi,
check this link,
https://forums.sdn.sap.com/click.jspa?searchID=3750707&messageID=3487864
regards,
seshu.
2007 Jul 10 10:09 AM
Hi,
Look bellow sample program
report ytest.
data: lt_fieldcatalog type lvc_t_fcat.
data: ls_fieldcatalog type lvc_s_fcat.
field-symbols: <fs_data> type ref to data.
field-symbols: <fs_1>.
field-symbols: <fs_2> type any table.
field-symbols: <fs_3> type ypoll.
data: lt_data type ref to data.
assign lt_data to <fs_data>.
ls_fieldcatalog-fieldname = 'MANDT'.
ls_fieldcatalog-tabname = 'LT_TAB'.
append ls_fieldcatalog to lt_fieldcatalog.
ls_fieldcatalog-fieldname = 'POLLID'.
ls_fieldcatalog-tabname = 'LT_TAB'.
append ls_fieldcatalog to lt_fieldcatalog.
ls_fieldcatalog-fieldname = 'TEAM'.
ls_fieldcatalog-tabname = 'LT_TAB'.
append ls_fieldcatalog to lt_fieldcatalog.
ls_fieldcatalog-fieldname = 'INITIATOR'.
ls_fieldcatalog-tabname = 'LT_TAB'.
append ls_fieldcatalog to lt_fieldcatalog.
ls_fieldcatalog-fieldname = 'DESCRIPTION'.
ls_fieldcatalog-tabname = 'LT_TAB'.
append ls_fieldcatalog to lt_fieldcatalog.
ls_fieldcatalog-fieldname = 'APPROVED'.
ls_fieldcatalog-tabname = 'LT_TAB'.
append ls_fieldcatalog to lt_fieldcatalog.
ls_fieldcatalog-fieldname = 'INITIATED_DATE'.
ls_fieldcatalog-tabname = 'LT_TAB'.
append ls_fieldcatalog to lt_fieldcatalog.
ls_fieldcatalog-fieldname = 'END_DATE'.
ls_fieldcatalog-tabname = 'LT_TAB'.
append ls_fieldcatalog to lt_fieldcatalog.
ls_fieldcatalog-fieldname = 'WINNER'.
ls_fieldcatalog-tabname = 'LT_TAB'.
append ls_fieldcatalog to lt_fieldcatalog.
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.
assign <fs_data>->* to <fs_1>.
assign <fs_1> to <fs_2>.
loop at <fs_2> assigning <fs_3>.
write: <fs_3>-pollid.
endloop.
Regards
Gaurav
2007 Jul 10 10:09 AM
hi Felix ,
Try the following blog:
/people/rich.heilman2/blog/2005/07/27/dynamic-internal-tables-and-structures--abap
Reward if helpful !
Regards,
Ranjita
2007 Jul 10 10:10 AM
Hi,
hi,
try this..
=====================================
REPORT zmaschl_create_data_dynamic .
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.
<b>Reward points</b>
Regards
2007 Jul 10 10:13 AM
2007 Jul 10 10:14 AM
Hi Felix,
try this short example:
PARAMETER: P_DBTAB LIKE DATABROWSE-TABLENAME DEFAULT 'MARA'.
*
DATA: GDO_DATA TYPE REF TO DATA.
FIELD-SYMBOLS: <GT_ITAB> TYPE TABLE.
*
CREATE DATA GDO_DATA TYPE TABLE OF (P_DBTAB).
ASSIGN GDO_DATA->* TO <GT_ITAB>.
*
SELECT * FROM (P_DBTAB) UP TO 100 ROWS INTO TABLE <GT_ITAB>.
Regards, Dieter
2007 Jul 11 9:27 AM