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

Former Member
0 Likes
854

hi all,

iam wrote the code like this but its taking too much time to get the out put, if anybody suggest me which way i ca get good performance.

SELECT KUNNR NAME1 INTO (ITAB-KUNNR,ITAB-NAME1) FROM KNA1

WHERE KUNNR IN S_KUNNR.

SELECT BELNR ZTERM WRBTR AUGDT INTO (ITAB-BELNR,ITAB-ZTERM,ITAB-WRBTR,

ITAB-AUGDT)

FROM BSEG WHERE

KUNNR EQ ITAB-KUNNR

AND BUKRS EQ P_BUKRS

AND AUGDT EQ '00000000'.

SELECT BLDAT INTO (ITAB-BLDAT) FROM BKPF WHERE

BUKRS = P_BUKRS AND BELNR EQ ITAB-BELNR.

ENDSELECT.

ENDSELECT.

ENDSELECT.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
784

Hi,

Remove nested selects instead use all entries.

Follow below hints to imropve performance

1) Remove corresponding from select satement

2) Remove * from select

3) Select field in sequence as defined in database

4) Avoid unnecessary selects

i.e check for internal table not initial

5) Use all entries and sort table by key fields

6) Remove selects ferom loop and use binary search

7) Try to use secondary index when you don't have

full key.

😎 Modify internal table use transporting option

9) Avoid nested loop . Use read table and loop at itab

from sy-tabix statement.

10) free intrenal table memory wnen table is not

required for further processing.

11)

Follow below logic.

FORM SUB_SELECTION_AUFKTAB.

if not it_plant[] is initial.

it_plant1[] = it_plant[].

sort it_plant1 by werks.

delete adjacent duplicates from it_plant1 comparing werks

SELECT AUFNR KTEXT USER4 OBJNR INTO CORRESPONDING FIELDS OF TABLE I_AUFKTAB

FROM AUFK

FOR ALL ENTRIES IN it_plant1

WHERE AUFNR IN S_AUFNR AND

KTEXT IN S_KTEXT AND

  • WERKS IN S_WERKS AND

AUART IN S_AUART AND

USER4 IN S_USER4 AND

werks eq it_plant1-werks.

free it_plant1.

Endif.

Regards

Amole

7 REPLIES 7
Read only

Former Member
0 Likes
785

Hi,

Remove nested selects instead use all entries.

Follow below hints to imropve performance

1) Remove corresponding from select satement

2) Remove * from select

3) Select field in sequence as defined in database

4) Avoid unnecessary selects

i.e check for internal table not initial

5) Use all entries and sort table by key fields

6) Remove selects ferom loop and use binary search

7) Try to use secondary index when you don't have

full key.

😎 Modify internal table use transporting option

9) Avoid nested loop . Use read table and loop at itab

from sy-tabix statement.

10) free intrenal table memory wnen table is not

required for further processing.

11)

Follow below logic.

FORM SUB_SELECTION_AUFKTAB.

if not it_plant[] is initial.

it_plant1[] = it_plant[].

sort it_plant1 by werks.

delete adjacent duplicates from it_plant1 comparing werks

SELECT AUFNR KTEXT USER4 OBJNR INTO CORRESPONDING FIELDS OF TABLE I_AUFKTAB

FROM AUFK

FOR ALL ENTRIES IN it_plant1

WHERE AUFNR IN S_AUFNR AND

KTEXT IN S_KTEXT AND

  • WERKS IN S_WERKS AND

AUART IN S_AUART AND

USER4 IN S_USER4 AND

werks eq it_plant1-werks.

free it_plant1.

Endif.

Regards

Amole

Read only

Former Member
0 Likes
784

You should use join instead of nested selects. to best construct your query please refer to Menu in ABAP Editor Go to Enviornment>Examples>Performance. Then from the left coloumn choose SQL Interface --> Select Over more than one table.

You can find solution of your problem there with some good other examples as well.

Cheers.

Read only

naimesh_patel
Active Contributor
0 Likes
784

Hello,

If you want to take customer related data from BSEG and BKPF.. then better to use the table BSID and BSAD.

As you are only taking initial AUGDT. SO, use table BSID only.

Like,

select kunnr blenr zterm wrbtr augdt bldat

into table it_bsid

from bsid

where bukrs = p_bukrs

and kunnr in s_kunnr.

*check for entries in the it_bsid.

select name1 from kna1

into it_kna1

for all entries in it_bsid

where kunnr = it_bsid.

  • modify your name1 of it_bsid from it_kunnr.

Regards,

Naimesh

Read only

Former Member
0 Likes
784

SELECT BBELNR BZTERM BWRBTR BAUGDT bkunnr kname1

c~bldat

INTO corresponding fields of table itab

FROM BSEG as B inner join kna1 as k on bkunnr = kkunnr

inner join bkpf as c on bbelnr = cbelnr and bbukrs = cbukrs

WHERE KUNNR in s_kunnr

AND BUKRS EQ P_BUKRS

AND AUGDT EQ '00000000'.

Read only

Former Member
0 Likes
784

hi Pravee,

1. First of all try avoiding nested select statement ...

2. Use loop endloop statements inside loop try using read statement

3. avoid using select .. endselect statement ..

Regards,

Santosh

Read only

Former Member
0 Likes
784

SELECT KUNNR NAME1 INTO table ITAB1

FROM KNA1

WHERE KUNNR IN S_KUNNR.

if not itab1[] is initial.

SELECT kunnr BELNR ZTERM WRBTR AUGDT INTO table ITAB2

FROM BSEG

for all entries in itab1

WHERE

KUNNR EQ ITAB1-KUNNR

AND BUKRS EQ P_BUKRS

AND AUGDT EQ '00000000'.

SELECT BELNR BLDAT INTO ITAB3 FROM BKPF

for all entries in itab1

WHERE

BUKRS = P_BUKRS AND BELNR EQ ITAB1-BELNR.

endif.

loop at itab1.

read table itab2 with key kunnr = itab1-kunnr.

if sy-subrc = 0.

itab1-belnr = itab2-belnr.

itab1-zterm = itab2-zterm.

itab1-wrbtr = itab2-wrbtr.

itab1-augdt = itab2-augdt.

endif.

read table itab3 with key belnr = itab1-belnr.

if sy-subrc = 0.

itab1-bldat = itab3-bldat.

endif.

modify itab1 index sy-tabix.

endloop.

Regards,

Ravi

Read only

Former Member
0 Likes
784

Hi,

try this code

tables:kna1,bseg,bkpf.

data:begin of itab1 occurs 0,

kunnr like kna1-kunnr,

name1 like kna1-name1,

end of itab1.

data:begin of itab2 occurs 0,

belnr like bseg-belnr,

zterm like bseg-zterm,

wrbtr like bseg-wrbtr,

augdt like bseg-augdt,

kunnr like bseg-kunnr,

bukrs like bseg-bukrs,

end of itab2.

data:begin of itab3 occurs 0,

bldat like bkpf-bldat,

bukrs like bkpf-bukrs,

belnr like bkpf-belnr,

end of itab3.

parameters:p_bukrs like bkpf-bukrs.

select-options:s_kunnr for kna1-kunnr.

select kunnr name1 from kna1

into table itab1

where kunnr in s_kunnr.

select belnr zterm wrbtr augdt from bseg

into corresponding fields of table itab2

for all entries in itab1

where kunnr = itab1-kunnr and

bukrs = p_bukrs and

augdt = '00000000'.

select bldat from bkpf

into corresponding fields of table itab3

for all entries in itab2

where bukrs = p_bukrs and

belnr = itab2-belnr.

regards,

sowjanya