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 single statement out of loop

Former Member
0 Likes
741

Hi

How can we make select single statement out of loop.

eg

LOOP AT WK.

SELECT SINGLE * FROM BKPF WHERE BUKRS = '4187' AND

BELNR = WK-BELNR AND

GJAHR = PROCYR.

...........

...........

.......

ENDLOOP.

To improve the performance we need to put the select single statement out of the loop. How can we do it.

Hi

How can we make select single statement out of loop.

eg

LOOP AT WK.

SELECT SINGLE * FROM BKPF WHERE BUKRS = '4187' AND

BELNR = WK-BELNR AND

GJAHR = PROCYR.

...........

...........

.......

ENDLOOP.

To improve the performance we need to put the select single statement out of the loop. How can we do it.

6 REPLIES 6
Read only

amit_khare
Active Contributor
0 Likes
702

Change it to following -

SELECT * FROM BKPF into table it_bkpf WHERE BUKRS = '4187' .

LOOP AT WK.

Read table it_BKPF with key

BELNR = WK-BELNR.

GJAHR = PROCYR.

...........

...........

.......

ENDLOOP.

Regards,

Amit

Read only

Former Member
0 Likes
702

Hi,

DATA : i_bkpf LIKE BKPF OCCURS 0 WITH

HEADER LINE.

SELECT * FROM BKPF

INTO TABLE i_BKPF

FOR ALL ENTRIES IN WK

WHERE BUKRS = '4187' AND

BELNR = WK-BELNR AND

GJAHR = PROCYR.

LOOP AT WK.

READ TABLE i_BKPF WITH KEY

BUKRS = '4187'

BELNR = WK-BELNR

GJAHR = PROCYR.

IF SY-SUBRC EQ 0.

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

ENDIF.

ENDLOOP.

Don't forget to reward if useful...

Read only

Former Member
0 Likes
702

see i can do it by making select * but the thing is in select * it will return the best match value whereas in select single it returns the best first match values. So dont you think the requirement can change in making select * instead of select single.

Read only

0 Likes
702

Hi Anindita,

Select * will Fetch all the values for given BUKRS and reading within Loop will give the same entry when using select single.

Read only

Former Member
0 Likes
702

But in where we are not giving full key . In this case multiple data will comefor same key.

I dont think select * is a gud option

Read only

0 Likes
702

You are giving it the full key, so FOR ALL ENTRIES is a good option.

Rob