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: 

is this code correct ?

Former Member
0 Kudos

hello,

is this performance wise correct,



LOOP BSEG INTO WA.

  AT NEW BUZEI.

   SELECT SINGLE * FROM TABLE INTO VARIABLE WHERE ....

   SELECT SINGLE * FROM TABLE INTO VARIABLE WHERE ....

   SELECT SINGLE * FROM TABLE INTO VARIABLE WHERE ....
 
   WRITE:/ value, wa-value.

  ENDAT.

ENDLOOP.

Message was edited by: shehryar dahar

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Performance cannot be measured like this. You have to give the exact code. If your table is a small table and you are hitting an index all the time, then I don't see why it will be a problem. But if your table has a lot of data and your WHERE clause is resulting in a sequential search, then yes, performance will be hit badly.

Please give us the exact code, without which this discussion will be with a lot suppositions.

26 REPLIES 26

Former Member
0 Kudos

hi Dahar,

Use read table statement before select single statement ...

Regards,

Santosh

0 Kudos

Santosh, can u demonstrate with an example,

0 Kudos

hi,

here is an example of that..

    READ TABLE it_owners WITH KEY ba_ba_no  =  it_detail-own_no
                                 ba_seq_no =  it_detail-own_seq_no.

also make sure that your internal table in whicb you are collecting have in an order as they are in DB table ...

<b>Please close all your previous threads even this once if it answered by marking all the helpful answers...</b>

Regards,

Santosh

0 Kudos

hi Santosh,

How to get the value after using the read statement and secondly i was told to use read statements instead of select single ??

Former Member
0 Kudos

hi the code should be like this:: and in where condition which fields you are using... if these fileds after buzei in internaltable then u have to use <b>Read statement</b>.

<b>AT NEW table-BUZEI.</b>

read table itab with key buzei = some value.

SELECT SINGLE * FROM TABLE INTO VARIABLE WHERE ....

SELECT SINGLE * FROM TABLE INTO VARIABLE WHERE ....

SELECT SINGLE * FROM TABLE INTO VARIABLE WHERE ....

WRITE:/ value.

ENDAT.

Message was edited by: Ashok Parupalli

Message was edited by: Ashok Parupalli

Former Member
0 Kudos

hi shehryar,

use READ stmts..

check if u have sorted the table...

Former Member
0 Kudos

Well, first off, if you are selecting * you need to select into a table structure; or

Select Single Fieldname From Table Into Variable Where

suresh_datti
Active Contributor
0 Kudos

Unless unaviodable it is preferable not to use SELECTs inside a loop.. you would be better off dumping the required data into itabs & reading them inside the loop instead.

~ Suresh

0 Kudos

hello,

priya.. yes, i have sorted the bseg with belnr and koart.

suresh.. can you demonstrate with an example ?

Former Member
0 Kudos

Hi,

Avoid using selects within a loop.

it affects ur performance.

regards,

keerthi.

former_member181962
Active Contributor
0 Kudos

NOt correct.

Get the selects outside the loop and use for all entries instead.

inside the loop, you have to use read statements

SELECT * FROM TABLE INTO table it_table1

for all entries in it_bseg

WHERE

ERE ....

> LOOP at it_BSEG INTO WA.

>

> AT NEW BUZEI.

>

> read table it_table1 with key ere =

> read table it_table1 with key ere =>

> read table it_table1 with key ere =

>

> WRITE:/ value, wa-value.

>

> ENDAT.

>

> ENDLOOP.

>

Regards,

Ravi

0 Kudos

Hi Ravi,

but i have to read from different tables inside the ' AT NEW BUZEI' ?

0 Kudos

Ravi,

how do i get/display values after using the READ statements. ??

Former Member
0 Kudos

Performance cannot be measured like this. You have to give the exact code. If your table is a small table and you are hitting an index all the time, then I don't see why it will be a problem. But if your table has a lot of data and your WHERE clause is resulting in a sequential search, then yes, performance will be hit badly.

Please give us the exact code, without which this discussion will be with a lot suppositions.

0 Kudos

Hello Advani,

i am writing this from home. Its sumthing like this,

[code]

select * from bkpf into t_bkpf where bldat in s_bldat and blart = 'KZ'.

select * from bseg into wa_bseg where belnr = t_bkpf-belnr.

append wa_bseg into t_bseg.

endselect.

endselect.

clear wa_bseg.

sort t_bseg belnr koart.

LOOP AT t_bseg into waa_bseg.

AT NEW BUZEI.

IF waa_bseg-koart EQ 'K'.

SELECT SINGLE * FROM LFA1 into t_lfa1 where lifnr = waa_bseg-lifnr.

ELSEIF waa_bseg-koart EQ 'D'.

SELECT SINGLE * FROM KNA1 into t_kna1 where kunnr = waa_bseg-kunnr.

ENDIF.

WRITE:/ t_lfa1-name1.

WRITE:/ t_kna1-name1.

WRITE:/ waa_bseg-belnr.

ENDAT.

ENDLOOP.

itz approximately the same code snippet.

0 Kudos

Just as I thought!!. There will not be any performance issue with the LOOP itself as you are hitting the tables with the primary key. Your performance will be bad because of the select statements before that (from BKPF and BSEG). Change that. See if you can pass BUKRS to BKPF select and then change the code as follows:


DATA: BEGIN OF t_bseg OCCURS 0.
        INCLUDE STRUCTURE bseg.
DATA: END OF t_bseg.

DATA: BEGIN OF t_bkpf OCCURS 0,
        bukrs LIKE bkpf-bukrs,
        belnr LIKE bkpf-belnr,
        gjahr LIKE bkpf-gjahr,
        bldat LIKE bkpf-bldat.
DATA: END OF t_bkpf.

SELECT-OPTIONS: s_bldat FOR t_bkpf-bldat.

SELECT bukrs belnr
       gjahr bldat FROM bkpf
                   INTO TABLE t_bkpf
                  WHERE blart EQ 'KZ'.
CHECK sy-subrc = 0.
DELETE t_bkpf WHERE NOT bldat IN s_bldat.

SELECT * FROM bseg
         INTO TABLE t_bseg FOR ALL ENTRIES IN t_bkpf
        WHERE belnr = t_bkpf-belnr.

0 Kudos

If you can add BUKRS in the WHERE clause for BKPF and BSEG selects in my previous code, it will be even more faster.

Also consider going to BSIK, BSAK and BSID and BSAD tables if you are interested only in customer and vendor accounts.

0 Kudos

Hello Adavi,

thanks for the correction. So, the 'AT NEW BUZEI' part is correct ?

0 Kudos

Yes. Just make sure that the work area WA_BSEG is filled in for KUNNR and LIFNR in AT NEW BUZEI. If not, you will have to read that record once again.

0 Kudos

sorry, didnt get it . ?!

'WA_BSEG is filled in for KUNNR and LIFNR ' ??

0 Kudos

In debugging see if the value of WA_BSEG-KUNNR and WA_BSEG-LIFNR are getting reset to '*' instead of actual values.

Within the loop if you are using control break statements such as AT NEW, AT LAST etc., only the values of the fields that are before are available within that AT ... ENDAT block. So in your case, values for BUKRS BELNR GJAHR and BUZEI will be there within the AT ... ENDAT block, but all others will be reset to '*'s. Outside the block, you will again see all the values.

0 Kudos

hello Adavi,

yeah, they are coming . i have used,

LOOP AT T_BSEG into WA_BSEG.

waa_bseg = wa_bseg.

// using waa_bseg instead of wa_bseg.

ENDLOOP.

one more thing, wa_bseg will be of the type,

wa_bseg LIKE LINE OF t_bseg. <- right way ?

i can loop at like the,

LOOP AT t_bseg into wa_bseg.

0 Kudos

thanks all,

i have check the other ways n return to reward the answers...

0 Kudos

Adavi, you there to answer the query in my last thread ?

0 Kudos

> hello Adavi,

>

> yeah, they are coming . i have used,

>

> LOOP AT T_BSEG into WA_BSEG.

>

> waa_bseg = wa_bseg.

>

> // using waa_bseg instead of wa_bseg.

>

> ENDLOOP.

>

>

> one more thing, wa_bseg will be of the type,

>

> wa_bseg LIKE LINE OF t_bseg. <- right way ?

>

> i can loop at like the,

>

> LOOP AT t_bseg into wa_bseg.

That is correct

Former Member
0 Kudos

hi use

Read table xyz with some key value...

thanks

sony