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

SQL querry

Former Member
0 Likes
974

Moderator message: please use a more informative subject in future

Hi,

i want retrive data from mseg and mkpf table, base on material , customer and posting date.

above three fields are report input.

means

customer - abc

material - xyz

date - 10/12/2008 to 10/01/2009

material and customer fields in mseg table .

posting date fields in mkpf table.

code

SELECT * FROM MSEG INTO CORRESPONDING FIELDS OF TABLE IT_MSEG

WHERE MATNR IN MAT AND KUNNR IN CUST .

SELECT * FROM MKPF INTO CORRESPONDING FIELDS OF TABLE IT_MKPF

FOR ALL ENTRIES IN IT_MSEG

WHERE MBLNR = IT_MSEG-MBLNR AND BUDAT IN DATE .

but it not give between posting date record.

Thanks in Advance.

Regard

Sam.

Edited by: Matt on Jan 22, 2009 9:59 AM

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
947

HI Sam,

I would advise you to build a range for MJAHR also from date and use it in both MSEG and MKPF.

Also what other erroneous BUDAT are you getting in the output..can u provide some examples...

and yes MSEG is a transparent table...

so i will suggest you to fetch data using a join..

SELECT (field_list) FROM MKPF as a JOIN mseg as b ON amblnr = bmblnr and amjahr = bmjahr

WHERE ...all conditions...

Edited by: Ankesh Saharan on Jan 22, 2009 12:38 PM

8 REPLIES 8
Read only

Former Member
0 Likes
947

Hi,

try like this,

SELECT * FROM MSEG INTO CORRESPONDING FIELDS OF TABLE IT_MSEG

WHERE MATNR IN MAT AND KUNNR IN CUST .

SELECT * FROM MKPF INTO CORRESPONDING FIELDS OF TABLE IT_MKPF

FOR ALL ENTRIES IN IT_MSEG

WHERE MBLNR = IT_MSEG-MBLNR

AND BUDAT IN DATE

AND MJAHR = IT_MSEG-MJAHR . "Added

Read only

Former Member
0 Likes
947

HELLO

MSEG is a cluster table and the complexity of data in mseg table is very high,so before fetching the data from mseg please make sure that you are providing full primary key details in the where clause so that only the required results are fetched.

hope it helps.

regards

geeta gupta

Read only

SuhaSaha
Product and Topic Expert
Product and Topic Expert
0 Likes
947

Hello Sam,

If you try this way, MSEG will have data for MBLNR not in the date range.

I will suggest use INNER JOINS on MKPF & MSEG.

BR,

Suhas

PS: I suggest this to get consistent data & nothing to do with performance.

Read only

Former Member
0 Likes
947

Suhas,

Why in that case the restriction in WHERE clause for BUDAT IN DATE not work??

Read only

SuhaSaha
Product and Topic Expert
Product and Topic Expert
0 Likes
947

Hello Ankesh,

Quite simple: MSEG has no restriction on BUDAT --> You get data based on the WHERE clause say 20 MBLNRs.

MKPF has BUDAT restriction --> You get 5 MBLNRs from the 20 in IT_MSEG which fall in the date reange.

Now you have Loop at IT_MKPF and delete from IT_MSEG. IF you use JOINS you donot have to worry about this.

Suhas

Read only

Former Member
0 Likes
948

HI Sam,

I would advise you to build a range for MJAHR also from date and use it in both MSEG and MKPF.

Also what other erroneous BUDAT are you getting in the output..can u provide some examples...

and yes MSEG is a transparent table...

so i will suggest you to fetch data using a join..

SELECT (field_list) FROM MKPF as a JOIN mseg as b ON amblnr = bmblnr and amjahr = bmjahr

WHERE ...all conditions...

Edited by: Ankesh Saharan on Jan 22, 2009 12:38 PM

Read only

0 Likes
947

Hi Ankesh and all,

Thanks for answer.

problem Sloved.

Read only

matt
Active Contributor
0 Likes
947

Please use a more informative subject in future