‎2007 Jun 11 7:39 AM
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
‎2007 Jun 11 7:44 AM
hi,
Use
FOR ALL ENTIRESor
JOINS.
FOR ALL ENTRIESis an effective way of doing away with using
JOINon 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 <------------> DBTAB2It is used to JOIN two
DATABASEtables
having some
COMMONfields.
Whereas
For All Entries,
DBTAB1 <----
> ITAB1
is not at all related to two
DATABASEtables.
It is related to
INTERNALtable.
If we want to fetch data
from some
DBTABLE1but 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
‎2007 Jun 11 7:41 AM
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.
‎2007 Jun 11 7:44 AM
hi,
Use
FOR ALL ENTIRESor
JOINS.
FOR ALL ENTRIESis an effective way of doing away with using
JOINon 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 <------------> DBTAB2It is used to JOIN two
DATABASEtables
having some
COMMONfields.
Whereas
For All Entries,
DBTAB1 <----
> ITAB1
is not at all related to two
DATABASEtables.
It is related to
INTERNALtable.
If we want to fetch data
from some
DBTABLE1but 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
‎2007 Jun 11 7:47 AM
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