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

SELECT STATEMENT

Former Member
0 Likes
462

Hi, what is the best way to populate an internal table with multiple database table fields. give me some example code.

reward points if answered

1 ACCEPTED SOLUTION
Read only

anversha_s
Active Contributor
0 Likes
440

hi,

Use

FOR ALL ENTIRES

or

JOINS

.

FOR ALL ENTRIES

is an effective way of doing away with using

JOIN

on two tables.

You can check the below code -

SELECT BUKRS BELNR GJAHR AUGDT
FROM BSEG
INTO TABLE I_BSEG
WHERE BUKRS = ....

SELECT BUKRS BELNR BLART BLDAT
FROM BKPF
INTO TABLE I_BKPF
FOR ALL ENTRIES IN I_BSEG
WHERE BUKRS = I_BSEG-BUKRS
AND BELNR = I_BSEG-BELNR
AND BLDAT IN SO_BLDAT.

*******************************8

look another example

what is the use of FOR ALL ENTRIES

 INNER JOIN
DBTAB1 <------------> DBTAB2

It is used to JOIN two

DATABASE

tables

having some

COMMON

fields.

Whereas

For All Entries,

DBTAB1 <----


> ITAB1

is not at all related to two

DATABASE

tables.

It is related to

 INTERNAL

table.

If we want to fetch data

from some

DBTABLE1

but we want to fetch

for only some records

which are contained in some internal table,

then we use for alll entries.

*----


simple example of for all entries.

NOTE THAT

In for all entries,

it is NOT necessary to use

TWO DBTABLES.

(as against JOIN)

use this program (just copy paste)

it will fetch data

from T001

FOR ONLY TWO COMPANIES

(as mentioned in itab)


REPORT abc.



DATA : BEGIN OF itab OCCURS 0,
bukrs LIKE t001-bukrs,
END OF itab.

DATA : t001 LIKE TABLE OF t001 WITH HEADER LINE.

*--------------------

itab-bukrs = '1000'.
APPEND itab.
itab-bukrs = '1100'.
APPEND itab.


*--------------------

SELECT * FROM t001
INTO TABLE t001
FOR ALL ENTRIES IN itab
WHERE bukrs = itab-bukrs.


*--------------------------
LOOP AT t001.
WRITE :/ t001-bukrs.
ENDLOOP.

Hope this helps!

Regards,

Anversha

3 REPLIES 3
Read only

Former Member
0 Likes
440

hi,

Use for all entries or join.

Its better not to hit the entire db table using '*'.Its better if u retrieve only selected fields.

Read only

anversha_s
Active Contributor
0 Likes
441

hi,

Use

FOR ALL ENTIRES

or

JOINS

.

FOR ALL ENTRIES

is an effective way of doing away with using

JOIN

on two tables.

You can check the below code -

SELECT BUKRS BELNR GJAHR AUGDT
FROM BSEG
INTO TABLE I_BSEG
WHERE BUKRS = ....

SELECT BUKRS BELNR BLART BLDAT
FROM BKPF
INTO TABLE I_BKPF
FOR ALL ENTRIES IN I_BSEG
WHERE BUKRS = I_BSEG-BUKRS
AND BELNR = I_BSEG-BELNR
AND BLDAT IN SO_BLDAT.

*******************************8

look another example

what is the use of FOR ALL ENTRIES

 INNER JOIN
DBTAB1 <------------> DBTAB2

It is used to JOIN two

DATABASE

tables

having some

COMMON

fields.

Whereas

For All Entries,

DBTAB1 <----


> ITAB1

is not at all related to two

DATABASE

tables.

It is related to

 INTERNAL

table.

If we want to fetch data

from some

DBTABLE1

but we want to fetch

for only some records

which are contained in some internal table,

then we use for alll entries.

*----


simple example of for all entries.

NOTE THAT

In for all entries,

it is NOT necessary to use

TWO DBTABLES.

(as against JOIN)

use this program (just copy paste)

it will fetch data

from T001

FOR ONLY TWO COMPANIES

(as mentioned in itab)


REPORT abc.



DATA : BEGIN OF itab OCCURS 0,
bukrs LIKE t001-bukrs,
END OF itab.

DATA : t001 LIKE TABLE OF t001 WITH HEADER LINE.

*--------------------

itab-bukrs = '1000'.
APPEND itab.
itab-bukrs = '1100'.
APPEND itab.


*--------------------

SELECT * FROM t001
INTO TABLE t001
FOR ALL ENTRIES IN itab
WHERE bukrs = itab-bukrs.


*--------------------------
LOOP AT t001.
WRITE :/ t001-bukrs.
ENDLOOP.

Hope this helps!

Regards,

Anversha

Read only

Former Member
0 Likes
440

Hi Sravangd Panjugula,

Its an easy thing but make sure that you avoid using inner joins.

Read tables one after another by using <b>FOR ALL ENTRIES</b>.

Once all the tables are read. Use <b>READ TABLE - WITH KEY</b> criterion. This helps you to bring the data of all tables into one single table.

Hope this solves your query.

Reward Points if useful.

Thanks,

Tej..

null