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

Using Table name in Read statement dynamically

Former Member
0 Likes
2,731

Hi Experts,

I have the following requirement.

Based on a country code say "A" , "B", "C" and based on this i have to read different internal tables lt_tabA, lt_tabB and lt_tabC.

The table key can be given dynamically, but how can i use the internal table name dynamically without using if statements.

Please help.

Thanks!

Best Regards,

Gayathri

1 ACCEPTED SOLUTION
Read only

GayathriRR
Product and Topic Expert
Product and Topic Expert
0 Likes
1,969

I basically have to use READ statement

8 REPLIES 8
Read only

GayathriRR
Product and Topic Expert
Product and Topic Expert
0 Likes
1,970

I basically have to use READ statement

Read only

0 Likes
1,969

Hi,

if you have just 3 internal tables, what is teh issue in using if/case statements?

Read only

GayathriRR
Product and Topic Expert
Product and Topic Expert
0 Likes
1,969

There is no issue. It is just that a similar piece of code has to repeated and i want the code to be better.

Read only

0 Likes
1,969

hi,

thsi should solve your problem:

[;

Read only

GayathriRR
Product and Topic Expert
Product and Topic Expert
0 Likes
1,969

thanks for the link to the thread..It has solve my problem

Read only

Former Member
0 Likes
1,969

Hello,

it is possible with a little dynamic programming. Here is how:


FIELD-SYBMOLS:
  <lv_tab>  TYPE STANDARD TABLE.

DATA:
  lt_tab1   TYPE TABLE OF....
  lt_tab2   TYPE TABLE OF...

ASSIGN lt_tab1 TO <lv_tab>.

READ TABLE <lv_tab> " read from the first table
  ...

ASSIGN lt_tab2 TO <lv_tab>.

READ TABLE <lv_tab> " read from the second table
  ...

Read only

0 Likes
1,969

Hi,

you can use the concept of field symbols .

ASSIGN COMPONENT lv_data OF STRUCTURE <dyn_wa> TO <fs1>.

<fs1> = p_wa_out-comp_code.

some thing like this.

Read only

Clemenss
Active Contributor
0 Likes
1,969

Hi Gayathri,

something like

DATA:
    lt_t100 TYPE TABLE OF t100,
    lt_t000 TYPE TABLE OF t000.
  FIELD-SYMBOLS:
    <table> TYPE table,
    <rec>   TYPE ANY,
    <field> TYPE ANY.
  SELECT:
    * INTO CORRESPONDING FIELDS OF TABLE lt_t100 FROM t100 UP TO 10 ROWS,
    * INTO CORRESPONDING FIELDS OF TABLE lt_t000 FROM t000 UP TO 10 ROWS.

  CASE abap_true.
    WHEN space.
      ASSIGN  lt_t100 TO <table>.
    WHEN OTHERS.
      ASSIGN  lt_t000 TO <table>.
  ENDCASE.
  READ TABLE <table> with key ('MANDT') = sy-mandt ASSIGNING <rec>.

Regards,

Clemens