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 from a internal table whose name is decided in runtime

Former Member
0 Likes
801

Dear ABAPers

I've an internal table's name in a variable, the name is populated in runtime (user_command->ls_selfield-tabname). Now that using the name (in the variable) i need to read a row from that particular internal table (which is populated into the variable). How can i do that.

Regards

Prabumanoharan

1 ACCEPTED SOLUTION
Read only

MarcinPciak
Active Contributor
0 Likes
747

Hi,

Use below:


DATA: tabname(40) TYPE c.

WRITE ls_selfield-tabname TO tabname.


FIELD-SYMBOLS: <fs> TYPE table, 
               <fs_wa>.

ASSIGN (tabname) TO <fs>.
READ TABLE <fs> ASSIGNING <fs_wa> INDEX 1.

Regards

Marcin

Dear ABAPers

I've an internal table's name in a variable, the name is populated in runtime (user_command->ls_selfield-tabname). Now that using the name (in the variable) i need to read a row from that particular internal table (which is populated into the variable). How can i do that.

Regards

Prabumanoharan

4 REPLIES 4
Read only

Former Member
0 Likes
747

Use field symbols.

FIELD-SYMBOLS: <FS> TYPE ANY table.

loop at (tab-name) assigning <FS>

Edited by: kartik tarla on Dec 10, 2008 6:24 PM

Read only

MarcinPciak
Active Contributor
0 Likes
748

Hi,

Use below:


DATA: tabname(40) TYPE c.

WRITE ls_selfield-tabname TO tabname.


FIELD-SYMBOLS: <fs> TYPE table, 
               <fs_wa>.

ASSIGN (tabname) TO <fs>.
READ TABLE <fs> ASSIGNING <fs_wa> INDEX 1.

Regards

Marcin

Read only

former_member203501
Active Contributor
0 Likes
747

hi see the coding and do the changes accordingly...

 

report ztests .

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.

Read only

Former Member
0 Likes
747

closing the thread