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 data from one table which are not in another table

Former Member
0 Likes
7,804

Hi All,

I need to select onlyl those MBLNR from MKPF

Which MBLNR are not in BKPF.

I have write code like below:


DATA : BEGIN OF T_BKPF OCCURS 0,
              BELNR LIKE BKPF-BELNR,
       END OF T_BKPF.

DATA: BEGIN OF T_MKPF OCCURS 0,
             MBLNR LIKE MKPF-MBLNR,
        END OF T_MKPF.

SELECT BELNR INTO CORRESPONDING FIELDS OF TABLE T_BKPF.

SELECT MBLNR INTO CORRESPOMDING FIELDS OF TABLE T_MKPF
             WHERE MBLNR NOT IN T_BKPF.

But its not correct. Please tell me how can I get the data.

with thanks,

Moshior

1 ACCEPTED SOLUTION
Read only

former_member186741
Active Contributor
0 Likes
3,223

this might not be very efficient but you could use a sub-query in the select:

data t type table of mkpf.

select * from mkpf

into table t

where not exists

( select * from bkpf

where belnr = mkpf~mblnr )

Hi All,

I need to select onlyl those MBLNR from MKPF

Which MBLNR are not in BKPF.

I have write code like below:


DATA : BEGIN OF T_BKPF OCCURS 0,
              BELNR LIKE BKPF-BELNR,
       END OF T_BKPF.

DATA: BEGIN OF T_MKPF OCCURS 0,
             MBLNR LIKE MKPF-MBLNR,
        END OF T_MKPF.

SELECT BELNR INTO CORRESPONDING FIELDS OF TABLE T_BKPF.

SELECT MBLNR INTO CORRESPOMDING FIELDS OF TABLE T_MKPF
             WHERE MBLNR NOT IN T_BKPF.

But its not correct. Please tell me how can I get the data.

with thanks,

Moshior

5 REPLIES 5
Read only

Former Member
0 Likes
3,223

hi

range : r_xblnr for bkpf-xblnr.

SELECT XBLNR from bkpf and populate into range r_xblnr.

SELECT MBLNR INTO CORRESPOMDING FIELDS OF TABLE T_MKPF

WHERE MBLNR NOT IN r_xblnr.

Edited by: Sachin Patil on Oct 14, 2010 9:30 AM

Read only

former_member186741
Active Contributor
0 Likes
3,224

this might not be very efficient but you could use a sub-query in the select:

data t type table of mkpf.

select * from mkpf

into table t

where not exists

( select * from bkpf

where belnr = mkpf~mblnr )

Read only

0 Likes
3,223

Hi Neil,

Thanks..........Problem is solved

Read only

Former Member
0 Likes
3,223

Hi,

I'm not sure that your data selection makes sense. Normally MKPF-MBLNR and BKPF-BELNR are completely different document types.

But if it is true, then please verify, whether you have to check for the year MKPF-MJAHR vs. BKPF-GJAHR, too.

Those document numbers in both tables are not unique by there numbers!

Regards,

Klaus

Read only

Former Member
0 Likes
3,223

Hi Friend,