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

Intersection in Select statement

Former Member
0 Likes
1,550

Hi,

Do any one know about some intersection option in select statement.

My case is : I have 2 database tables say TAB1 and TAB2 . TAB1 has data (A, B, C, D) and TAB2 has data (B, D) now I want the output as (A and C) after joining these 2 tables and selecting.

That is I want the values of Table1 which are not there in Table2.

I have the option of selecting Table1 and then for all entries fetch Table2, then Loop at the Table & delete if record exists.

But this is creating performance issue as the number of records in both tables are in Lakhs.

So I wanted to know is there any option like Left Intersecion or some thing like left outer join and all, so that I can pick the dat in one select.

Thanks,

Sameer

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
958

LEFT OUTER JOIN.

Look it up in the ABAP help.

4 REPLIES 4
Read only

Former Member
0 Likes
959

LEFT OUTER JOIN.

Look it up in the ABAP help.

Read only

ThomasZloch
Active Contributor
0 Likes
958

You should be able to do this with a LEFT JOIN of these two tables (check F1 help). However if I remember correctly you cannot use fields of tab2 in the WHERE-condition, as in WHERE TAB2~FIELD1 IS NULL, to not even select those lines where tab2 has no matching entry.

You can delete these rows in a second step from the result table though.

Thomas

P.S. please use international units only, lakh = 100,000

Read only

Former Member
0 Likes
958

I think a subquery may work here. Something like:

SELECT form TAB2 where not in TAB1.

Rob

Read only

Former Member
0 Likes
958

Issue solved :

Sample Code

TYPES : BEGIN OF X_VBAK,

VBELN TYPE VBAK-VBELN,

AUBEL TYPE VBRP-AUBEL.

TYPES : END OF X_VBAK.

DATA : I_VBAK TYPE STANDARD TABLE OF X_VBAK.

DATA : I_VBAS TYPE STANDARD TABLE OF X_VBAK.

SELECT AVBELN BAUBEL INTO CORRESPONDING FIELDS OF TABLE I_VBAK FROM ( VBAK AS A

LEFT OUTER JOIN VBRP AS B ON AVBELN EQ BAUBEL ).

SORT I_VBAK BY VBELN.

delete ADJACENT DUPLICATES FROM i_vbak COMPARING ALL FIELDS.

DELETE I_VBAK WHERE AUBEL NE ''.

SORT I_VBAK BY VBELN.

SORT I_VBAS BY VBELN.