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

Problem in Select Query

Former Member
0 Likes
1,127

Hi All,

I am having a weird problem in my Select Query.

I am working in PM Module.

Select Query is as follows :

SELECT KOKRS GJAHR KSTAR WRTTP OBJNR PERIO WTGBTR

FROM COEP CLIENT SPECIFIED

INTO TABLE WT_COEP

FOR ALL ENTRIES IN WT_AUFK

WHERE MANDT EQ SY-MANDT

AND LEDNR EQ '00'

AND OBJNR EQ WT_AUFK-OBJNR

AND KOKRS EQ 'UB00'

AND KSTAR IN P_KSTAR

AND WRTTP EQ '04'

AND BEKNZ NE 'A'.

The problem is for the object number in table wt_aufk, if there are multiple entries in coep with the same material number i.e multiple line items for same AUFNR and MATNR, then the select query is picking only the first entry for the combination from COEP.

Please help me solve this problem.

Thanks in Advance,

Bhavika

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,089

Hi,

For all enteries will remove all the duplicate entries and only give unique entires.

Cheers,

Surinder

10 REPLIES 10
Read only

Former Member
0 Likes
1,090

Hi,

For all enteries will remove all the duplicate entries and only give unique entires.

Cheers,

Surinder

Read only

0 Likes
1,089

Hi Surinder,

Please suggest me what to use, if not For All Entries.

Thanks

Bhavika

Read only

0 Likes
1,089

Hi,

You can use the FOR ALL ENTRIES but you need add one more field from COEP table which is unique and will not repeat.

SELECT KOKRS 
             BELNR         " << Add these fields in your internal and select
             BUZEI          " << Add these fields in your internal and select
             GJAHR 
             KSTAR 
             WRTTP 
             OBJNR 
             PERIO 
             WTGBTR
FROM COEP CLIENT SPECIFIED
INTO TABLE WT_COEP
FOR ALL ENTRIES IN WT_AUFK
WHERE MANDT EQ SY-MANDT
AND LEDNR EQ '00'
AND OBJNR EQ WT_AUFK-OBJNR
AND KOKRS EQ 'UB00'
AND KSTAR IN P_KSTAR
AND WRTTP EQ '04'
AND BEKNZ NE 'A'.

Read only

0 Likes
1,089

Hi Bhavika,

Instead of FOR ALL ENTRIES, you can use the RANGES.

for more information on the RANGES you will get the from the F1 help..

Thanks

Read only

Former Member
0 Likes
1,089

Even if there are multiple netries for one OBJNR and its picking only first one, i dont see a problem coz u get the object number once. What other entries do you want to compare?

Read only

Former Member
0 Likes
1,089

Hi bhavika kumar,

Make sure that your are selecting data with all key in Table COEP.

Regards,

Suneel G

Read only

Former Member
0 Likes
1,089

Hi Bhavika,

You have not used all the key fields in where clause.

Please make use of following fields in the where clause of your select query

BELNR (Document Number)

BUZEI (Posting row)

Hope this will solve your problem.

Best Regards,

Deepa Kulkarni

Read only

Former Member
0 Likes
1,089

Hi ,

Use the condition in following way.



SELECT KOKRS GJAHR KSTAR WRTTP OBJNR PERIO WTGBTR
FROM COEP 
INTO TABLE WT_COEP
FOR ALL ENTRIES IN WT_AUFK
WHERE OBJNR EQ WT_AUFK-OBJNR
AND LEDNR EQ '00'
AND KOKRS EQ 'UB00'
AND KSTAR IN P_KSTAR
AND WRTTP EQ '04'
AND BEKNZ NE 'A'.

Hope it helps,

RJ

Read only

awin_prabhu
Active Contributor
0 Likes
1,089

Remove all other conditions in 'Where' clause except for fields 'MANDT' and 'OBJNR'.

Just use below query.

SELECT KOKRS GJAHR KSTAR WRTTP OBJNR PERIO WTGBTR

FROM COEP CLIENT SPECIFIED

INTO TABLE WT_COEP

FOR ALL ENTRIES IN WT_AUFK

WHERE MANDT EQ SY-MANDT

AND OBJNR EQ WT_AUFK-OBJNR.

Thanks.

Read only

0 Likes
1,089

Hi,

Many Thanks to all. My Problem is solved.

Regards,

Bhavika