Skip to Content
author's profile photo
Former Member

Select from a dynamically chosen table

Hi everyone,

I'm willing to retrieve information stored in a given column of a given table, both generated dynamically. Thus, I have a string S1 with the table name and a string S2 with a column name of this table.

My aim would be to do something like that :

+select single * into corresponding fields of X

from (S1)

where Y = 'SomeValue'.+

X being like a line of the table (S1)

Y being the column name stored in S2.

But for this, I need to fine a correct way to define X and Y from S1 and S2, which I failed to do until now. 😔 My first idea was to use field-symbols but it didn't help me. It might be quite easy or maybe impossible, I don't even know as my knowledge in ABAP is far from being excellent, but any reply would be welcome.

Best regards,

François

Add comment
10|10000 characters needed characters exceeded

  • Follow
  • Get RSS Feed

2 Answers

  • author's profile photo
    Former Member
    Jul 08, 2004 at 02:06 PM

    I tested this code with release 46c.

    FIELD-SYMBOLS:

    <t001>, <fs>.

    DATA:

    lr_t001 TYPE REF TO data.

    CONSTANTS:

    s1(30) VALUE 'T001',

    s2(30) VALUE 'BUKRS',

    s3(30) VALUE 'BUTXT'.

    DATA:

    lt_where(72) OCCURS 0 WITH HEADER LINE.

    CREATE DATA lr_t001 TYPE (s1).

    ASSIGN lr_t001->* TO <t001>.

    ASSIGN (s1) TO <fs>.

    CONCATENATE s2 '=' '3000' INTO lt_where SEPARATED BY space.

    APPEND lt_where.

    SELECT *

    INTO <t001>

    FROM (s1)

    WHERE (lt_where).

    ASSIGN COMPONENT s3 OF STRUCTURE <t001> TO <fs>.

    WRITE: / s3, ': ', <fs>.

    ENDSELECT.

    Add comment
    10|10000 characters needed characters exceeded

  • author's profile photo
    Former Member
    Jul 08, 2004 at 03:05 PM

    Thanks a lot for your help, I wasn't using those field-symbols correctly.

    It works perfectly that way ! 😊

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member Former Member

      In 4.6 systems you can use class CL_ALV_CREATE_TABLE (or something very similar in name), to generate a dynamic internal table.

      As Pavan suggests, behind the scenes this class utilises the GENERATE SUBROUTINE POOL logic and hence has the same limitations (only up to 36 subroutine pools per internal mode). At least it simplifies things.

      Scott