Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

building table dynamically

Former Member
0 Kudos

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

1 ACCEPTED SOLUTION

Former Member
0 Kudos
7 REPLIES 7

Former Member
0 Kudos

Former Member
0 Kudos

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

former_member196299
Active Contributor
0 Kudos

hi Felix ,

Try the following blog:

/people/rich.heilman2/blog/2005/07/27/dynamic-internal-tables-and-structures--abap

Reward if helpful !

Regards,

Ranjita

Former Member
0 Kudos

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

Former Member
0 Kudos

Hi,

Check the following link:

http://www.sap-img.com/ab030.htm

Regards,

Bhaskar

Former Member
0 Kudos

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

Former Member
0 Kudos

Found a way to work around this....