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

performance ..which one is better

Former Member
0 Likes
431

LOOP AT gt_bsak. " INTO wa_bsak.

SELECT SINGLE lifnr FROM lfb1

INTO wa_lifnr

WHERE lifnr = gt_bsak-lifnr

AND bukrs = gt_bsak-bukrs

AND uzawe EQ 'ZN'

.

IF sy-subrc = 0.

DELETE TABLE gt_bsak. "FROM wa_bsak.

EXIT.

ENDIF.

  • Checking document header text,.

SELECT SINGLE bktxt FROM bkpf

INTO wa_bktxt

WHERE bukrs = gt_bsak-bukrs

AND belnr = gt_bsak-belnr

AND gjahr = gt_bsak-gjahr.

IF wa_bktxt+0(5) = 'OTPY:' OR

wa_bktxt+0(5) = 'OTPN:'.

DELETE TABLE gt_bsak. " FROM wa_bsak.

EXIT.

ENDIF.

ENDLOOP.

Is the above loop is ok ..performance point of view ? out of select single and SELECT up to 1 rows which one is the better ?

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
408

Hi Sam,

Avoding a select is always better inside a loop. Whether it is select single or select up to one rows its always better to avoid.

But if the situation is such that you cannot avoid select within a loop then better to use SELECT SINGLE with all KEY FIELDS.

You can also use Field symbols with LOOP as described in the weblog by rich

/people/rich.heilman2/blog/2006/03/07/using-field-symbols-in-loop-statements--performance-boost

Cheers

VJ

Message was edited by: Vijayendra Rao

LOOP AT gt_bsak. " INTO wa_bsak.

SELECT SINGLE lifnr FROM lfb1

INTO wa_lifnr

WHERE lifnr = gt_bsak-lifnr

AND bukrs = gt_bsak-bukrs

AND uzawe EQ 'ZN'

.

IF sy-subrc = 0.

DELETE TABLE gt_bsak. "FROM wa_bsak.

EXIT.

ENDIF.

  • Checking document header text,.

SELECT SINGLE bktxt FROM bkpf

INTO wa_bktxt

WHERE bukrs = gt_bsak-bukrs

AND belnr = gt_bsak-belnr

AND gjahr = gt_bsak-gjahr.

IF wa_bktxt+0(5) = 'OTPY:' OR

wa_bktxt+0(5) = 'OTPN:'.

DELETE TABLE gt_bsak. " FROM wa_bsak.

EXIT.

ENDIF.

ENDLOOP.

Is the above loop is ok ..performance point of view ? out of select single and SELECT up to 1 rows which one is the better ?

2 REPLIES 2
Read only

Former Member
0 Likes
409

Hi Sam,

Avoding a select is always better inside a loop. Whether it is select single or select up to one rows its always better to avoid.

But if the situation is such that you cannot avoid select within a loop then better to use SELECT SINGLE with all KEY FIELDS.

You can also use Field symbols with LOOP as described in the weblog by rich

/people/rich.heilman2/blog/2006/03/07/using-field-symbols-in-loop-statements--performance-boost

Cheers

VJ

Message was edited by: Vijayendra Rao

Read only

Former Member
0 Likes
408

I think logic may be more of a problem here than performance. Do you want to <b>EXIT</b> out of the loop or <b>CONTINUE</b> withe the next loop pass?

Rob