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: 

Select query

former_member569226
Participant
0 Kudos

Hi,

S114010001

S118000001

S840100001

S168000001

S840100001

S128000001

S840100001

S128000001

I want to write a select queries where I need to pick the entries starting with S11* or S12*.

Similar way another query where it picks entries that will not start with S11* or S12*.

Example:

select single hkont into x_hkont from bseg where

belnr = vbrk-vbeln

and hkont like 'S11%'

or hkont like 'S12%'.

will the above query works? also I need other query where hkont is not equal to S11% or S12% that means it should select other than S11* or S12*.

Best Regards

MS

4 REPLIES 4

andreas_mann3
Active Contributor
0 Kudos

you must be carefule with: and / or

try:

select single hkont into x_hkont from bseg

where belnr = vbrk-vbeln

and ( hkont like 'S11%'

or hkont like 'S12%' ) .

(or better here : use select-options or ranges -> S_HKONT for BSEG-HKONT )

btw: this is a "bad" select-query becaus table bseg can rapid increase to 10.000.000++ documents

so be careful and try to use (here) tables bsis or bsas - otherwise use first table bkpf

-> and select bseg with key BUKRS,BELNR,GJAHR

grx

Andreas

Edited by: Andreas Mann on Jul 26, 2010 4:28 PM

Former Member
0 Kudos

This should work.

But I suggest do it in a better way. HKONT is not a key field & you are using only one key field in your select statement 'BELNR'. Instead of heaving two select statements, you rather TRY TO use your complete primary key BUKRS, BELNR, GJAHR & LINE ITEM.

After selecting the data, loop this itab and filter your data into two separate itabs and also perform any operations and calculation in the same loop. This way, you can avoid 2 selects and fetching data with flash card signs and non-key fields.

Hope this helps..

Thanks,

Kiran

Former Member
0 Kudos

Suresh..

definitely follow what kiran said.. but still if you just want your code to work..

you need to put the or condition in bracket..else it wont work.

it should be like..

select single hkont into x_hkont from bseg where
belnr = vbrk-vbeln and 
( hkont like 'S11%'                  "===> i have added brackets..
or hkont like 'S12%' ).

Former Member
0 Kudos

Moderator message - Please do not ask or answer basic questions - thread locked Rob