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

Read dynamic internal tables

Former Member
0 Likes
2,578

Hi There,

can someone tell me how to read an internal table whose name will be known only at the runtime?

rgds,

Deb.

4 REPLIES 4
Read only

vinod_gunaware2
Active Contributor
0 Likes
517

REPORT CHAP2303.

  • Parameters for reading a single line, can be modified by the end user

PARAMETERS: KEY1(10) DEFAULT 'NAME',

VALUE1(25),

KEY2 LIKE KEY1 DEFAULT 'ID',

VALUE2 LIKE VALUE1.

  • Declarations for later use

TABLES CUSTOMERS.

DATA ALL_CUSTOMERS LIKE CUSTOMERS OCCURS 100

WITH HEADER LINE.

  • Filling the internal table

SELECT * FROM CUSTOMERS INTO TABLE ALL_CUSTOMERS.

  • Dynamic read table command

READ TABLE ALL_CUSTOMERS

WITH KEY (KEY1) = VALUE1

(KEY2) = VALUE2.

  • Displaying the result

IF SY-SUBRC EQ 0.

WRITE: / ALL_CUSTOMERS-ID,

ALL_CUSTOMERS-NAME,

ALL_CUSTOMERS-CITY,

ALL_CUSTOMERS-TELEPHONE.

ELSE.

WRITE 'Entry not found'.

ENDIF.

Or u can use same way variable (table_name) .

regards

vinod

Read only

Former Member
0 Likes
517

hii

chk out this code

DATA : BEGIN OF I_ITAB OCCURS 0,

TEST(5),

END OF I_ITAB.

<b>DATA: I_DYN_TAB(10) VALUE 'I_ITAB[]'.

DATA: DTAB TYPE REF TO DATA.</b>

<b>FIELD-SYMBOLS : <ITAB> TYPE ANY TABLE ,

<WA> TYPE ANY.</b>

I_ITAB-TEST = 'TEST'.

APPEND I_ITAB.

<b>ASSIGN (I_DYN_TAB) TO <ITAB>.

LOOP AT <ITAB> ASSIGNING <WA>.</b>

WRITE <WA>.

ENDLOOP.

also go thru this link

<b>

Regards

Naresh

Read only

0 Likes
517

REPORT YTEST_DYN .

*

*DATA: d_ref TYPE REF TO data,

*d_ref2 TYPE REF TO data ,

*i_alv_cat TYPE TABLE OF lvc_s_fcat,

*ls_alv_cat LIKE LINE OF i_alv_cat.

*

*

*TYPES tabname LIKE dcobjdef-name .

*parameter: p_tablen type tabname.

*

*data: begin of itab occurs 0.

  • INCLUDE STRUCTURE dntab.

*data: end of itab.

*

*

*FIELD-SYMBOLS : <F_FS> TYPE table,

*<F_FS1> TYPE TABLE,

*<F_FS2> TYPE ANY,

*<F_FS3> TYPE TABLE.

*

*REFRESH itab.

*CALL FUNCTION 'NAMETAB_GET'

  • EXPORTING

  • langu = sy-langu

  • tabname = p_tablen

  • TABLES

  • nametab = itab

  • EXCEPTIONS

  • no_texts_found = 1.

*LOOP AT itab .

  • ls_alv_cat-fieldname = itab-fieldname.

  • ls_alv_cat-ref_table = p_tablen.

  • ls_alv_cat-ref_field = itab-fieldname.

  • APPEND ls_alv_cat TO i_alv_cat.

*ENDLOOP.

    • internal table build

*CALL METHOD cl_alv_table_create=>create_dynamic_table

  • EXPORTING

  • it_fieldcatalog = i_alv_cat

  • IMPORTING

  • ep_table = d_ref.

ASSIGN d_ref-> TO <F_FS>.

*

*SELECT * FROM (p_tablen) INTO CORRESPONDING FIELDS OF TABLE <F_FS>.

*

*

*LOOP AT <F_FS> ASSIGNING <F_FS2>.

  • write:/12 <F_FS2> .

*

*ENDLOOP.

reward point if it helps

gunjan

Read only

former_member416164
Participant
0 Likes
517

Hello,

You can use field-symbol to do this.

Try this :

field-symbols <table> type any table.

  • Data contains the name of your internal table

assign (data) to <table>.

Hope this help