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 issue

Former Member
0 Likes
565

How to improve the performance of the following code

FORM get_data.

  • Extract Data from BKPF table

SELECT bukrs budat gjahr belnr monat blart waers

INTO TABLE it_bkpf

FROM bkpf

WHERE bukrs = p_bukrs

AND blart IN s_blart

AND budat IN s_budat.

SORT it_bkpf by belnr ascending.

IF NOT it_bkpf[] IS INITIAL.

  • Extract Data from BSEG table

SELECT bukrs belnr werks hkont aufnr dmbtr sgtxt

INTO TABLE it_bseg

FROM bseg

FOR ALL ENTRIES IN it_bkpf

WHERE belnr = it_bkpf-belnr

AND GJAHR = it_bkpf-gjahr

  • AND valut = it_bkpf-budat

AND bukrs = p_bukrs

AND werks = p_werks

AND hkont IN s_hkont

AND aufnr IN s_aufnr.

  • AND shkzg = 'H'.

ENDIF.

SORT it_bseg by belnr ascending.

*DELETE ADJACENT DUPLICATES FROM it_bseg COMPARING BUKRS AUFNR HKONT.

LOOP AT it_bseg.

READ TABLE it_bkpf WITH KEY

belnr = it_bseg-belnr BINARY SEARCH.

IF sy-subrc = 0.

it_detail-budat = it_bkpf-budat.

it_detail-period = it_bkpf-budat+0(6).

it_detail-hkont = it_bseg-hkont.

it_detail-aufnr = it_bseg-aufnr.

it_detail-sgtxt = it_bseg-sgtxt.

it_detail-blart = it_bkpf-blart.

it_detail-dmbtr = it_bseg-dmbtr.

it_detail-waers = it_bkpf-waers.

APPEND it_detail.

CLEAR it_detail.

ENDIF.

ENDLOOP.

  • Currency Conversion.

LOOP AT it_detail.

IF p_waers IS NOT INITIAL.

CALL FUNCTION 'CONVERT_TO_FOREIGN_CURRENCY'

EXPORTING

date = P_xdate

foreign_currency = p_waers

local_amount = it_detail-dmbtr

local_currency = it_detail-waers

type_of_rate = p_kurst

IMPORTING

foreign_amount = it_detail-dmbtr

EXCEPTIONS

no_rate_found = 1

overflow = 2

no_factors_found = 3

OTHERS = 4.

IF sy-subrc = 0.

CLEAR it_detail-waers.

it_detail-waers = p_waers.

MODIFY it_detail. " transporting dmbtr.

ENDIF.

ELSE.

ENDIF.

ENDLOOP.

ENDFORM. "get_data

1 ACCEPTED SOLUTION
Read only

vinod_vemuru2
Active Contributor
0 Likes
542

Hi Kumar,

First thing is select on cluster table will be slow. We can't help it. But find below Few tips to improve the performance of ur code.

SELECT bukrs budat gjahr belnr monat blart waers

INTO TABLE it_bkpf

FROM bkpf

WHERE bukrs = p_bukrs

AND blart IN s_blart

AND budat IN s_budat.

it_bkpf_temp[] = it_bkpf[].

SORT it_bkpf_temp BY belnr gjahr budat.

DELETE ADJACENT DUPLICATES FROM it_bkpf_temp COMPARING belnr gjahr budat.

SORT it_bkpf by belnr ascending.

IF NOT it_bkpf_temp[] IS INITIAL.

Extract Data from BSEG table

SELECT bukrs belnr werks hkont aufnr dmbtr sgtxt

INTO TABLE it_bseg

FROM bseg

FOR ALL ENTRIES IN it_bkpf_temp

WHERE belnr = it_bkpf_temp-belnr

AND GJAHR = it_bkpf_temp-gjahr

AND valut = it_bkpf_temp-budat

AND bukrs = p_bukrs

AND werks = p_werks

AND hkont IN s_hkont

AND aufnr IN s_aufnr.

AND shkzg = 'H'.

ENDIF.

SORT it_bkpf by belnr. "Ascending is by default.

Second thing is why do u need this extra table and loop(it_detail). Can't we loo at it_bseg and puth checks accordinly?

Also avoid header lines. These are slow compared to explicit work areas.

Thanks,

Vinod.

4 REPLIES 4
Read only

Former Member
0 Likes
542

Hi Kumar,

Before fetching data from BKPF , use tables BSIK & BSAK appending the entries from both & based on these, fetch data from BKPF. It will improve the performance a lot.

I too faced the same problem.

Hope this helps you too.

Reward if helpful.

Regards,

Sipra

Read only

0 Likes
542

Hi Sipra

Can u pls give me the sample coding for this

Read only

Former Member
0 Likes
542

Hello Kumar-

Accessing cluster table gives poor perfomance instead use index tables for the requirement.

For ex:vendor use bsik and bsak

customer bsid and bsad

g/l bsis and bsas.

send me your id i will fwd table relations exe file which will be very helpful.

Cheers,

~Srini....

Read only

vinod_vemuru2
Active Contributor
0 Likes
543

Hi Kumar,

First thing is select on cluster table will be slow. We can't help it. But find below Few tips to improve the performance of ur code.

SELECT bukrs budat gjahr belnr monat blart waers

INTO TABLE it_bkpf

FROM bkpf

WHERE bukrs = p_bukrs

AND blart IN s_blart

AND budat IN s_budat.

it_bkpf_temp[] = it_bkpf[].

SORT it_bkpf_temp BY belnr gjahr budat.

DELETE ADJACENT DUPLICATES FROM it_bkpf_temp COMPARING belnr gjahr budat.

SORT it_bkpf by belnr ascending.

IF NOT it_bkpf_temp[] IS INITIAL.

Extract Data from BSEG table

SELECT bukrs belnr werks hkont aufnr dmbtr sgtxt

INTO TABLE it_bseg

FROM bseg

FOR ALL ENTRIES IN it_bkpf_temp

WHERE belnr = it_bkpf_temp-belnr

AND GJAHR = it_bkpf_temp-gjahr

AND valut = it_bkpf_temp-budat

AND bukrs = p_bukrs

AND werks = p_werks

AND hkont IN s_hkont

AND aufnr IN s_aufnr.

AND shkzg = 'H'.

ENDIF.

SORT it_bkpf by belnr. "Ascending is by default.

Second thing is why do u need this extra table and loop(it_detail). Can't we loo at it_bseg and puth checks accordinly?

Also avoid header lines. These are slow compared to explicit work areas.

Thanks,

Vinod.