Application Development and Automation 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: 
Read only

How can I create a Dynamic internal table in abap program.

Former Member
0 Likes
1,299

Hi,everyone

I want to create a Dynamic table by the name which given from the seletion-screen in Unicode OS.

Can anyone give me some sample source ?

Thanks.

CHEN

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,233
10 REPLIES 10
Read only

Former Member
0 Likes
1,234
Read only

Former Member
0 Likes
1,233

Refer:

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

Read only

Former Member
0 Likes
1,233

Also refer:

[http://sample-code-abap.blogspot.com/2008/07/dynamic-internal-table-and-processing.html]

Read only

Former Member
0 Likes
1,233

hi,

check this link..

[https://www.sdn.sap.com/irj/sdn/weblogs?blog=/pub/wlg/2071] [original link is broken] [original link is broken] [original link is broken];

Regards,

Sathish Reddy.

Read only

0 Likes
1,233

hi Reddy

Thanks for your help.

I readed that blog and copy the code into my abap editor.

When I put the value 'T001',it worked well,

but when 'KNA1',I saw a short dump(System error).

In Unicode System, the method "cl_alv_table_create=>create_dynamic_table " is OK?

Read only

uwe_schieferstein
Active Contributor
0 Likes
1,233

Hello Chen

You may have a look at thread

If you have RTTI available on your SAP system I would go for it.

Regards

Uwe

Read only

Former Member
0 Likes
1,233

Hi,

Check this sample code,

DATA:
  o_ref TYPE REF TO data.
FIELD-SYMBOLS:
  <lt_table> TYPE STANDARD TABLE,
  <fs>       TYPE ANY,
  <field>    TYPE ANY,
  <field1>   TYPE ANY.
PARAMETERS:
  p_tab       TYPE tabname default 'MARA', " Table name (eg: MARA)
  p_field(20) TYPE c default 'MATNR'.      " Field name (eg: MATNR)

START-OF-SELECTION.
  CREATE DATA o_ref TYPE TABLE OF (p_tab).

  ASSIGN p_field TO <field1>.
  ASSIGN o_ref->* TO <lt_table>.

  SELECT *
    INTO TABLE <lt_table>
    FROM (p_tab).

  LOOP AT <lt_table> ASSIGNING <fs>.
    ASSIGN COMPONENT <field1> OF STRUCTURE <fs>
                  TO <field>.
    IF sy-subrc = 0.
      WRITE:/ <field>.
    ENDIF.
  ENDLOOP.

Regards

Adil

Read only

Former Member
0 Likes
1,233

Chen,

Please run the code below, it will help you understand the concept of Dynamic Internal Table creation.

<content removed by moderator as it was just a copy/paste of someone else's work without giving credit. Any points have been unassigned.>

Cheers,

Murthy.

Edited by: Mike Pokraka on Sep 18, 2008 3:41 PM

Read only

asik_shameem
Active Contributor
0 Likes
1,233

Hi

Do like this.

REPORT  z_test                                .

TYPE-POOLS: slis.

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.


PARAMETERS: p_table TYPE dd02l-tabname.

* Build fieldcat
CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
  EXPORTING
    i_structure_name = p_table
  CHANGING
    ct_fieldcat      = it_fieldcat[].


* Create a new Table
CALL METHOD cl_alv_table_create=>create_dynamic_table
  EXPORTING
    it_fieldcatalog = it_fieldcat
  IMPORTING
    ep_table        = new_table.

ASSIGN new_table->* TO <l_table>.

* Create Work Area
CREATE DATA new_line LIKE LINE OF <l_table>.
ASSIGN new_line->* TO <l_line>.

Read only

Former Member
0 Likes
1,233

Thanks for everyone.

I have solved this problem.