Skip to Content
0
Former Member
Dec 06, 2006 at 04:27 PM

help on performance

54 Views

Hi

ALL

I am new to this forum

I am jez learning ABAP . I anm sure that this site will help me grow in SAP via the help of all the gurus

I thank U all in advance

I have written a code and there is a Performance issue . The particular form 'cal_no_of_orders' is taking lotof time say more than 5 mins to execute can anyone suggest me the better way of writing this where I need to pass the valid to and valid from dates to calculate the noof orders and dollars . please tell me the flaw inthe code

report orders .

*----


  • DICTIONARY TABLES

*----


tables: vbak, "Sales Document: Header Data

vbpa, "Sales Document: Partner

vbuk, "Sales Document: Header Status and Administrative Data

adrc.

----


  • ALV Declarations *

----


type-pools: slis, kkblo.

data: g_repid like sy-repid,

gs_layout type slis_layout_alv,

gt_fieldcat type slis_t_fieldcat_alv,

fieldcat_in like line of gt_fieldcat,

cos_pos type i,

months like komp-anz_monate.

data: g_anzlines type i.

data : t_list_top_of_page type slis_t_listheader.

data : t_list_end_of_list type slis_t_listheader.

data : t_events type slis_t_event.

*----


  • DATA

*----


data: gv_netwr like vbak-netwr,

gv_netwr0 like vbak-netwr,

zvbeln like vbak-vbeln,

gv_count(6) type n,

gv_count0(6) type n,

erdat1 like vbak-erdat,

erdat2 like vbak-erdat,

vkorg like vbak-vkorg,

erdat(25),

hyphen(3) value '---',

p_name1 like adrc-name1,

zlines type i.

*----


  • INTERNAL TABLES

*----


data: begin of zvbak occurs 0,

vbeln like vbak-vbeln, "order no

vgbel like vbak-vgbel, "reference doc num

netwr like vbak-netwr, " amount

end of zvbak.

data: zvbak0 like zvbak occurs 0 with header line.

data: begin of zvbpa occurs 0,

vbeln like vbpa-vbeln,

parvw like vbpa-parvw, " partner function

kunnr like vbpa-kunnr,

adrnr like vbpa-adrnr,

netwr like vbak-netwr,

name1 like adrc-name1,

end of zvbpa.

data: zvbpa0 like zvbpa occurs 0 with header line.

data: alv_tab like zvbpa occurs 0 with header line,

alv_dat like zvbpa occurs 0 with header line.

data: begin of zvbuk occurs 0,

vbeln like vbak-vbeln,

netwr like vbak-netwr,

end of zvbuk.

data: begin of ztab_period occurs 0.

include structure scscp_period_str.

data: name(10) type c,

end of ztab_period.

data ztab_period0 like ztab_period occurs 0 with header line.

*----


  • SELECTION SCREEN

*----


selection-screen begin of block b with frame title text-001 .

select-options: s_erdat for vbak-erdat obligatory,

s_vkorg for vbak-vkorg obligatory.

selection-screen end of block b.

----


*INITIALIZATION.

----


initialization.

g_repid = sy-repid.

----


*START-OF-SELECTION.

----


start-of-selection.

perform select_orders.

*----


**END-OF-SELECTION.

*----


end-of-selection.

describe table alv_tab lines g_anzlines.

if g_anzlines gt 0.

perform display_list.

endif.

&----


*& Form select_orders

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


form select_orders.

data: gv_index like sy-tabix,

ztab like ztab_period,

erdath like vbak-erdat,

erdat_h like vbak-erdat.

erdat1 = s_erdat-low(8).

erdath = s_erdat-high(8).

concatenate erdat1 hyphen erdat_h erdath into erdat.

vkorg = s_vkorg+3(4).

*calculate the no of orders and dollars month wise from the selection

*date

call function 'CSCP_PARA1_GET_PERIODS'

exporting

i_datuv = s_erdat-low

i_datub = s_erdat-high

i_timeunit = 'D'

tables

et_dates = ztab_period.

append ztab_period.

clear ztab_period.

clear gv_index.

*calculate the names of the months

sort ztab_period by datuv.

describe table ztab_period lines zlines.

loop at ztab_period.

gv_index = sy-tabix.

*always delete first record inthe internal table

if ztab_period-sindex = 1.

delete ztab_period.

clear ztab_period.

endif.

endloop.

*Assign Month name and calculate no of orders

clear gv_index.

loop at ztab_period.

gv_index = sy-tabix.

if ztab_period-datuv+4(2) = '01'.

move 'JANUARY' to ztab_period-name.

loop at ztab_period into ztab.

if ztab_period-datuv+4(2) = '01'.

move ztab_period-datuv to ztab-datuv.

move ztab_period-datub to ztab-datub.

endif.

erdat1 = ztab-datuv.

erdat2 = ztab-datub.

perform cal_no_of_orders tables alv_dat

using erdat1 erdat2

changing gv_count0 gv_netwr0.

modify ztab_period index gv_index.

clear : erdat1 , ztab-datuv, erdat2, ztab-datub.

endloop.

clear: erdat1, erdat2, ztab_period-datuv, ztab_period-datub, ztab.

elseif ztab_period-datuv+4(2) = '02'.

move 'FEBRUARY' to ztab_period-name.

loop at ztab_period into ztab.

if ztab_period-datuv+4(2) = '02'.

move ztab_period-datuv to ztab-datuv.

move ztab_period-datub to ztab-datub.

endif.

erdat1 = ztab-datuv.

erdat2 = ztab-datub.

perform cal_no_of_orders tables alv_dat

using erdat1 erdat2

changing gv_count0 gv_netwr0.

modify ztab_period index gv_index.

clear : erdat1 , ztab-datuv, erdat2, ztab-datub.

endloop.

clear: erdat1, erdat2, ztab_period-datuv, ztab_period-datub, ztab.

elseif ztab_period-datuv+4(2) = '03'.

move 'MARCH' to ztab_period-name.

loop at ztab_period into ztab.

if ztab_period-datuv+4(2) = '03'.

move ztab_period-datuv to ztab-datuv.

move ztab_period-datub to ztab-datub.

endif.

erdat1 = ztab-datuv.

erdat2 = ztab-datub.

perform cal_no_of_orders tables alv_dat

using erdat1 erdat2

changing gv_count0 gv_netwr0.

modify ztab_period index gv_index.

clear : erdat1 , ztab-datuv, erdat2, ztab-datub.

endloop.

clear: erdat1, erdat2, ztab_period-datuv, ztab_period-datub, ztab.

elseif ztab_period-datuv+4(2) = '04'.

move 'APRIL' to ztab_period-name.

loop at ztab_period into ztab.

if ztab_period-datuv+4(2) = '04'.

move ztab_period-datuv to ztab-datuv.

move ztab_period-datub to ztab-datub.

endif.

erdat1 = ztab-datuv.

erdat2 = ztab-datub.

perform cal_no_of_orders tables alv_dat

using erdat1 erdat2

changing gv_count0 gv_netwr0.

modify ztab_period index gv_index.

clear : erdat1 , ztab-datuv, erdat2, ztab-datub.

endloop.

clear: erdat1, erdat2, ztab_period-datuv, ztab_period-datub, ztab.

elseif ztab_period-datuv+4(2) = '05'.

move 'MAY' to ztab_period-name.

loop at ztab_period into ztab.

if ztab_period-datuv+4(2) = '05'.

move ztab_period-datuv to ztab-datuv.

move ztab_period-datub to ztab-datub.

endif.

erdat1 = ztab-datuv.

erdat2 = ztab-datub.

perform cal_no_of_orders tables alv_dat

using erdat1 erdat2

changing gv_count0 gv_netwr0.

modify ztab_period index gv_index.

clear : erdat1 , ztab-datuv, erdat2, ztab-datub.

endloop.

clear: erdat1, erdat2, ztab_period-datuv, ztab_period-datub, ztab.

elseif ztab_period-datuv+4(2) = '06'.

move 'JUNE' to ztab_period-name.

loop at ztab_period into ztab.

if ztab_period-datuv+4(2) = '06'.

move ztab_period-datuv to ztab-datuv.

move ztab_period-datub to ztab-datub.

endif.

erdat1 = ztab-datuv.

erdat2 = ztab-datub.

perform cal_no_of_orders tables alv_dat

using erdat1 erdat2

changing gv_count0 gv_netwr0.

modify ztab_period index gv_index.

clear : erdat1 , ztab-datuv, erdat2, ztab-datub.

endloop.

clear: erdat1, erdat2, ztab_period-datuv, ztab_period-datub, ztab.

elseif ztab_period-datuv+4(2) = '07'.

move 'JULY' to ztab_period-name.

loop at ztab_period into ztab.

if ztab_period-datuv+4(2) = '07'.

move ztab_period-datuv to ztab-datuv.

move ztab_period-datub to ztab-datub.

endif.

erdat1 = ztab-datuv.

erdat2 = ztab-datub.

perform cal_no_of_orders tables alv_dat

using erdat1 erdat2

changing gv_count0 gv_netwr0.

modify ztab_period index gv_index.

clear : erdat1 , ztab-datuv, erdat2, ztab-datub.

endloop.

clear: erdat1, erdat2, ztab_period-datuv, ztab_period-datub, ztab.

elseif ztab_period-datuv+4(2) = '08'.

move 'AUGUST' to ztab_period-name.

loop at ztab_period into ztab.

if ztab_period-datuv+4(2) = '08'.

move ztab_period-datuv to ztab-datuv.

move ztab_period-datub to ztab-datub.

endif.

erdat1 = ztab-datuv.

erdat2 = ztab-datub.

perform cal_no_of_orders tables alv_dat

using erdat1 erdat2

changing gv_count0 gv_netwr0.

modify ztab_period index gv_index.

clear : erdat1 , ztab-datuv, erdat2, ztab-datub.

endloop.

clear: erdat1, erdat2, ztab_period-datuv, ztab_period-datub, ztab.

elseif ztab_period-datuv+4(2) = '09'.

move 'SEPTEMBER' to ztab_period-name.

loop at ztab_period into ztab.

if ztab_period-datuv+4(2) = '09'.

move ztab_period-datuv to ztab-datuv.

move ztab_period-datub to ztab-datub.

endif.

erdat1 = ztab-datuv.

erdat2 = ztab-datub.

perform cal_no_of_orders tables alv_dat

using erdat1 erdat2

changing gv_count0 gv_netwr0.

modify ztab_period index gv_index.

clear : erdat1 , ztab-datuv, erdat2, ztab-datub.

endloop.

clear: erdat1, erdat2, ztab_period-datuv, ztab_period-datub, ztab.

elseif ztab_period-datuv+4(2) = '10'.

move 'OCTOBER' to ztab_period-name.

loop at ztab_period into ztab.

if ztab_period-datuv+4(2) = '10'.

move ztab_period-datuv to ztab-datuv.

move ztab_period-datub to ztab-datub.

endif.

erdat1 = ztab-datuv.

erdat2 = ztab-datub.

perform cal_no_of_orders tables alv_dat

using erdat1 erdat2

changing gv_count0 gv_netwr0.

modify ztab_period index gv_index.

clear : erdat1 , ztab-datuv, erdat2, ztab-datub.

endloop.

clear: erdat1, erdat2, ztab_period-datuv, ztab_period-datub, ztab.

elseif ztab_period-datuv+4(2) = '11'.

move 'NOVEMBER' to ztab_period-name.

loop at ztab_period into ztab.

if ztab_period-datuv+4(2) = '11'.

move ztab_period-datuv to ztab-datuv.

move ztab_period-datub to ztab-datub.

endif.

erdat1 = ztab-datuv.

erdat2 = ztab-datub.

perform cal_no_of_orders tables alv_dat

using erdat1 erdat2

changing gv_count0 gv_netwr0.

modify ztab_period index gv_index.

clear : erdat1 , ztab-datuv, erdat2, ztab-datub.

endloop.

clear: erdat1, erdat2, ztab_period-datuv, ztab_period-datub, ztab.

elseif ztab_period-datuv+4(2) = '12'.

move 'DECEMBER' to ztab_period-name.

loop at ztab_period into ztab.

if ztab_period-datuv+4(2) = '12'.

move ztab_period-datuv to ztab-datuv.

move ztab_period-datub to ztab-datub.

endif.

erdat1 = ztab-datuv.

erdat2 = ztab-datub.

perform cal_no_of_orders tables alv_dat

using erdat1 erdat2

changing gv_count0 gv_netwr0.

modify ztab_period index gv_index.

clear : erdat1 , ztab-datuv, erdat2, ztab-datub.

endloop.

clear: erdat1, erdat2, ztab_period-datuv, ztab_period-datub, ztab.

endif.

clear ztab_period-datuv+4(2).

endloop.

endform. " select_orders

*&----


*

*& Form DISPLAY_LIST

*&----


*

  • text

*----


*

  • --> p1 text

  • <-- p2 text

*----


*

form display_list.

g_repid = sy-repid.

perform fillevents.

perform comment_build using t_list_top_of_page.

perform create_layout.

perform create_fieldcat.

call function 'REUSE_ALV_GRID_DISPLAY'

exporting

  • I_INTERFACE_CHECK = ' '

  • I_BYPASSING_BUFFER =

  • I_BUFFER_ACTIVE = ' '

i_callback_program = g_repid

  • I_CALLBACK_PF_STATUS_SET = ' '

  • I_CALLBACK_USER_COMMAND = ' '

i_callback_top_of_page = 'TOP_OF_PAGE'

  • I_CALLBACK_HTML_TOP_OF_PAGE = ' '

  • I_CALLBACK_HTML_END_OF_LIST = ' '

  • I_STRUCTURE_NAME =

  • I_BACKGROUND_ID = ' '

  • I_GRID_TITLE =

  • I_GRID_SETTINGS = gs_settings

is_layout = gs_layout

it_fieldcat = gt_fieldcat

  • IT_EXCLUDING =

  • IT_SPECIAL_GROUPS =

  • IT_SORT = 'X'

  • IT_FILTER =

  • IS_SEL_HIDE =

  • I_DEFAULT = 'X'

i_save = 'A'

  • IS_VARIANT =

it_events = t_events

  • IT_EVENT_EXIT =

  • IS_PRINT =

  • IS_REPREP_ID =

  • I_SCREEN_START_COLUMN = 0

  • I_SCREEN_START_LINE = 0

  • I_SCREEN_END_COLUMN = 0

  • I_SCREEN_END_LINE = 0

  • IT_ALV_GRAPHICS =

  • IT_ADD_FIELDCAT =

  • IT_HYPERLINK =

  • I_HTML_HEIGHT_TOP =

  • I_HTML_HEIGHT_END =

  • IT_EXCEPT_QINFO =

  • IMPORTING

  • E_EXIT_CAUSED_BY_CALLER =

  • ES_EXIT_CAUSED_BY_USER =

tables

t_outtab = alv_tab

  • EXCEPTIONS

  • PROGRAM_ERROR = 1

  • OTHERS = 2

.

if sy-subrc <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

endif.

endform. " DISPLAY_LIST

&----


*& Form comment_build

&----


  • text

----


  • -->P_t_list_top_of_page text

----


form comment_build using t_list_top_of_page type slis_t_listheader.

data : ls_line type slis_listheader.

data : ldate(10),hdate(10).

refresh : t_list_top_of_page.

clear ls_line.

ls_line-info = sy-repid.

ls_line-typ = 'H'.

ls_line-info = 'ORDERS AND DOLLARS REPORT'.

append ls_line to t_list_top_of_page.

write sy-datum to ldate using edit mask '__.__.____' .

clear ls_line.

ls_line-typ = 'A'.

concatenate 'Run Date :' ldate

into ls_line-info separated by space.

append ls_line to t_list_top_of_page.

clear ls_line.

ls_line-typ = 'A'.

ls_line-info = 'User ID :'.

ls_line-info+12 = sy-uname.

append ls_line to t_list_top_of_page.

clear ls_line.

ls_line-typ = 'A'.

ls_line-info = 'No OF ORDERS :'.

ls_line-info+17 = gv_count.

append ls_line to t_list_top_of_page.

clear ls_line.

ls_line-typ = 'A'.

ls_line-info = 'TOTAL dOLLAR AMOUNT :'.

ls_line-info+25 = gv_netwr.

append ls_line to t_list_top_of_page.

clear ls_line.

ls_line-typ = 'A'.

ls_line-info = 'Date Range for Documents :'.

ls_line-info+25 = erdat.

append ls_line to t_list_top_of_page.

clear ls_line.

ls_line-typ = 'A'.

ls_line-info = 'Sales Organization :'.

ls_line-info+25 = vkorg.

append ls_line to t_list_top_of_page.

endform. " comment_build

&----


*& Form fillevents

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


form fillevents.

data l_events type line of slis_t_event.

clear l_events.

l_events-name = 'TOP_OF_PAGE'.

l_events-form = 'TOP_OF_PAGE'.

append l_events to t_events.

*perform top-of-page1.

endform. " fillevents

&----


*& Form create_fieldcat

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


form create_fieldcat.

perform fill_fieldcat using 'KUNNR' 'ALV_TAB' 'SOLD-TO-PARTY' '1' ''.

perform fill_fieldcat using 'NAME1' 'ALV_TAB' 'NAME' '2' ''.

perform fill_fieldcat using 'NETWR' 'ALV_TAB' 'NETVALUE' '3' ''.

endform. " create_fieldcat

&----


*& Form create_layout

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


form create_layout.

gs_layout-colwidth_optimize = 'X'.

gs_layout-zebra = 'X'.

gs_layout-no_totalline = 'X'.

endform. " create_layout

&----


*& Form fill_fieldcat

&----


  • text

----


  • -->P_0564 text

  • -->P_0565 text

  • -->P_0566 text

  • -->P_0567 text

  • -->P_0568 text

----


form fill_fieldcat using p_fname

p_tabname

p_seltext

p_colpos

p_do_sum.

clear fieldcat_in.

fieldcat_in-fieldname = p_fname.

fieldcat_in-tabname = p_tabname.

fieldcat_in-seltext_m = p_seltext.

fieldcat_in-col_pos = p_colpos.

fieldcat_in-do_sum = p_do_sum.

append fieldcat_in to gt_fieldcat.

endform. " fill_fieldcat

&----


*& Form TOP_OF_PAGE

----


form top_of_page.

call function 'REUSE_ALV_COMMENTARY_WRITE'

exporting

i_logo = 'ENJOYSAP_LOGO'

it_list_commentary = t_list_top_of_page.

endform.

.

&----


*& Form cal_no_of_orders

&----


  • text

----


  • -->P_ALV_DAT text

  • -->P_ERDAT1 text

  • -->P_ERDAT2 text

  • <--P_KUNNR text

  • <--P_GV_COUNT text

  • <--P_GV_NETWR text

  • <--P_GV_NAME1 text

----


form cal_no_of_orders tables atv_tab

using p_erdat1

p_erdat2

changing p_gv_count

p_gv_netwr.

data: g_tabix like sy-tabix,

gv_index like sy-tabix.

*Select Orders Processed

select vbeln netwr vgbel from vbak

into corresponding fields of table zvbak where

erdat between p_erdat1 and p_erdat2 and

vkorg in s_vkorg and

vgbel ne space and

auart = 'TA' and

( ( bsark = 'DFUA' ) or

( bsark = 'DFUE' ) or

( bsark = 'DFUI' ) ).

if sy-subrc = 0.

clear sy-subrc .

select vbeln parvw kunnr adrnr from vbpa

into corresponding fields of table zvbpa

for all entries in zvbak

where vbeln = zvbak-vgbel

and parvw = 'AG'.

if sy-subrc = 0.

loop at zvbpa.

g_tabix = sy-tabix.

read table zvbak with key vgbel = zvbpa-vbeln.

if sy-subrc eq 0.

move :zvbak-netwr to zvbpa-netwr.

modify zvbpa index g_tabix.

endif.

select single name1 into (p_name1 )

from adrc

where addrnumber = zvbpa-adrnr.

if sy-subrc = 0.

move p_name1 to zvbpa-name1.

modify zvbpa index g_tabix.

endif.

endloop.

endif.

endif.

  • move Processed Orders to ALV display table

loop at zvbpa.

move-corresponding zvbpa to alv_tab.

append alv_tab.

clear alv_tab.

endloop.

  • Select Open Quotaions

select vbeln netwr vgbel from vbak

into corresponding fields of table zvbak0 where

erdat between p_erdat1 and p_erdat2 and

vkorg in s_vkorg and

vbtyp = 'B' and

vgbel = space and

auart = 'ZEDI'.

loop at zvbak0.

select single vbeln from vbuk

into (zvbeln )

where vbeln = zvbak0-vbeln

and vbtyp = 'B'

and gbstk = 'A'.

if sy-subrc = 0.

read table zvbak0 with key vbeln = zvbeln.

if sy-subrc = 0.

move: zvbak0-vbeln to zvbuk-vbeln,

zvbak0-netwr to zvbuk-netwr.

append zvbuk.

clear zvbuk.

endif.

endif.

endloop.

  • move Open Quotations to ALV display table

sort zvbuk.

loop at zvbuk.

move-corresponding zvbuk to alv_tab.

append alv_tab.

clear alv_tab.

endloop.

*get the total no of orders and dollar amount

sort alv_tab by kunnr.

loop at alv_tab.

gv_netwr = alv_tab-netwr + gv_netwr.

gv_count = gv_count + 1.

endloop.

endform. " cal_no_of_orders

thanks for taking time to read and go thru my code

ur suggestions would help me to grow and may be one day become a part of this forum .

thanks