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

Internal table question

Former Member
0 Likes
868

Hi,

I am writing some update routines for BW, and have an ABAP related question to you.

I would like to pull data from two tables into that internal table. The problem is that those tables have one field in common however this field is not a key field on neither of them.

Can i use the statement "FOR all Entries" in this case?

What i mean is that i will first select from one table and then write a second select statement for the other table and use the "FOR ALL ENTRIES" statement to match between the records?

Will this work? If not can you suggest some code that will do it?

Regards,

Xibi

1 ACCEPTED SOLUTION
Read only

alejandro_lpez
Contributor
0 Likes
849

Hi,

You can use the follow sentence:

To obtain data from first table

SELECT a b c INTO itab

FROM tab1

WHERE <cond>

and then obtain data from second table, and storage in the same internal table with APPENDING TABLE

SELECT a b c APPENDING TABLE itab

FROM tab2

WHERE <cond>

if this is not what you need, you could make a loop from the first table and then make a read table from second table comparing the no key field

loop at itab.

read table itab2 with key (common not key field) field = itab-field

if sy-subrc eq 0.

move values from itab2 to itab 1.

endif.

modify itab

endloop.

hope this help you.

Alejandro

9 REPLIES 9
Read only

Former Member
0 Likes
849

Hi

Would you like to do that:

SELECT * FROM <TABLE_1> INTO TABLE ITAB WHERE ....

IF SY-SUBRC = 0.

SELECT * FROM <TABLE_2> INTO TABLE ITAB2

FOR ALL ENTRIES IN ITAB WHERE FIELD = ITAB-FIELD.

ENDIF.

If it's so, yes it works, but I don't understand your problem.

Max

Max

Read only

Former Member
0 Likes
849

Hi ,

You can use for all entries.

Pseudo Code:

Select A B C from <TABLEA> into table ITAB1 where

TABLEA-FieldK = K

---

--- so on...

Select D E F from < TableB> into itab2 for all entries in itab1

where TableB-FieldX = Itab1-fieldX

and TableB-FieldY = Itab1-FieldY.

Hope this may help you.

Regards,

Lanka

Read only

0 Likes
849

I think i didn't explained myself correctly.

I wanted to select from the two tables into one internal table not into two of them.

Is this feasible in ABAP?

Regards,

Xibi

Read only

0 Likes
849

Hi,

You you can pull the data from 2 diff tables into one table.& FOR ALL ENTRIES CAN BE USED.

Read only

0 Likes
849

Hi,

using for all entries, and combine the two tables and make it one table.

regards

vijay

Read only

0 Likes
849

Hi Xibi,

You can join the two data base tables during select statement and then you can us "appending the corresponding fields of <ITAB>".

Lanka

Read only

Former Member
0 Likes
849

Hi,

this can be done...

select a
       b
       c
      from <db>
      into table itab.
if sy-subrc = 0.
select b
       d
       from <db2>
       into table itab1
       for all entries in itab
       where b = itab-b.
endif.

regards

vijay

Read only

alejandro_lpez
Contributor
0 Likes
850

Hi,

You can use the follow sentence:

To obtain data from first table

SELECT a b c INTO itab

FROM tab1

WHERE <cond>

and then obtain data from second table, and storage in the same internal table with APPENDING TABLE

SELECT a b c APPENDING TABLE itab

FROM tab2

WHERE <cond>

if this is not what you need, you could make a loop from the first table and then make a read table from second table comparing the no key field

loop at itab.

read table itab2 with key (common not key field) field = itab-field

if sy-subrc eq 0.

move values from itab2 to itab 1.

endif.

modify itab

endloop.

hope this help you.

Alejandro

Read only

Former Member
0 Likes
849

hi Xibi,

use

select afield1 afield2...

from table1 as a

into table itab

inner join table2 as b

on afield = bfield.

i think it works..

regards

satesh