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 Statement

Former Member
0 Likes
979

Dear Friends,

From the MKPF table, I have taken the uniquie document number into Itab-1. In Itab-2 I am selecting all the entries from MSEG.

The code used is as follows:

-


SELECT MBLNR BUDAT

FROM MKPF

INTO CORRESPONDING FIELDS OF TABLE IT_MKPF

WHERE BUDAT LE P_LDATE.

SORT IT_MKPF BY MBLNR BUDAT DESCENDING.

DELETE ADJACENT DUPLICATES FROM IT_MKPF COMPARING

MBLNR.

SELECT BMBLNR BMATNR BBWART BBUKRS BWERKS BLGORT

BSHKZG BMENGE BXAUTO BSOBKZ

FROM MSEG AS B

INNER JOIN MARA AS C

ON BMATNR = CMATNR

INTO TABLE IT_STOCK1 FOR ALL ENTRIES IN IT_MKPF

WHERE B~MBLNR EQ IT_MKPF-MBLNR AND

C~SPART IN ('CT', 'AP', 'AU', 'AC' , 'PJ')

AND B~MATNR IN S_MATNR.

-


The no. range used for last year and this year is same, and hence I am deleting the duplicates from the MKPF itab.

The problem I have observed is that, there are two genuine records available in MSEG for a single MKPF document no. But, in the Itab-2, it is selecting only one record from MSEG, istead of two records.

Pls guide me the solution.

Thanks in advace,

MARK K

11 REPLIES 11
Read only

Former Member
0 Likes
948

as u r using FOR ALL ENTRIES it will take only one doc number

Read only

0 Likes
948

How to get all the records ?

Regards,

Read only

0 Likes
948

oh sorry!

u r using DELETING ADJACENT DUPLICATES COMPARING MBLNR.

this will remove duplicate documents , either specify some more fields in the above statement like

DELETING ADJACENT DUPLICATES COMPARING MBLNR BUDAT .. or remove this statement

Read only

0 Likes
948

Hi,

are you sure those two records qualify the where condition, i feel you got one record because of where condition (only one record satisfied the where condition). can you check it once again

Regards

vijay

Read only

0 Likes
948

Though i use DELETING ADJACENT DUPLICATES COMPARING MBLNR, there is only record in MKPF table (even without deleting) but for the same document no., there are two records in MSEG.

Regards,

Read only

0 Likes
948

All the fields that u r selecting from MSEG and MARA should be same for those two genuine records. That's the reason why only one set of fields are extracted.

<b>Adding primary fields of MSEG and MARA in the selection(not extraction) part should solve ur problem</b>

Read only

0 Likes
948

Hello mark,

You are getting only one entry as you are using 'FOR ALL ENTRIES' statement.

The FOR ALL ENTRIES checks for similar records and considers only one. Refer to Help on 'WHERE' condition - 'for all entries'

You will need to loop through the table to be able to select all records.

Read only

0 Likes
948

HI Mark,

When U use FOR ALL ENTRIES at that time you should select all the key fields from the table. In your select query you are not selecting fields MJAHR and ZEILE. Try to get these fields in the internal table.

I think this must solve your problem.

Regards,

Atish

Read only

Former Member
0 Likes
948

All the fields that u r selecting from MSEG and MARA should be same for those two genuine records. That's the reason why only one set of fields are extracted.

Adding primary fields of MSEG and MARA in the selecting part should solve ur problem

Read only

Former Member
0 Likes
948

after deleting duplicates i think there is only one value for MBLNR.

when u used for all entries in another select it compare only one time with MBLNR. so it takes only one value.

avoid to used delete adjucent comparing MBLNR.

for number range problem just use MJAHR field for current year u take it 2006 or sy-datum+0(4)

<b>SELECT MBLNR BUDAT

FROM MKPF

INTO CORRESPONDING FIELDS OF TABLE IT_MKPF

WHERE BUDAT LE P_LDATE

and MJAHR = sy-datum+0(4) .</b>

Read only

Former Member
0 Likes
948

in the select from MSEG you added <b>AND B~MATNR IN S_MATNR</b> , check this S_MATNR have 2 material numbers or not.

i believe, your S_MATNR is missing out 1 ,so your result also getting based on that.

regards

srikanth