Skip to Content
author's profile photo Former Member
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 a comment
10|10000 characters needed characters exceeded

Related questions

2 Answers

  • author's profile photo Former Member
    Former Member
    Posted on 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 a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on 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 a 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

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.