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

use a string to define data

Former Member
0 Likes
644

Hello experts

Is there a way to do this: get a table name as a string from a query and use it to define another variable

For example:

data: line TYPE RSDSSEG.

select * from RSDSSEG into line where DATASOURCE = '/CW1/MMD01'.

ENDSELECT.

psatablename = line-psa.

*now psatablename contains the name of the abap table i would like to read

  • the following two lines do not work

data: psaline type psatablename.

select * from psatablename into psaline.

Thanks a lot for your help

Thibault

1 ACCEPTED SOLUTION
Read only

valter_oliveira
Active Contributor
0 Likes
603

Hello.

Check this example:


DATA: w_gentab TYPE aind_str2-gentab.

SELECT SINGLE gentab FROM aind_str2
  INTO (w_gentab)
 WHERE archindex EQ 'SAP_SD_VBRK_002'
   AND active EQ 'X'.

SELECT fkimg FROM (w_gentab) ...

So, use SELECT * FROM (psatablename) ... psatablename type char field. psaline shouldn't be of type psatablename but type of the table that psatablename will be.

Regards.

Valter Oliveira.

3 REPLIES 3
Read only

valter_oliveira
Active Contributor
0 Likes
604

Hello.

Check this example:


DATA: w_gentab TYPE aind_str2-gentab.

SELECT SINGLE gentab FROM aind_str2
  INTO (w_gentab)
 WHERE archindex EQ 'SAP_SD_VBRK_002'
   AND active EQ 'X'.

SELECT fkimg FROM (w_gentab) ...

So, use SELECT * FROM (psatablename) ... psatablename type char field. psaline shouldn't be of type psatablename but type of the table that psatablename will be.

Regards.

Valter Oliveira.

Read only

Former Member
0 Likes
603

Hi

data: line TYPE RSDSSEG.

select * from RSDSSEG into line where DATASOURCE = '/CW1/MMD01'.
ENDSELECT.

psatablename = line-psa.

*data: psaline type psatablename.
*select * from psatablename into psaline.

DATA: WA TYPE REF TO DATA.

FIELD-SYMBOLS: <WA>.

CREATE DATA WA TYPE (PSATABLENAME).
ASSIGN WA->* TO <WA>.

SELECT * FROM (PSATABLENAME) INTO <WA>.
ENDSELECT.

Max

Read only

Former Member
0 Likes
603

Yes it is possible.

Pl. check this sample code.

DATA:

dy_table TYPE REF TO data,

dy_line TYPE REF TO data.

***********************************************************************

  • FIELD-SYMBOLS *

***********************************************************************

FIELD-SYMBOLS: <dyn_table> TYPE STANDARD TABLE,

<dyn_wa> TYPE ANY.

  • Create internal table dynamically with the stucture of table name

CREATE DATA dy_table TYPE STANDARD TABLE OF (psatablename).

ASSIGN dy_table->* TO <dyn_table>.

IF sy-subrc = 0.

  • Create workarea for the table

CREATE DATA dy_line LIKE LINE OF <dyn_table>.

ASSIGN dy_line->* TO <dyn_wa>.

  • Select data from table

SELECT * FROM (psatablename)

INTO TABLE <dyn_table>.

ENDIF.

Regards,

Joy.