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 on KEKO

Former Member
0 Likes
1,770

I have the material number and the plant. What is the most efficient select to get the latest kalnr(costing estimate) based on date. Doing a select-endselect to find the last record is a performance problem.

Current code:

select kalnr kadky

from keko

where matnr = mbew-matnr

werks = werks-low.

endselect.

Suggestions? Thank you.

1 ACCEPTED SOLUTION
Read only

RichHeilman
Developer Advocate
Developer Advocate
1,403
report zrich_0001.


data: ikeko type table of keko with header line..

parameters: p_matnr type mara-matnr,
            p_werks type marc-werks.


select * from keko into table ikeko
            where matnr = p_matnr
              and werks = p_werks.


sort ikeko descending by kadky.

read table ikeko index 1.


write:/ ikeko-kadky, ikeko-matnr, ikeko-werks, ikeko-LOSGR.

Regards,

Rich Heilman

I have the material number and the plant. What is the most efficient select to get the latest kalnr(costing estimate) based on date. Doing a select-endselect to find the last record is a performance problem.

Current code:

select kalnr kadky

from keko

where matnr = mbew-matnr

werks = werks-low.

endselect.

Suggestions? Thank you.

5 REPLIES 5
Read only

RichHeilman
Developer Advocate
Developer Advocate
1,404
report zrich_0001.


data: ikeko type table of keko with header line..

parameters: p_matnr type mara-matnr,
            p_werks type marc-werks.


select * from keko into table ikeko
            where matnr = p_matnr
              and werks = p_werks.


sort ikeko descending by kadky.

read table ikeko index 1.


write:/ ikeko-kadky, ikeko-matnr, ikeko-werks, ikeko-LOSGR.

Regards,

Rich Heilman

Read only

Former Member
0 Likes
1,403

Hello Janet,

Rather than using Select-EndSelect, you can used Select into internal table....which wll be much faster while processing data.

So query will be...

Select Kalnr kadky

into itab1

from keko

where matnr = mbew-matnr

werks = werks-low.

and then you can loop into itab1 if you want to process data.

Cheers,

Nilesh

Read only

0 Likes
1,403

The SELECT... ENDSELECT is a slower method.

You have no keys fields here so your DB engine will be using the INDEX on MATNR.

select Kalnr kadky

into table The_Table

from keko

where matnr = mbew-matnr

werks = werks-low

descending by kadky.

read table The_table index 1.

Read only

0 Likes
1,403

Or

select single Kalnr kadky into (keko-kalnr, keko-kadky)

from keko

where matnr = mbew-matnr

werks = werks-low

descending by kadky.

Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
1,403

Or you can do something like this.



report zrich_0001.


data: xkeko type keko .

parameters: p_matnr type mara-matnr,
            p_werks type marc-werks.

select * from keko up to 1 rows into  xkeko
            where matnr = p_matnr
              and werks = p_werks
                  order by kadky descending.

endselect.

write:/ xkeko-kadky, xkeko-matnr, xkeko-werks, xkeko-losgr.

Regards,

Rich Heilman