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: 

Is it possible to take lifnr(5) in WHERE Clause of SELECT Statement

former_member435508
Participant
0 Kudos
389

Hi,

I have to take Invoice only for 1 & 2 Series Vendors. i.e. Lifnr = 01********** & 02**********.

I try it with diff codes - As -->


SELECT belnr gjahr budat lifnr lifnr(2) FROM rbkp
                         INTO (it_final-belnr, it_final-gjahr, it_final-budat, it_final-lifnr, v_lifnr)
                         WHERE budat IN so_budat
                           AND tcode = 'MIRO'
                           AND stblg = ''
                           AND lifnr(2) IN ('01','02').
" Syntax error

But not getting the correct Syntax. Is it possible to work like it?

Itwill give major diff on Performance if I can filter it in SELECT Statement.

Edited by: Priya.ABAP on Feb 25, 2011 10:34 AM

1 ACCEPTED SOLUTION

Former Member
0 Kudos
245

Hi Priya,

The code should be :


lifnr like '01%'.....

For your referenece see the below example..


data : it_lfa1 type TABLE OF lfa1.
select *
  from lfa1
  into TABLE it_lfa1
  WHERE LIFNR LIKE '00003%'.

I have tested it.

It will select the vendors correponding to '00003...'

Hope it helps you.

Thanks

Arbind

9 REPLIES 9

Former Member
0 Kudos
245

i think you can use option of % in the where clause

where lifnr = '01 %'

try this option ..

Edited by: sniper on Feb 25, 2011 3:10 PM

0 Kudos
245

Thanks.

I already try this options.

@Sniper

where lifnr = '01 %'

It's giving me Initial ITAB (sy-subrc = 4).

@Anilbhai

Yes, I have to compare first two Char Only.

lifnr + 0(2) in ( '01', '02') is also giving syntax error.

" Field lifnr+0(2) is unknown.

Former Member
0 Kudos
245

Hi,

Do you want to compare exactily first two characters of lifnr ?

then try using lifnr + 0(2) in ( '01', '02').

Thanks & Regards,

Anil Bhai

Former Member
0 Kudos
246

Hi Priya,

The code should be :


lifnr like '01%'.....

For your referenece see the below example..


data : it_lfa1 type TABLE OF lfa1.
select *
  from lfa1
  into TABLE it_lfa1
  WHERE LIFNR LIKE '00003%'.

I have tested it.

It will select the vendors correponding to '00003...'

Hope it helps you.

Thanks

Arbind

0 Kudos
245

Thanks Arbind.

I did it with LIKE statement only - But it works only for One Option and Not if I go for Three.

Like -->


SELECT belnr gjahr budat lifnr FROM rbkp
                         INTO (it_final-belnr, it_final-gjahr, it_final-budat, it_final-lifnr)
                         WHERE budat IN so_budat
                           AND tcode = 'MIRO'
                           AND stblg = ''
                           AND lifnr LIKE '01%'.
*This works Fine - and give me all Invoices for 1 Series Vendor - No issues"

But My Requirement is for Multiple - Like 1, 2 & 3 Series

And when I try it as -


SELECT belnr gjahr budat lifnr FROM rbkp
                         INTO (it_final-belnr, it_final-gjahr, it_final-budat, it_final-lifnr)
                         WHERE budat IN so_budat
                           AND tcode = 'MIRO'
                           AND stblg = ''
                           AND lifnr LIKE '01%' OR lifnr LIKE '02%' OR lifnr LIKE '03%'.
*In this Case it's giving me sy-subrc = 4. (Records are there in RBKP)

0 Kudos
245

Try this:

SELECT belnr gjahr budat lifnr FROM rbkp

INTO (it_final-belnr, it_final-gjahr, it_final-budat, it_final-lifnr)

WHERE budat IN so_budat

AND tcode = 'MIRO'

AND stblg = ''

AND ( lifnr LIKE '01%' OR lifnr LIKE '02%' OR lifnr LIKE '03%' ).

0 Kudos
245

Hi,

It should be like...


                        WHERE budat = '1'
                          AND tcode = 'MIRO'
                          AND stblg = ''
                          AND ( lifnr LIKE '01%' OR lifnr LIKE '02%' OR lifnr LIKE '03%' ).

Try it out.

It will work.

Thanks

Arbind

Former Member
0 Kudos
245

Hi Priya,

You have to use 'Like' statement to get the exact linked Vendors.

Thanks

Arbind

Edited by: Arbind Prasad on Feb 25, 2011 3:50 PM

0 Kudos
245

Pls try this way. don't know whether it is useful for you

DATA : it_lfa1 TYPE TABLE OF lfa1,

wa_lfa1 like LINE OF it_lfa1.

SELECT *

FROM lfa1

INTO TABLE it_lfa1.

LOOP AT it_lfa1 INTO wa_lfa1

WHERE ( lifnr0(2) = '01' OR lifnr0(2) = '02').

********do your coding here***

ENDLOOP.

Regds,

AnilBhai