Select with Variable

Q.

> -----------------------------------------------
> > > Hi all,
> > > Can somebody help me with this (little) problem.
> > > -----------------------------------------------
> > > IS:
> > > DATA Z0051 LIKE T005 OCCURS 0 WITH HEADER LINE.
> > > DATA Z0052 LIKE T005 OCCURS 0 WITH HEADER LINE.
> > >
> > > SELECT * INTO TABLE Z0051 FROM T005.
> > > SELECT * INTO TABLE Z0052 FROM T005.
> > > =====
> > > -----------------------------------------------

> > > DEBIT:
> > > Instead of these two SELECT specification I would
> > > like to write a SELECT specification with a variable
> > > internal table.
> > >
> > > SELECT * INTO TABLE variable FROM T005.
> > > ========
> > > -----------------------------------------------
> > > Is that possible?
> > > I hope you understand what I wrote.
> > > I am improving my english but it isn't perfect.



A1:

There are a lot of ways you can use dynamically internal table assignments.

The best way, for my attitude, is to use the following code:

PROGRAM ZXXXXXX.
DATA: Z0051 LIKE T005 OCCURS 0 WITH HEADER LINE.
DATA: Z0052 LIKE T005 OCCURS 0 WITH HEADER LINE.

START-OF-SELECTION.
PERFORM ADD-DYNAMIC TABLES Z0051.
PERFORM ADD-DYNAMIC TABLES Z0052.
END-OF-SELECTION.

FORM ADD-DYNAMIC TABLES F_TAB.
SELECT * FROM T005 INTO TABLE F_TAB.
ENDFORM.

Kind regards, Ingo-Willy Raddatz.

A2:

Hi Roland,

I believe, here is an example that could help you. Worked perfectly.

DATA: Z001 LIKE T005 OCCURS 0 .
DATA: Z002 LIKE T005 OCCURS 0 .
DATA: ITAB_NAME(10).
FIELD-SYMBOLS: <ITAB> TYPE TABLE.

MOVE 'Z001' TO ITAB_NAME.

ASSIGN (ITAB_NAME) TO <ITAB>.
SELECT * FROM T005 INTO TABLE <ITAB>.

MOVE 'Z002' TO ITAB_NAME.

ASSIGN (ITAB_NAME) TO <ITAB>.
SELECT * FROM T005 INTO TABLE <ITAB>.

Note, Z001 .... can only be interanl tables WITHOUT header line,
otherwise ASSIGN won't work. Is there a problem for you? I'm on 3.1H.

Regards,

Siarhei

Converted from CHM to HTML with chm2web Standard 2.7 (unicode)