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: 

How to transfer data to dynamic internal table

Former Member
0 Kudos

Using an internal table in a program which has fields from many tables. Thru many select statements and logic the data gets populated in internal table ITAB.

Now how to transfer this data to dynamic internal table. All the examples related to dynamic internal table transfer data from a standrad Table.

Can any body provide code where data is being transferred from another internal table.

thanks

anya

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Already have an internal table and you just want to create another (dynamically declared) internal table of the same type.

anya

7 REPLIES 7

Former Member
0 Kudos

Go through t e following sample Code for Dynamic Creation of Internal Tables

=====================================

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.

Regards

Sreeni

Former Member
0 Kudos

Your question is very unspecified...

Do you have a statically declared internal table and want to transfer the records from this to another, dynamically declared internal table with the same structure?

if so:

MOVE static_itab TO <dynamic_itab>.

if they differ in structure:


DATA:
  lw_itab LIKE LINE OF static_itab.
FIELD-SYMBOLS:
  <lw_itab> TYPE ANY.

LOOP AT static_itab INTO lw_itab.
  INSERT INITIAL LINE INTO TABLE <dynamic_itab> ASSIGNING <lw_itab>.
  MOVE-CORRESPONDING lw_itab TO <lw_itab>.
ENDLOOP.

Former Member
0 Kudos

Mike,

how to define <dynamic_itab> in the coding. pls resolve.

anya

0 Kudos

In your initial posting you talked about an "dynamic internal table", therefore i thought, this was already available. Please let me have some more information about how to structure the dynamic internal table: From which other object can the structure be derived? Examples:

1 - You already have an internal table and you just want to create another (dynamically declared) internal table of the same type

2 - The dynamic internal table should have the same structure as a table desclared in DDIC

3 - You have a list of fields (columns) that should make up the structure of the internal table

4 - ...

Former Member
0 Kudos

Already have an internal table and you just want to create another (dynamically declared) internal table of the same type.

anya

0 Kudos

OK, that´s easy:

(I assume, your statically declared internal table has the name STAT_ITAB)


DATA:
  lr_tabledescr TYPE REF TO cl_abap_tabledescr,
  lr_dref       TYPE REF TO DATA.

FIELD-SYMBOLS:
  <lt_dyn_itab> TYPE ANY TABLE.

lr_tabledescr ?= cl_abap_tabledescr=>describe_by_data( stat_itab ).

CREATE DATA lr_dref TYPE HANDLE lr_tabledescr.
ASSIGN lr_dref->* TO <lt_dyn_itab>.

now the field-symbol points to the new, dynamically declared internal table, which has the same type (structure, key, ...) as the statically declared internal table STAT_ITAB.

reward point, if helpful

Former Member
0 Kudos

Mike,

very helpful answer, points have been given.

Is there any method to display all the content of this internal table in ALV format something like

CALL METHOD w_grid->set_table_for_first_display

EXPORTING

i_structure_name = tabname

CHANGING

it_outtab = <lw_itab>.

anya