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 quiry

Former Member
0 Likes
879

I need to restrict values to specific cost centers. I need to pick up all cost centers that end with '452' and cost centers that end with '470' . I also need all cost centers that end with numbers between '452' and '470'.

example of Cost Center: 100VT452

7 REPLIES 7
Read only

Former Member
0 Likes
823

Hi Mahesh,

U can do something like this. First select all the entries from DB table. And then filter that which ur criteria. Something like this....

data : kostl type kmzei-kostl,

itab type standard table of kmzei with header line,

itab1 type standard table of kmzei with header line.

data : cost_center type i.

select * from kmzei into table itab.

loop at itab.

cost_center = itab-kostl+7(3).

if cost_center >= 452 and cost_center <= 470.

move itab to itab1.

append itab1.

endif.

endloop.

loop at itab1.

write : / itab1-kostl.

endloop.

-SatyaPriya

Read only

seshatalpasai_madala
Product and Topic Expert
Product and Topic Expert
0 Likes
823

Hi,

If 100VT is common in all the cost centersthat you want then you can easily get it by creating an internal table of these values like this.

DATA: itab type table of cost_center_type,

wa_cost type cost_center_type.

DO 18 times.

DATA: str type string,

number type I value 452.

concatenate '100VT' number into str.

wa_cost = str.

append wa_cost to itab.

ENDDO.

then use this itab in SELECT quey WHERE IN.

concatenate '%' number into str.

And to find out cost center that end with say 452 you need to do SELECT WHERE cost center LIKE str.

Regards,

Sesh

Read only

Former Member
0 Likes
823

Hi Mahesh ,

Create a range and fill it with values like

'%452' to get all cost centers that end with 452 and in similar way for your all other cases.

Then use this range in your select statement.

Regards

Arun

Read only

jayanthi_jayaraman
Active Contributor
0 Likes
823

Hi,

Select * from db into table itab where kostl like '%452' or kostl like '%470'.

Message was edited by:

Jayanthi Jayaraman

Read only

Former Member
0 Likes
823

Hi Mahesh,

You can do something like this.

select single kostl

from <DB table>

into lv_kostl_452

where kostl like '%452'.

this will give you the first one of type .......452

Similarly the same u can do for 470 to select into lv_kostl_470

Now u can create a range like this 'I BT lv_kostl_452 lv_kostl_470' say this range be lv_range

so your select query now you can write is

Select kostl

from <DB table>

into table <int table>

where kostl in lv_range

or kostl like %470.

This will do it.

Regards

Nishant

Read only

Former Member
0 Likes
823

HI,

Use the where condition similar to Oracle/Sql query.

Select f1 f2 into table int_tab1 from tbl1

where kostl like '%452'

or kostl like '%470'.

Regards

Subramanian

Read only

Former Member
0 Likes
823

Hi Mahseh,

Please read this......

<b>Comparing Strings</b>

To find out whether the value of a column matches a pattern, use:

SELECT ... WHERE <s> [NOT ] LIKE <f> [ESCAPE <h>] ...

The condition is true if the value of the column <s> matches [does not match] the pattern in the data object <f>. You can only use this test for text fields. The data type of the column must be alphanumeric. <f> must have data type C.

You can use the following wildcard characters in <f>:

% for a sequence of any characters (including spaces).

_ for a single character.

For example, ABC_EFG% matches the strings ABCxEFGxyz and ABCxEFG, but not ABCEFGxyz. If you want to use the two wildcard characters explicitly in the comparison, use the ESCAPE option. ESCAPE <h> specifies an escape symbol <h>. If preceded by <h>, the wildcards and the escape symbol itself lose their usual function within the pattern <f>. The use of _ and % corresponds to Standard SQL usage. Logical expressions elsewhere in ABAP use other wildcard characters (+ and *).

You cannot use LIKE in the ON condition of the FROM clause.