Application Development 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: 

Problem in select statement

Former Member
0 Kudos

Hi Abap Gurus,

In my select statement iam picking up right data, Here the thing is when i give one single pernr, i need to get 1 single pernr's data.

Here in this select statement iam getting all the data.

SELECT * FROM PA0001

INTO TABLE IT_PERNR

WHERE PERNR IN SO_PERNR OR

PERSK EQ 'FG' OR

PERSK EQ 'MI' OR

PERSK EQ 'GM' OR

PERSK EQ 'TL' OR

BTRTL IN SO_BTRTL AND

ENDDA GE W_ENDDA AND

BEGDA LE W_BEGDA.

Thanks and Regards,

-Anil

Points will be rewarded....

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Anil,

Try with this.

SELECT * FROM PA0001

INTO TABLE IT_PERNR

WHERE PERNR IN SO_PERNR OR

PERSK IN ( 'FG' , 'MI' , 'GM' , 'TL' ) OR

BTRTL IN SO_BTRTL AND

ENDDA GE W_ENDDA AND

BEGDA LE W_BEGDA.

(OR )

SELECT * FROM PA0001

INTO TABLE IT_PERNR

WHERE PERNR IN SO_PERNR AND

PERSK IN ( 'FG' , 'MI' , 'GM' , 'TL' ) OR

BTRTL IN SO_BTRTL AND

ENDDA GE W_ENDDA AND

BEGDA LE W_BEGDA.

Don't forget to reward if useful...

10 REPLIES 10

Former Member
0 Kudos

Hi,

USe SELECT SINGLE..

SELECT SINGLE * FROM PA0001

INTO TABLE IT_PERNR

WHERE PERNR IN SO_PERNR OR

PERSK EQ 'FG' OR

PERSK EQ 'MI' OR

PERSK EQ 'GM' OR

PERSK EQ 'TL' OR

BTRTL IN SO_BTRTL AND

ENDDA GE W_ENDDA AND

BEGDA LE W_BEGDA.

Reward Appropriate points.

Regards,

MAnsi.

Former Member
0 Kudos

Hi,

If you want to fetch only single record then you need to use the SINGLE keyword in your SELECT query...

SELECT SINGLE * FROM PA0001

INTO TABLE IT_PERNR

WHERE PERNR IN SO_PERNR OR

PERSK EQ 'FG' OR

PERSK EQ 'MI' OR

PERSK EQ 'GM' OR

PERSK EQ 'TL' OR

BTRTL IN SO_BTRTL AND

ENDDA GE W_ENDDA AND

BEGDA LE W_BEGDA.

Reward points if useful.

Thanks.

Former Member
0 Kudos

try SELECT SINGLE * FROM PA0001

........................................

0 Kudos

try this,

SELECT * FROM PA0001

INTO TABLE IT_PERNR

WHERE PERNR IN SO_PERNR and

( PERSK EQ 'FG' OR

PERSK EQ 'MI' OR

PERSK EQ 'GM' OR

PERSK EQ 'TL' ) and

BTRTL IN SO_BTRTL AND

ENDDA GE W_ENDDA AND

BEGDA LE W_BEGDA.

Former Member
0 Kudos

try select single.....from Dbtab

0 Kudos

U have to specify all these fields

PERNR

SUBTY

OBJPS

SPRPS

ENDDA

BEGDA

SEQNR

in ur select query. then u will get exactly one row

Narendra

former_member699750
Participant
0 Kudos

hiii...use select single statement..and also if ur going to give single pernr u can directly pass like PERNR = SO_PERNR,if SO_PERNR contains single value, change ur code like this..

SELECT single * FROM PA0001

INTO TABLE IT_PERNR

WHERE PERNR IN SO_PERNR and

( PERSK EQ 'FG' OR

PERSK EQ 'MI' OR

PERSK EQ 'GM' OR

PERSK EQ 'TL' ) and

BTRTL IN SO_BTRTL AND

ENDDA GE W_ENDDA AND

BEGDA LE W_BEGDA

reward if usefull

Edited by: Sugumar Ganesan on Feb 5, 2008 6:44 AM

Former Member
0 Kudos

Select SIngle query will fetch you a single record.. keep in mind in the where clause you have provided all key fields as conditions.

Alternatively you can also use query SELECT UP TO 1 ROWS query. This will also give you only one (the first match) record.

0 Kudos

Try with below code

Replace OR by AND

SELECT * FROM PA0001

INTO TABLE IT_PERNR

WHERE PERNR IN SO_PERNR AND

PERSK IN ( 'FG' , 'MI', 'GM', 'TL' ) AND

BTRTL IN SO_BTRTL AND

ENDDA GE W_ENDDA AND

BEGDA LE W_BEGDA.

If u give OR condition in pernr it will check for the pernr in the select option and if it fails it check for the next condition.

If possible make the PERSK into a range .

Hope this will do.

Former Member
0 Kudos

Anil,

Try with this.

SELECT * FROM PA0001

INTO TABLE IT_PERNR

WHERE PERNR IN SO_PERNR OR

PERSK IN ( 'FG' , 'MI' , 'GM' , 'TL' ) OR

BTRTL IN SO_BTRTL AND

ENDDA GE W_ENDDA AND

BEGDA LE W_BEGDA.

(OR )

SELECT * FROM PA0001

INTO TABLE IT_PERNR

WHERE PERNR IN SO_PERNR AND

PERSK IN ( 'FG' , 'MI' , 'GM' , 'TL' ) OR

BTRTL IN SO_BTRTL AND

ENDDA GE W_ENDDA AND

BEGDA LE W_BEGDA.

Don't forget to reward if useful...