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

Join query

Former Member
0 Likes
572

Hi friends,

I need to join AUFK and AUAK based on OBJNR.

Here below is my query.

SELECT AAUFNR AKOKRS AOBJNR AKDAUF

INTO TABLE T_AUFK

FROM AUFK AS A

INNER JOIN

AUAK AS B

ON AOBJNR EQ BOBJNR

WHERE B~PERIO IN S_PERIO

AND B~BUGJAHR IN S_BUGJAH

AND A~WERKS IN S_WERKS.

It is working but not correctly.

For the given condition there is a single record only.

The output is 3 records of same information (duplication of single record).

I found that in aufk only one record where as in auak the objnr is present in 3 records. I think this may be a reason. Pls tell me the correct query to do.

Thank u.

4 REPLIES 4
Read only

Former Member
0 Likes
540

Hi

The querry is correct

There may be a 3 settlement Document numbers(BELNR) for the same order(AUFK-OBJNR)

check the field values of BELNR are they same or different.

If they are different it is right.

if they are same they it is wrong.

Then sort the ITAB by AUFNR KOKRS BELNR

and use delete adjacent duplicates from ITAB comparing AUFNR BELNR.

Reward points for useful Answers

Regards

Anji

Read only

Former Member
0 Likes
540

Hi Murugan,

Try this...

SELECT <i>DISTINCT</i> AAUFNR AKOKRS AOBJNR AKDAUF

INTO TABLE T_AUFK

FROM AUFK AS A

INNER JOIN

AUAK AS B

ON AOBJNR EQ BOBJNR

WHERE B~PERIO IN S_PERIO

AND B~BUGJAHR IN S_BUGJAH

AND A~WERKS IN S_WERKS.

Read only

Former Member
0 Likes
540

Please try following changed query

SELECT A~AUFNR

B~KOKRS

B~OBJNR

A~KDAUF

INTO TABLE T_AUFK

FROM AUFK AS A

INNER JOIN AUAK AS B

ON AOBJNR EQ BOBJNR

WHERE B~PERIO IN S_PERIO

AND B~BUGJAHR IN S_BUGJAH

AND A~WERKS IN S_WERKS.

Read only

Former Member
0 Likes
540

Hi,

The problem is bcoz there are 3 records maintained for objnr in auak. Since u r fetching values only from aufk, u will be fetching the same records again and again. I am not sure how exactly the two tables are related. If u have more idea on their relation, then u can add some more condition check so that by the objnr in aufk along with some other field will point to only one record in auak.

Otherwise if its not possible, u can fetch the data into the internal table t_aufk.

Then sort the internal table by objnr.

delete adjacent duplicates from t_aufk.

these will remove the duplicate records.

reward if useful

regards

anoop