How to optimize the performance of this code ?
I've two Movie clips on a flash project. One of them is fixed and the other can be moved by arrow buttons on the keyboard. The two Movie clips have irregular shapes, so HitTestObject and HitTestPoint doesn't work very well. I've a function that detects collision of two movie clips using bitmap. I wanted to update the position of the movable Movie clip so I put the collision detection function under the code of ENTER_FRAME event listener. It works very well, but when I add many fixed movie clips ( about 10 fixed movie clips in one frame ), the game (.swf file) becomes slower and the performance of the PC becomes slower. I thought that my collision detection function has a negative effect on PC performance so I used the class on this page : https://forums.adobe.com/thread/873737
but the same thing happens.
Would you tell me how to speed up the execution of my codes ?
Here is part of my code :
stage.addEventListener(Event.ENTER_FRAME, myOnEnterFrame);
function myOnEnterFrame(event:Event):void
if (doThisFn) // doThisFn is a variable to allow or prevent the movable movie clip form being moved with keyboard arrows
if ( left && !right ) {
player.x -= speed;
player.rotation = player.rotation - speed ;
if( right && !left ) {
player.x += speed;
player.rotation = player.rotation + speed ;
if( up && !down ) {
player.y -= speed;
if( down && !up ) {
player.y += speed;
// The fixed movie clips are wall1 ,wall2 , wall3 , wall4 , ... and so on
// the following code checks how many walls exists on each frame and pushes them into the wallA array
for(var i:int=0;i<1000;i++) // We can put up to 1000 wall object into the wallA array
if(this['wall'+i]) // If the object wall exists, push it into the wallA array
wallA.push(this['wall'+i]);
for(i=0;i<wallA.length;i++)
if( h.hitF (player , wallA[i] ) || gameOverTest ) // This code checks if the player ( the movable movie clip ) hits the walls or not
trace ( "second try" ) ;
gameOver.visible = true ;
doThisFn = false ;
//I think the following codes are easy to excite and run. I think the performance issue is due to previous codes.
if (player.hitTestObject(door))
win.visible = true ;
doThisFn = false ;
if (key) // if there is a key on frame
if (player.hitTestObject(key))
key.visible = false ;
switch( currentFrame )
case 4:
wallA[0].visible = false ;
wallA[0].x = 50000;
break;
case 5:
wall14.play();
wall8.x = 430 ;
break;
it's a simple question that usually has no simple answer.
here's an excerpt from a book (Flash Game Development: In a Social, Mobile and 3D World) i wrote.
Optimization Techniques
Unfortunately, I know of no completely satisfactory way to organize this information. In what follows, I discuss memory management first with sub-topics listed in alphabetical order. Then I discuss CPU/GPU management with sub-topics listed in alphabetical order.
That may seem logical but there are, at least, two problems with that organization.
1. I do not believe it is the most helpful way to organize this information.
2. Memory management affects CPU/GPU usage, so everything in the Memory Management section could also be listed in the CPU/GPU section.
Anyway, I am going to also list the information two other ways, from easiest to hardest to implement and from greatest to least benefit.
Both of those later listings are subjective and are dependent on developer experience and capabilities, as well as, the test situation and test environment. I very much doubt there would be a consensus on ordering of these lists. Nevertheless, I think they still are worthwhile.
Easiest to Hardest to Implement
1. Do not use Filters.
2. Always use reverse for-loops and avoid do-loops and avoid while-loops.
3. Explicitly stop Timers to ready them for gc (garbage collection).
4. Use weak event listeners and remove listeners.
5. Strictly type variables whenever possible.
6. Explicitly disable mouse interactivity when mouse interactivity not needed.
7. Replace dispatchEvents with callback functions whenever possible.
8. Stop Sounds to enable Sounds and SoundChannels to be gc'd.
9. Use the most basic DisplayObject needed.
10. Always use cacheAsBitmap and cacheAsBitmapMatrix with air apps (i.e., mobile devices).
11. Reuse Objects whenever possible.
12. Event.ENTER_FRAME loops: Use different listeners and different listener functions applied to as few DisplayObjects as possible.
13. Pool Objects instead of creating and gc'ing Objects.
14. Use partial blitting.
15. Use stage blitting.
16. Use Stage3D
Greatest to Least Benefit
Use stage blitting (if there is enough system memory).
Use Stage3D.
Use partial blitting.
Use cacheAsBitmap and cacheAsBitmapMatrix with mobile devices.
Explicitly disable mouse interactivity when mouse interactivity not needed.
Do not use Filters.
Use the most basic DisplayObject needed.
Reuse Objects whenever possible.
Event.ENTER_FRAME loops: Use different listeners and different listener functions applied to as few DisplayObjects as possible.
Use reverse for-loops and avoid do-loops and while-loops.
Pool Objects instead of creating and gc'ing Objects.
Strictly type variables whenever possible.
Use weak event listeners and remove listeners.
Replace dispatchEvents with callback functions whenever possible.
Explicitly stop Timers to ready for gc.
16. Stop Sounds to enable Sounds and SoundChannels to be gc'd.
Similar Messages
-
How to improve the performance of this code
Hi gurus
code is given below with LDB
this code look big but most of lines are commented
plz help its urgent
thanks in advance
*& Report ZSALES_RECON
REPORT ZSALES_RECON.
TYPE-POOLS : SLIS.
nodes: bseg , bkpf.
data : begin of zbseg occurs 0,
kunnr like bseg-kunnr,
*lifnr like bseg-lifnr,
dmbtr like bseg-dmbtr,
*shkzg like bseg-shkzg,
*gsber like bseg-gsber,
bschl like bseg-bschl,
*sgtxt like bseg-sgtxt,
total like bseg-dmbtr,
hkont like bseg-hkont,
BUDAT LIKE Bkpf-BUDAT,
belnr LIKE BSEG-belnr,
cash like bseg-dmbtr,
credit like bseg-dmbtr,
abn_voucher like bseg-dmbtr,
barista_voucher like bseg-dmbtr,
accor like bseg-dmbtr,
sodexho like bseg-dmbtr,
gift like bseg-dmbtr,
corp like bseg-dmbtr,
card like bseg-dmbtr,
miscellaneous like bseg-dmbtr,
werks like bseg-werks,
gjahr like bseg-gjahr,
SR_NO TYPE I,
shkzg like bseg-shkzg,
end of zbseg,
TP_TBL_DATA like ZBSEG.
DATA : idx TYPE sy-tabix.
Report data to be shown.
data: it_data like ZBSEG.
Heading of the report.
data: t_heading type slis_t_listheader.
AT SELECTION-SCREEN.
get bkpf.
START-OF-SELECTION.
data : sum_mis like bseg-dmbtr,
sum_abn like bseg-dmbtr,
sum_cash like bseg-dmbtr,
sum_credit like bseg-dmbtr,
sum_card like bseg-dmbtr,
sum_barista_voucher like bseg-dmbtr,
sum_accor like bseg-dmbtr,
sum_sodexho like bseg-dmbtr,
sum_gift like bseg-dmbtr,
sum_corp like bseg-dmbtr.
data : wa1_total like bseg-dmbtr.
data : wa_belnr like bseg-belnr,
wa_kunnr like bseg-kunnr,
wa_werks like bseg-werks,
belnr1 like bseg-belnr,
wa_sr_no type i.
GET BSEG.
data : wa like line of zbseg.
data : count type i,
count1 type i.
move-corresponding bseg to zbseg.
*idx = sy-tabix.
on change of zbseg-belnr.
wa_kunnr = zbseg-kunnr.
wa_kunnr = wa_kunnr+6(4).
select single werks into wa_werks from bseg where belnr = zbseg-belnr
and kunnr = '' and gjahr = zbseg-gjahr.
if wa_kunnr = wa_werks.
if zbseg-bschl <> '01'.
clear: sum_mis,wa1_total,sum_abn,sum_cash,sum_credit,sum_card,
sum_barista_voucher,sum_accor,sum_sodexho,sum_gift,sum_corp.
wa-BUDAT = BKPF-BUDAT.
wa-bschl = zbseg-bschl.
wa-hkont = zbseg-hkont.
wa-belnr = zbseg-belnr.
wa_belnr = wa-belnr.
wa-shkzg = zbseg-shkzg.
wa-kunnr = zbseg-kunnr.
count = wa-sr_no.
*wa-sr_no = count + 1.
idx = idx + 1.
append wa to zbseg.
**count = wa-sr_no.
*wa-sr_no = wa-sr_no + 1.
clear wa-total.
endif.
endif.
endon.
*clear : wa1_total.
if wa_belnr = zbseg-belnr.
loop at zbseg into wa.
wa-total = wa1_total.
wa-bschl = zbseg-bschl.
wa-hkont = zbseg-hkont.
count = sy-tabix.
wa-sr_no = count.
count1 = count.
*wa_sr_no = count.
modify zbseg from wa transporting sr_no.
IF wa-bschl eq '40' and wa-hkont eq '0024013020'.
if sy-tabix = 1.
wa-cash = zbseg-dmbtr.
sum_cash = sum_cash + wa-cash.
wa-cash = sum_cash.
modify zbseg index idx from wa transporting cash.
endif.
endif.
IF wa-bschl eq '40' and wa-hkont eq '0026060010'.
if sy-tabix = 1.
wa-credit = zbseg-dmbtr.
sum_credit = sum_credit + wa-credit.
wa-credit = sum_credit.
modify zbseg index idx from wa transporting credit.
endif.
endif.
IF wa-bschl eq '40' and wa-hkont eq '0026060015'.
if sy-tabix = 1.
wa-abn_voucher = zbseg-dmbtr.
sum_abn = sum_abn + wa-abn_voucher.
wa-abn_voucher = sum_abn.
modify zbseg index idx from wa transporting abn_voucher.
endif.
endif.
IF wa-bschl eq '40' and wa-hkont eq '0026060017'.
if sy-tabix = 1.
wa-barista_voucher = zbseg-dmbtr.
sum_barista_voucher = sum_barista_voucher + wa-barista_voucher.
wa-barista_voucher = sum_barista_voucher.
modify zbseg index idx from wa transporting barista_voucher.
endif.
endif.
IF wa-bschl eq '40' and wa-hkont eq '0026060020'.
if sy-tabix = 1.
wa-sodexho = zbseg-dmbtr.
sum_sodexho = sum_sodexho + wa-sodexho.
wa-sodexho = sum_sodexho.
modify zbseg index idx from wa transporting sodexho.
endif.
endif.
IF wa-bschl eq '40' AND wa-hkont eq '0026060030'.
if sy-tabix = 1.
wa-accor = zbseg-dmbtr.
sum_accor = sum_accor + wa-accor.
wa-accor = sum_accor.
modify zbseg index idx from wa transporting accor.
endif.
endif.
IF wa-bschl eq '40' AND wa-hkont eq '0026070040'.
if sy-tabix = 1.
wa-gift = zbseg-dmbtr.
sum_gift = sum_gift + wa-gift.
wa-gift = sum_gift.
modify zbseg index idx from wa transporting gift.
endif.
endif.
IF wa-bschl eq '40' AND wa-hkont eq '0026060070'.
if sy-tabix = 1.
wa-card = zbseg-dmbtr.
sum_card = sum_card + wa-card.
wa-card = sum_card.
modify zbseg index idx from wa transporting card.
endif.
endif.
IF wa-bschl eq '40' AND wa-hkont eq '0026060018'.
if sy-tabix = 1.
wa-corp = zbseg-dmbtr.
sum_corp = sum_corp + wa-corp.
wa-corp = sum_corp.
modify zbseg index idx from wa transporting corp.
endif.
endif.
*IF wa-bschl eq '11' .
*wa-total = zbseg-dmbtr.
*modify zbseg index idx from wa transporting total.
*endif.
IF wa-bschl EQ '40' or wa-bschl = '01' .
if sy-tabix = 1.
wa-total = zbseg-dmbtr.
wa1_total = wa1_total + wa-total.
wa-total = wa1_total.
*if idx = 2.
*modify zbseg index 1 from wa transporting total.
*else.
modify zbseg index idx from wa transporting total.
*endif.
endif.
endif.
*IF zbseg-TOTAL NE zbseg-DMBTR.
IF wa-BSCHL NE '11' AND wa-BSCHL NE '40'. "AND wa-BSCHL NE '01'.
if sy-tabix = 1.
if wa-shkzg = 'S'.
wa-miscellaneous = - wa-miscellaneous.
endif.
wa-miscellaneous = ZBSEG-DMBTR.
sum_mis = sum_mis + wa-miscellaneous.
wa-miscellaneous = sum_mis.
modify zbseg index idx from wa transporting miscellaneous.
endif.
ENDIF.
*wa1-miscellaneous = wa-miscellaneous.
*modify zbseg index idx from wa.
*ENDIF.
*append wa to zbseg.
*clear:zbseg-dmbtr.
endloop.
endif.
*****endif.
*****endon.
*ENDFORM.
*append zbseg.
*endloop.
End-of-selection.
perform build_alv using zbseg t_heading.
*& Form build_alv
Builds and display the ALV Grid.
form build_alv using t_data
*tp_tbl_data
t_heading type slis_t_listheader.
ALV required data objects.
data: w_title type lvc_title,
w_repid type syrepid,
w_comm type slis_formname,
w_status type slis_formname,
x_layout type slis_layout_alv,
t_event type slis_t_event,
t_fieldcat type slis_t_fieldcat_alv,
t_sort type slis_t_sortinfo_alv.
refresh t_fieldcat.
refresh t_event.
refresh t_sort.
clear x_layout.
clear w_title.
Field Catalog
perform set_fieldcat2 using:
1 'SR_NO' 'SR_NO' 'BKPF' '5' space space 'SR NO' space space space
space space space space space t_fieldcat ,
2 'BELNR' 'BELNR' 'BKPF' '10' space space 'Document No' space space
space space space space space space t_fieldcat ,
3 'BUDAT' 'BUDAT' 'BKPF' '10' space space 'Document Date' space
space space space space space space space t_fieldcat ,
4 'KUNNR' space space space space space 'Site' space space
space space space space space space t_fieldcat ,
5 'TOTAL' space 'BSEG' space space space 'Total' space space space
space space space space 'X' t_fieldcat ,
6 'CASH' 'CASH' 'BSEG' space space space 'Cash Sales'
space space space space space space space 'X' t_fieldcat ,
7 'CREDIT' 'CREDIT' 'BSEG' space space space 'Credit Card'
space space space space space space space 'X' t_fieldcat ,
8 'ABN_VOUCHER' space 'BSEG' space space space 'ABN Voucher' space
space
space space space space space 'X' t_fieldcat ,
9 'BARISTA_VOUCHER' space 'BSEG' '15' space space 'BARISTA Voucher'
space space
space space space space space 'X' t_fieldcat ,
10 'CORP' 'CORP' 'BSEG' space space space 'ABN Corp' space space
space space space space space 'X' t_fieldcat ,
11 'SODEXHO' 'SODEXHO' 'BSEG' space space space 'Sodexho' space
space space space space space space 'X' t_fieldcat ,
12 'ACCOR' 'ACCOR' 'BSEG' space space space 'Accor'
space space space space space space space 'X' t_fieldcat ,
13 'GIFT' 'GIFT' 'BSEG' space space space 'Gift Coupon'
space space space space space space space 'X' t_fieldcat ,
14 'CARD' 'CARD' 'BSEG' space space space 'Diners Card' space
space space space space space space 'X' t_fieldcat ,
15 'MISCELLANEOUS' space 'BKPF' '18' space space
'Miscellaneous Income' space space space space space space space 'X'
t_fieldcat .
*14 'KBETR' 'KBETR' 'KONP' '10' space space 'Tax %age' space space
*space space space space space space t_fieldcat ,
*15 'MWSKZ1' 'MWSKZ1' 'RBKP' space space space 'Tax Type' space
*space
space space space space space space t_fieldcat ,
*16 'AMT' 'AMT' 'RBKP' space space space 'Amount Payable' space
*space
space space space space space 'X' t_fieldcat ,
*17 'WERKS' 'SITE' 'RSEG' space space space 'State' space space
*space space space space space space t_fieldcat .
*18 'GSBER' 'GSBER' 'RBKP' space space space 'Business Area' space
*space space space space space space space t_fieldcat .
Layout
x_layout-zebra = 'X'.
Top of page heading
perform set_top_page_heading using t_heading t_event.
Events
perform set_events using t_event.
GUI Status
w_status = ''.
w_repid = sy-repid.
Title
w_title = <<If you want to set a title for
the ALV, please, uncomment and edit this line>>.
User commands
w_comm = 'USER_COMMAND'.
Order
Example
PERFORM set_order USING '<field>' 'IT_DATA' 'X' space space t_sort.
Displays the ALV grid
call function 'REUSE_ALV_GRID_DISPLAY'
exporting
i_callback_program = w_repid
it_fieldcat = t_fieldcat
is_layout = x_layout
it_sort = t_sort
i_callback_pf_status_set = w_status
i_callback_user_command = w_comm
i_save = 'X'
it_events = t_event
i_grid_title = w_title
tables
t_outtab = zbseg
t_data
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. " build_alv.
*& Form set_top_page_heading
Creates the report headings.
form set_top_page_heading using t_heading type slis_t_listheader
t_events type slis_t_event.
data: x_heading type slis_listheader,
x_event type line of slis_t_event.
Report title
clear t_heading[].
clear x_heading.
x_heading-typ = 'H'.
x_heading-info = 'SALES RECONCILIATION REPORT'(001).
append x_heading to t_heading.
Top of page event
x_event-name = slis_ev_top_of_page.
x_event-form = 'TOP_OF_PAGE'.
append x_event to t_events.
endform.
*& Form set_events
Sets the events for ALV.
The TOP_OF_PAGE event is alredy being registered in
the set_top_page_heading subroutine.
form set_events using t_events type slis_t_event.
data: x_event type line of slis_t_event.
Example
clear x_event.
x_event-name = .
x_event-form = .
append x_event to t_event.
endform.
*& Form set_order
Adds an entry to the order table.
FORM set_order USING p_fieldname p_tabname p_up p_down p_subtot
t_sort TYPE slis_t_sortinfo_alv.
DATA: x_sort TYPE slis_sortinfo_alv.
CLEAR x_sort.
x_sort-fieldname = p_fieldname.
x_sort-tabname = p_tabname.
x_sort-up = p_up.
x_sort-down = p_down.
x_sort-subtot = p_subtot.
APPEND x_sort TO t_sort.
ENDFORM. "set_order
*& Form set_fieldcat2
Adds an entry to the field catalog.
p_colpos: Column position.
p_fieldname: Field of internal table which is being described by
* this record of the field catalog.
p_ref_fieldname: (Optional) Table field / data element which
* describes the properties of the field.
* If this field is not given, it is copied from
* the fieldname.
p_ref_tabname: (Optional) Table which holds the field referenced
* by <<p_ref_fieldname>>.
If this is not given, the parameter
<<p_ref_fieldname>> references a data element.
p_outputlen: (Optional) Column width.
p_noout: (Optional) If set to 'X', states that the field is not
* showed initially. If so, the field has to be
included in the report at runtime using the display
options.
p_seltext_m: (Optional) Medium label to be used as column header.
p_seltext_l: (Optional) Long label to be used as column header.
p_seltext_s: (Optional) Small label to be used as column header.
p_reptext_ddic: (Optional) Extra small (heading) label to be
* used as column header.
p_ddictxt: (Optional) Set to 'L', 'M', 'S' or 'R' to select
whether to use SELTEXT_L, SELTEXT_M, SELTEXT_S,
or REPTEXT_DDIC as text for column header.
p_hotspot: (Optional) If set to 'X', this field will be used
* as a hotspot area for cursor, alolowing the user
* to click on the field.
p_showasicon: (Optional) If set to 'X', this field will be shown
as an icon and the contents of the field will set
* which icon to show.
p_checkbox: (Optional) If set to 'X', this field will be shown
as a checkbox.
p_edit: (Optional) If set to 'X', this field will be editable.
p_dosum: (Optional) If set to 'X', this field will be summed
(aggregation function) according to the grouping set
by the order functions.
t_fieldcat: Table which contains the whole fieldcat.
FORM set_fieldcat2 USING
p_colpos p_fieldname p_ref_fieldname p_ref_tabname
p_outputlen p_noout
p_seltext_m p_seltext_l p_seltext_s p_reptext_ddic p_ddictxt
p_hotspot p_showasicon p_checkbox p_edit
p_dosum
t_fieldcat TYPE slis_t_fieldcat_alv.
DATA: wa_fieldcat TYPE slis_fieldcat_alv.
CLEAR wa_fieldcat.
General settings
wa_fieldcat-fieldname = p_fieldname.
wa_fieldcat-col_pos = p_colpos.
wa_fieldcat-no_out = p_noout.
wa_fieldcat-hotspot = p_hotspot.
wa_fieldcat-checkbox = p_checkbox.
wa_fieldcat-icon = p_showasicon.
wa_fieldcat-do_sum = p_dosum.
Set reference fieldname, tablenam and rollname.
If p_ref_tabname is not given, the ref_fieldname given
is a data element.
If p_ref_tabname is given, the ref_fieldname given is a
field of a table.
In case ref_fieldname is not given,
it is copied from the fieldname.
IF p_ref_tabname IS INITIAL.
wa_fieldcat-rollname = p_ref_fieldname.
ELSE.
wa_fieldcat-ref_tabname = p_ref_tabname.
IF p_ref_fieldname EQ space.
wa_fieldcat-ref_fieldname = wa_fieldcat-fieldname.
ELSE.
wa_fieldcat-ref_fieldname = p_ref_fieldname.
ENDIF.
ENDIF.
Set output length.
IF NOT p_outputlen IS INITIAL.
wa_fieldcat-outputlen = p_outputlen.
ENDIF.
Set text headers.
IF NOT p_seltext_m IS INITIAL.
wa_fieldcat-seltext_m = p_seltext_m.
ENDIF.
IF NOT p_seltext_l IS INITIAL.
wa_fieldcat-seltext_l = p_seltext_l.
ENDIF.
IF NOT p_seltext_s IS INITIAL.
wa_fieldcat-seltext_s = p_seltext_s.
ENDIF.
IF NOT p_reptext_ddic IS INITIAL.
wa_fieldcat-reptext_ddic = p_reptext_ddic.
ENDIF.
IF NOT p_ddictxt IS INITIAL.
wa_fieldcat-ddictxt = p_ddictxt.
ENDIF.
Set as editable or not.
IF NOT p_edit IS INITIAL.
wa_fieldcat-input = 'X'.
wa_fieldcat-edit = 'X'.
ENDIF.
APPEND wa_fieldcat TO t_fieldcat.
ENDFORM. "set_fieldcat2
======================== Subroutines called by ALV ================
*& Form top_of_page
Called on top_of_page ALV event.
Prints the heading.
form top_of_page.
call function 'REUSE_ALV_COMMENTARY_WRITE'
exporting
i_logo = <<If you want to set a logo, please,
uncomment and edit this line>>
it_list_commentary = t_heading.
endform. " alv_top_of_page
*& Form user_command
Called on user_command ALV event.
Executes custom commands.
form user_command using r_ucomm like sy-ucomm
rs_selfield type slis_selfield.
Example Code
Executes a command considering the sy-ucomm.
CASE r_ucomm.
WHEN '&IC1'.
Set your "double click action" response here.
Example code: Create and display a status message.
DATA: w_msg TYPE string,
w_row(4) TYPE n.
w_row = rs_selfield-tabindex.
CONCATENATE 'You have clicked row' w_row
'field' rs_selfield-fieldname
'with value' rs_selfield-value
INTO w_msg SEPARATED BY space.
MESSAGE w_msg TYPE 'S'.
ENDCASE.
End of example code.
endform. "user_command
*********************************ldb code start from here *************************************************************
DATABASE PROGRAM OF LOGICAL DATABASE ZBRM_3
top-include and nxxx-include are generated automatically
Do NOT change their names manually!!!
*include DBZBRM_3TOP . " header
*include DBZBRM_3NXXX . " all system routines
include DBZBRM_3F001 . " user defined include
PROGRAM SAPDBZBRM_3 DEFINING DATABASE ZBRM_3.
TABLES:
BKPF,
BSEG.
Hilfsfelder
DATA:
BR_SBUKRS LIKE BKPF-BUKRS,
BR_SBELNR LIKE BKPF-BELNR,
BR_SGJAHR LIKE BKPF-GJAHR,
BR_SBUDAT LIKE BKPF-BUDAT,
BR_SGSBER LIKE BSEG-GSBER.
BR_SBUZEI LIKE BSEG-BUZEI,
BR_SEBELN LIKE BSEG-EBELN,
BR_SEBELP LIKE BSEG-EBELP,
BR_SZEKKN LIKE BSEG-ZEKKN.
working areas for the authority check "n435991
for the company code "n435991
*TYPES : BEGIN OF STYPE_BUKRS, "n435991
BUKRS LIKE T001-BUKRS, "n435991
WAERS LIKE T001-WAERS, "n435991
RETCODE TYPE N, "n435991
END OF STYPE_BUKRS. "n435991
"n435991
*DATA : G_S_BUKRS TYPE STYPE_BUKRS, "n435991
G_T_BUKRS TYPE STYPE_BUKRS OCCURS 0. "n435991
"n435991
for the document type "n435991
*TYPES : BEGIN OF STYPE_BLART, "n435991
BLART LIKE BKPF-BLART, "n435991
RETCODE TYPE N, "n435991
END OF STYPE_BLART. "n435991
"n435991
*DATA : G_S_BLART TYPE STYPE_BLART, "n435991
G_T_BLART TYPE STYPE_BLART OCCURS 0. "n435991
"n435991
for the business area "n435991
*TYPES : BEGIN OF STYPE_GSBER, "n435991
GSBER LIKE BSEG-GSBER, "n435991
RETCODE TYPE N, "n435991
END OF STYPE_GSBER. "n435991
"n435991
*DATA : G_S_GSBER TYPE STYPE_GSBER, "n435991
G_T_GSBER TYPE STYPE_GSBER OCCURS 0. "n435991
"n435991
for the purchasing organization "n435991
*TYPES : BEGIN OF STYPE_EKORG, "n435991
EKORG LIKE EKKO-EKORG, "n435991
RETCODE TYPE N, "n435991
END OF STYPE_EKORG. "n435991
"n435991
*DATA : G_S_EKORG TYPE STYPE_EKORG, "n435991
G_T_EKORG TYPE STYPE_EKORG OCCURS 0. "n435991
"n435991
for the plant "n435991
*TYPES : BEGIN OF STYPE_WERKS, "n435991
WERKS LIKE EKPO-WERKS, "n435991
RETCODE TYPE N, "n435991
END OF STYPE_WERKS. "n435991
"n435991
*DATA : G_S_WERKS TYPE STYPE_WERKS, "n435991
G_T_WERKS TYPE STYPE_WERKS OCCURS 0. "n435991
"n435991
*DATA : G_F_TABIX LIKE SY-TABIX. "n435991
"n435991
working tables for array database access "n934526
*types : begin of stype_key, "n934526
bukrs type bkpf-bukrs, "n934526
belnr type bkpf-belnr, "n934526
gjahr type bkpf-gjahr, "n934526
end of stype_key, "n934526
"n934526
stab_key type standard table of "n934526
stype_key "n934526
with default key. "n934526
Initialwerte setzen
FORM INIT.
ENDFORM.
Selection Screen: Process before output
FORM PBO.
ENDFORM.
Selection Screen: Process after input
FORM PAI USING FNAME MARK.
CHECK MARK = SPACE.
ENDFORM.
Lesen BKPF und Uebergabe an den Selektionsreport
FORM PUT_BKPF.
define locla working areas "n934526
data : l_t_key type stab_key, "n934526
l_t_key_block type stab_key, "n934526
l_t_bkpf type standard table of bkpf. "n934526
"n934526
----------------------------------------------------------"n934526
"n934526
database seletion improved "n934526
at first read all FI doc keys into a lean table "n934526
data: wa like bkpf-belnr.
SELECT * FROM BKPF
where budat in br_budat
AND GJAHR EQ BR_GJAHR-LOW
AND BLART = 'RV'.
AND BLART IN BR_BLAR "n934526
"n934526
check sy-subrc is initial. "n934526
"n934526
then process the found FI doc keys in small blocks "n934526
do. "n934526
if l_t_key[] is initial. "n934526
exit. " no more keys -> leave this DO loop "n934526
endif. "n934526
"n934526
form small blocks with 100 FI docs each "n934526
refresh l_t_key_block. "n934526
append lines of l_t_key from 1 to 100 "n934526
to l_t_key_block. "n934526
delete l_t_key from 1 to 100. "n934526
"n934526
read the complete FI doc headers for the block "n934526
SELECT * FROM BKPF "n934526
into corresponding fields of table l_t_bkpf "n934526
for all entries in l_t_key_block "n934526
WHERE BUKRS = l_t_key_block-BUKRS "n934526
AND BELNR = l_t_key_block-BELNR "n934526
AND GJAHR = l_t_key_block-GJAHR. "n934526
"n934526
provide the complete structure for the PUT "n934526
loop at l_t_bkpf into bkpf. "n934526
process this company code : authority and read T001 "n934526
PERFORM F1000_COMPANY_CODE. "n934526
"n934526
go on if the first authority check was successful "n934526
CHECK : G_S_BUKRS-RETCODE IS INITIAL. "n934526
"n934526
set the currency key and save the keys "n934526
MOVE : G_S_BUKRS-WAERS TO T001-WAERS, "n934526
BKPF-BUKRS TO BR_SBUKRS, "n934526
MOVE BKPF-BELNR TO BR_SBELNR.
MOVE BKPF-GJAHR TO BR_SGJAHR . "n934526
BKPF-GJAHR TO BR_SGJAHR. "n934526
PUT BKPF. "n934526
endloop. "n934526
enddo. "n934526
ENDSELECT.
ENDFORM.
Lesen BSEG und Uebergabe an den Selektionsreport
FORM PUT_BSEG.
define local working areas "n934526
data : l_t_bseg type standard table of bseg. "n934526
"n934526
----------------------------------------------------------"n934526
BR_SGSBER = BR_GSBER-LOW.
"n934526
SELECT * FROM BSEG "n934526
WHERE BELNR EQ BR_SBELNR
AND GJAHR EQ BR_SGJAHR
AND GSBER EQ BR_SGSBER.
check sy-subrc is initial. "n934526
"n934526
loop at l_t_bseg into bseg. "n934526
MOVE BSEG-BUZEI TO BR_SBUZEI.
MOVE BSEG-EBELN TO BR_SEBELN.
MOVE BSEG-EBELP TO BR_SEBELP.
MOVE BSEG-ZEKKN TO BR_SZEKKN.
PUT BSEG.
endSELECT. "n934526
ENDFORM.
"n435991
FORM AUTHORITYCHECK_BKPF "n435991
"n435991
"n435991
*FORM AUTHORITYCHECK_BKPF. "n435991
"n435991
the authority-check for the company code was successful; "n435991
check authority for the document type here "n435991
"n435991
does the buffer contain this document type ? "n435991
READ TABLE G_T_BLART INTO G_S_BLART "n435991
WITH KEY BLART = BKPF-BLART BINARY SEARCH. "n435991
"n435991
CASE SY-SUBRC. "n435991
WHEN 0. "document type is known "n435991
"n435991
WHEN 4. "docment type is new --> insert "n435991
MOVE SY-TABIX TO G_F_TABIX. "n435991
PERFORM F1200_CREATE_BLART_ENTRY. "n435991
INSERT G_S_BLART INTO G_T_BLART "n435991
INDEX G_F_TABIX. "n435991
"n435991
WHEN 8. "document type is new --> append "n435991
PERFORM F1200_CREATE_BLART_ENTRY. "n435991
APPEND G_S_BLART TO G_T_BLART. "n435991
ENDCASE. "n435991
"n435991
set the return code "n435991
MOVE G_S_BLART-RETCODE TO SY-SUBRC. "n435991
"n435991
*ENDFORM. "authoritycheck_bkpf "n435991
"n435991
"n435991
FORM AUTHORITYCHECK_BSEG "n435991
"n435991
"n435991
*FORM AUTHORITYCHECK_BSEG. "n435991
"n435991
does the buffer contain this document type ? "n435991
READ TABLE G_T_GSBER INTO G_S_GSBER "n435991
WITH KEY GSBER = BSEG-GSBER BINARY SEARCH. "n435991
"n435991
CASE SY-SUBRC. "n435991
WHEN 0. "business area is known "n435991
"n435991
WHEN 4. "business area is new --> insert "n435991
MOVE SY-TABIX TO G_F_TABIX. "n435991
PERFORM F1300_CREATE_GSBER_ENTRY. "n435991
INSERT G_S_GSBER INTO G_T_GSBER "n435991
INDEX G_F_TABIX. "n435991
"n435991
WHEN 8. "business area is new --> append "n435991
PERFORM F1300_CREATE_GSBER_ENTRY. "n435991
APPEND G_S_GSBER TO G_T_GSBER. "n435991
ENDCASE. "n435991
"n435991
set the return code "n435991
MOVE G_S_GSBER-RETCODE TO SY-SUBRC. "n435991
"n435991
*ENDFORM. "authoritycheck_bseg "n435991
"n435991ABAP provides few tools to analyse the perfomance of the objects, which was developed by us.
Run time analysis transaction SE30
This transaction gives all the analysis of an ABAP program with respect to the database and the non-database processing.
SQL Trace transaction ST05
by using this tool we can analyse the perfomance issues related to DATABASE calls.
Perfomance Techniques for improve the perfomance of the object.
1) ABAP/4 programs can take a very long time to execute, and can make other processes have to wait before executing. Here are some tips to speed up your programs and reduce the load your programs put on the system:
2) Use the GET RUN TIME command to help evaluate performance. It's hard to know whether that optimization technique REALLY helps unless you test it out.
3) Using this tool can help you know what is effective, under what kinds of conditions. The GET RUN TIME has problems under multiple CPUs, so you should use it to test small pieces of your program, rather than the whole program.
4) Generally, try to reduce I/O first, then memory, then CPU activity. I/O operations that read/write to hard disk are always the most expensive operations. Memory, if not controlled, may have to be written to swap space on the hard disk, which therefore increases your I/O read/writes to disk. CPU activity can be reduced by careful program design, and by using commands such as SUM (SQL) and COLLECT (ABAP/4).
5) Avoid 'SELECT *', especially in tables that have a lot of fields. Use SELECT A B C INTO instead, so that fields are only read if they are used. This can make a very big difference.
6) Field-groups can be useful for multi-level sorting and displaying. However, they write their data to the system's paging space, rather than to memory (internal tables use memory). For this reason, field-groups are only appropriate for processing large lists (e.g. over 50,000 records). If you have large lists, you should work with the systems administrator to decide the maximum amount of RAM your program should use, and from that, calculate how much space your lists will use. Then you can decide whether to write the data to memory or swap space.
Use as many table keys as possible in the WHERE part of your select statements.
7)Whenever possible, design the program to access a relatively constant number of records (for instance, if you only access the transactions for one month, then there probably will be a reasonable range, like 1200-1800, for the number of transactions inputted within that month). Then use a SELECT A B C INTO TABLE ITAB statement.
8) Get a good idea of how many records you will be accessing. Log into your productive system, and use SE80 -> Dictionary Objects (press Edit), enter the table name you want to see, and press Display. Go To Utilities -> Table Contents to query the table contents and see the number of records. This is extremely useful in optimizing a program's memory allocation.
9) Try to make the user interface such that the program gradually unfolds more information to the user, rather than giving a huge list of information all at once to the user.
10) Declare your internal tables using OCCURS NUM_RECS, where NUM_RECS is the number of records you expect to be accessing. If the number of records exceeds NUM_RECS, the data will be kept in swap space (not memory).
11) Use SELECT A B C INTO TABLE ITAB whenever possible. This will read all of the records into the itab in one operation, rather than repeated operations that result from a SELECT A B C INTO ITAB... ENDSELECT statement. Make sure that ITAB is declared with OCCURS NUM_RECS, where NUM_RECS is the number of records you expect to access.
12) If the number of records you are reading is constantly growing, you may be able to break it into chunks of relatively constant size. For instance, if you have to read all records from 1991 to present, you can break it into quarters, and read all records one quarter at a time. This will reduce I/O operations. Test extensively with GET RUN TIME when using this method.
13) Know how to use the 'collect' command. It can be very efficient.
14) Use the SELECT SINGLE command whenever possible.
15) Many tables contain totals fields (such as monthly expense totals). Use these avoid wasting resources by calculating a total that has already been calculated and stored.
Some tips:
1) Use joins where possible as redundant data is not fetched.
2) Use select single where ever possible.
3) Calling methods of a global class is faster than calling function modules.
4) Use constants instead of literals
5) Use WHILE instead of a DO-EXIT-ENDDO.
6) Unnecessary MOVEs should be avoided by using the explicit work area operations
see the follwing links for a brief insifght into performance tuning,
http://www.thespot4sap.com/Articles/SAPABAPPerformanceTuning_Introduction.asp
1. Debuggerhttp://help.sap.com/saphelp_47x200/helpdata/en/c6/617ca9e68c11d2b2ab080009b43351/content.htm
2. Run Time Analyser
http://help.sap.com/saphelp_47x200/helpdata/en/c6/617cafe68c11d2b2ab080009b43351/content.htm
3. SQL trace
http://help.sap.com/saphelp_47x200/helpdata/en/d1/801f7c454211d189710000e8322d00/content.htm
4. CATT - Computer Aided Testing Too
http://help.sap.com/saphelp_47x200/helpdata/en/b3/410b37233f7c6fe10000009b38f936/frameset.htm
5. Test Workbench
http://help.sap.com/saphelp_47x200/helpdata/en/a8/157235d0fa8742e10000009b38f889/frameset.htm
6. Coverage Analyser
http://help.sap.com/saphelp_47x200/helpdata/en/c7/af9a79061a11d4b3d4080009b43351/content.htm
7. Runtime Monitor
http://help.sap.com/saphelp_47x200/helpdata/en/b5/fa121cc15911d5993d00508b6b8b11/content.htm
8. Memory Inspector
http://help.sap.com/saphelp_47x200/helpdata/en/a2/e5fc84cc87964cb2c29f584152d74e/content.htm
9. ECATT - Extended Computer Aided testing tool.
http://help.sap.com/saphelp_47x200/helpdata/en/20/e81c3b84e65e7be10000000a11402f/frameset.htm
Performance tuning for Data Selection Statement
http://www.sap-img.com/abap/performance-tuning-for-data-selection-statement.htm -
Is There any way to improve the performance on this code
Hi all can any one tell me how to improve the performance of this below code.
Actually i need to calculate opening balance of gl account so instead of using bseg am using bsis
So is there any way to improve this code performance.
Any help would be appreciated.
REPORT ZTEMP5 NO STANDARD PAGE HEADING LINE-SIZE 190.
data: begin of collect occurs 0,
MONAT TYPE MONAT,
HKONT TYPE HKONT,
BELNR TYPE BELNR_D,
BUDAT TYPE BUDAT,
WRBTR TYPE WRBTR,
SHKZG TYPE SHKZG,
SGTXT TYPE SGTXT,
AUFNR TYPE AUFNR_NEU,
TOT LIKE BSIS-WRBTR,
end of collect.
TYPES: BEGIN OF TY_BSIS,
MONAT TYPE MONAT,
HKONT TYPE HKONT,
BELNR TYPE BELNR_D,
BUDAT TYPE BUDAT,
WRBTR TYPE WRBTR,
SHKZG TYPE SHKZG,
SGTXT TYPE SGTXT,
AUFNR TYPE AUFNR_NEU,
END OF TY_BSIS.
DATA: IT_BSIS TYPE TABLE OF TY_BSIS,
WA_BSIS TYPE TY_BSIS.
DATA: TOT TYPE WRBTR,
SUMA TYPE WRBTR,
VALUE TYPE WRBTR,
VALUE1 TYPE WRBTR.
SELECTION-SCREEN: BEGIN OF BLOCK B1.
PARAMETERS: S_HKONT LIKE WA_BSIS-HKONT DEFAULT '0001460002' .
SELECT-OPTIONS: S_BUDAT FOR WA_BSIS-BUDAT,
S_AUFNR FOR WA_BSIS-AUFNR DEFAULT '200020',
S_BELNR FOR WA_BSIS-BELNR.
SELECTION-SCREEN: END OF BLOCK B1.
AT SELECTION-SCREEN OUTPUT.
LOOP AT SCREEN.
IF SCREEN-NAME = 'S_HKONT'.
SCREEN-INPUT = 0.
MODIFY SCREEN.
ENDIF.
ENDLOOP.
START-OF-SELECTION.
SELECT MONAT
HKONT
BELNR
BUDAT
WRBTR
SHKZG
SGTXT
AUFNR
FROM BSIS
INTO TABLE IT_BSIS
WHERE HKONT EQ S_HKONT
AND BELNR IN S_BELNR
AND BUDAT IN S_BUDAT
AND AUFNR IN S_AUFNR.
* if sy-subrc <> 0.
* message 'No Data' type 'I'.
* endif.
SELECT SUM( WRBTR )
FROM BSIS
INTO COLLECT-TOT
WHERE HKONT EQ S_HKONT
AND BUDAT < S_BUDAT-LOW
AND AUFNR IN S_AUFNR.
END-OF-SELECTION.
CLEAR: S_BUDAT, S_AUFNR, S_BELNR, S_HKONT.
LOOP AT IT_BSIS INTO WA_BSIS.
IF wa_bsis-SHKZG = 'H'.
wa_bsis-WRBTR = 0 - wa_bsis-WRBTR.
ENDIF.
collect-MONAT = wa_bsis-monat.
collect-HKONT = wa_bsis-hkont.
collect-BELNR = wa_bsis-belnr.
collect-BUDAT = wa_bsis-budat.
collect-WRBTR = wa_bsis-wrbtr.
collect-SHKZG = wa_bsis-shkzg.
collect-SGTXT = wa_bsis-sgtxt.
collect-AUFNR = wa_bsis-aufnr.
collect collect into collect.
CLEAR: COLLECT, WA_BSIS.
ENDLOOP.
LOOP AT COLLECT.
AT end of HKONT.
WRITE:/65 'OpeningBalance',
85 collect-tot.
skip 1.
ENDAT.
WRITE:/06 COLLECT-BELNR,
22 COLLECT-BUDAT,
32 COLLECT-WRBTR,
54 COLLECT-SGTXT.
AT end of MONAT.
SUM.
WRITE:/ COLLECT-MONAT COLOR 1.
WRITE:32 COLLECT-WRBTR COLOR 1.
VALUE = COLLECT-WRBTR.
SKIP 1.
ENDAT.
VALUE1 = COLLECT-TOT + VALUE.
AT end of MONAT.
WRITE:85 VALUE1.
ENDAT.
endloop.
CLEAR: COLLECT, SUMA, VALUE, VALUE1.
TOP-OF-PAGE.
WRITE:/06 'Doc No',
22 'Post Date',
39 'Amount',
54 'Text'.
Moderator message : See the Sticky threads (related for performance tuning) in this forum. Thread locked.
Edited by: Vinod Kumar on Oct 13, 2011 11:12 AMHi Ben,
both BSIS selects would become faster if you can add Company Code BUKRS as 1st field of WHERE clause, because it's the 1st field of primary key and HKONT is the 2nd field of primary key.
If you have no table index with HKONT as 1st field it's a full database access.
If possible, try to add BUKRS as 1st field of WHERE clause, otherwise ask for an additional BSIS index at your basis team.
Regards,
Klaus -
Please help me how to improve the performance of this query further.
Hi All,
Please help me how to improve the performance of this query further.
Thanks.Hi,
this is not your first SQL tuning request in this community -- you really should learn how to obtain performance diagnostics.
The information you posted is not nearly enough to even start troubleshooting the query -- you haven't specified elapsed time, I/O, or the actual number of rows the query returns.
The only piece of information we have is saying that your query executes within a second. If we believe this, then your query doesn't need tuning. If we don't, then we throw it away
and we're left with nothing.
Start by reading this blog post: Kyle Hailey &raquo; Power of DISPLAY_CURSOR
and applying this knowledge to your case.
Best regards,
Nikolay -
How to optimize the performance of crystal report?
Hi,
-I have to design a crystal report with best possible optimization. Optimization is main concern since report will run against 1-2 million data set. Though I am using parameter to fetch only the required data, required data can go till 1 million records.
-Based on the input passed by the user I have to group the data in report. And for each selected parameter the Detail section I am printing is different. For example:-If user selects store then detail section is different and if user select Host then detail section will be different.
-Report can be grouped by Time Field also. So to full fill this requirement I would have to create a sub report since other parameters are of string type and can be used in one formula to get parameter based grouping in report. However If I try to return Time filed from the same formula I get the errors the "Return type should be of String typeu201D. This forces me to create sub report for Time based grouping. If user selects Time Field to be grouped on, all the information in the main report gets suppressed and only the sub report gets printed.
If user select store, Host and User in parameter to be grouped on, sub report gets suppressed.
Now with the above mentioned points I tried to optimize the report in following way.
-Printing 1 million records in the report does not make sense; hence we wanted to show the summary of all the records in chart section but wanted to print just 5000 records in detailed section. Suppressing detailed section after 5000 records does not help much since suppressing just saves the time in printing and does not limit the number of records to be fetched from the DB.I have a subreport also so it fetches the data 2 times from the DB hence makes the performance of the report worse.
To solve this problem I used command object and put the charts in the subreport and detail in main report.
In main report's Command Object I limited the number to records to be fetched from the DB to 5000 using rownum<5000 but in subreport's Command Object I did not set any limit in the query but I am doing all my aggregation in SQL which means do summary operation in DB and get only summarized data from DB.
-To solve section problem I am using Template object (new feature added in CR 2008).In which I am returning the field based on the "Group By" parameter selected by user.
-For time Field I have created two sub reports, one for chart and other one for details in the same way described in point one(Printing 1 million recordsu2026u2026).
After implementing these points my crystal reports performance improved drastically. The report that was taking 24 minute to come back now taking only 2 minutes.
However I want my report to come back with one minute. It returns if I remove the sub reports for Time Based Grouping but I can not do so.
My questions here are,
-Can I stop Subreport from fetching the data from DB if itu2019s suppressed?
-I believe using Conditional Template Object is a better option rather than having multiple detailed sections to print the data for a selected Group. However any suggestion here to improve the performance will be appreciable.
-since crystal report does not provide any option to limit the number of records to be fetched from DB, I am forced to use command object with rownum in where condition.
Please let me know about other option(s) to get this done...If there is any.
I am using Crystal report 2008.And we have developed our application the use JRC to export crystal report in PDF.
Regards,
Amrita
Edited by: Amrita Singh on May 12, 2009 11:36 AM1) I have to design a crystal report with best possible optimization. Optimization is main concern since report will run against 1-2 million data set. Though I am using parameter to fetch only the required data, required data can go till 1 million records.
2) Based on the input passed by the user I have to group the data in report. And for each selected parameter the Detail section I am printing is different. For example:-If user selects store then detail section is different and if user select Host then detail section will be different.
3) Report can be grouped by Time Field also. So to full fill this requirement I would have to create a sub report since other parameters are of string type and can be used in one formula to get parameter based grouping in report. However If I try to return Time filed from the same formula I get the errors the "Return type should be of String typeu201D. This forces me to create sub report for Time based grouping. If user selects Time Field to be grouped on, all the information in the main report gets suppressed and only the sub report gets printed.
If user select store, Host and User in parameter to be grouped on, sub report gets suppressed.
Now with the above mentioned points I tried to optimize the report in following way.
1) Printing 1 million records in the report does not make sense; hence we wanted to show the summary of all the records in chart section but wanted to print just 5000 records in detailed section. Suppressing detailed section after 5000 records does not help much since suppressing just saves the time in printing and does not limit the number of records to be fetched from the DB.I have a subreport also so it fetches the data 2 times from the DB hence makes the performance of the report worse.
To solve this problem I used command object and put the charts in the subreport and detail in main report.
In main report's Command Object I limited the number to records to be fetched from the DB to 5000 using rownum<5000 but in subreport's Command Object I did not set any limit in the query but I am doing all my aggregation in SQL which means do summary operation in DB and get only summarized data from DB.
2)To solve section problem I am using Template object (new feature added in CR 2008).In which I am returning the field based on the "Group By" parameter selected by user.
Edited by: Amrita Singh on May 12, 2009 12:26 PM -
Toshiba M100 - How to optimize the performance?
I upgrade my Toshiba M100 from XP to Windows 7 after installing 2GB ram.
What to do for better performance to my system?Hi mate,
What Toshiba M100 you have? Is it Portege M100, Satellite M100 or what else?
To enhance the performance of Windows you should defragment the HDD, disable all services that you dont need and disable all start up programs that you dont need.
If you ask Google for some tips how to optimize, you will find enough! ;) -
How to improve the performance of one program in one select query
Hi,
I am facing performance issue in one program. I have given some part of the code of the program.
it is taking much time below select query. How to improve the performance.
Quick response is highly appreciated.
Program code
DATA: BEGIN OF t_dels_tvpod OCCURS 100,
vbeln LIKE tvpod-vbeln,
posnr LIKE tvpod-posnr,
lfimg_diff LIKE tvpod-lfimg_diff,
calcu LIKE tvpod-calcu,
podmg LIKE tvpod-podmg,
uecha LIKE lips-uecha,
pstyv LIKE lips-pstyv,
xchar LIKE lips-xchar,
grund LIKE tvpod-grund,
END OF t_dels_tvpod,
DATA: l_tabix LIKE sy-tabix,
lt_dels_tvpod LIKE t_dels_tvpod OCCURS 10 WITH HEADER LINE,
ls_dels_tvpod LIKE t_dels_tvpod.
SELECT vbeln INTO TABLE lt_dels_tvpod FROM likp
FOR ALL ENTRIES IN t_dels_tvpod
WHERE vbeln = t_dels_tvpod-vbeln
AND erdat IN s_erdat
AND bldat IN s_bldat
AND podat IN s_podat
AND ernam IN s_ernam
AND kunnr IN s_kunnr
AND vkorg IN s_vkorg
AND vstel IN s_vstel
AND lfart NOT IN r_del_types_exclude.
Waiting for quick response.
Best regards,
BDPBansidhar,
1) You need to add a check to make sure that internal table t_dels_tvpod (used in the FOR ALL ENTRIES clause) is not blank. If it is blank skip the SELECt statement.
2) Check the performance with and without clause 'AND lfart NOT IN r_del_types_exclude'. Sometimes NOT causes the select statement to not use the index. Instead of 'lfart NOT IN r_del_types_exclude' use 'lfart IN r_del_types_exclude' and build r_del_types_exclude by using r_del_types_exclude-sign = 'E' instead of 'I'.
3) Make sure that the table used in the FOR ALL ENTRIES clause has unique delivery numbers.
Try doing something like this.
TYPES: BEGIN OF ty_del_types_exclude,
sign(1) TYPE c,
option(2) TYPE c,
low TYPE likp-lfart,
high TYPE likp-lfart,
END OF ty_del_types_exclude.
DATA: w_del_types_exclude TYPE ty_del_types_exclude,
t_del_types_exclude TYPE TABLE OF ty_del_types_exclude,
t_dels_tvpod_tmp LIKE TABLE OF t_dels_tvpod .
IF NOT t_dels_tvpod[] IS INITIAL.
* Assuming that I would like to exclude delivery types 'LP' and 'LPP'
CLEAR w_del_types_exclude.
REFRESH t_del_types_exclude.
w_del_types_exclude-sign = 'E'.
w_del_types_exclude-option = 'EQ'.
w_del_types_exclude-low = 'LP'.
APPEND w_del_types_exclude TO t_del_types_exclude.
w_del_types_exclude-low = 'LPP'.
APPEND w_del_types_exclude TO t_del_types_exclude.
t_dels_tvpod_tmp[] = t_dels_tvpod[].
SORT t_dels_tvpod_tmp BY vbeln.
DELETE ADJACENT DUPLICATES FROM t_dels_tvpod_tmp
COMPARING
vbeln.
SELECT vbeln
FROM likp
INTO TABLE lt_dels_tvpod
FOR ALL ENTRIES IN t_dels_tvpod_tmp
WHERE vbeln EQ t_dels_tvpod_tmp-vbeln
AND erdat IN s_erdat
AND bldat IN s_bldat
AND podat IN s_podat
AND ernam IN s_ernam
AND kunnr IN s_kunnr
AND vkorg IN s_vkorg
AND vstel IN s_vstel
AND lfart IN t_del_types_exclude.
ENDIF. -
How to improve the performance of the abap program
hi all,
I have created an abap program. And it taking long time since the number of records are more. And can anyone let me know how to improve the performance of my abap program.
Using se30 and st05 transaction.
can anyone help me out step by step
regds
harithaHi Haritha,
->Run Any program using SE30 (performance analysis)
Note: Click on the Tips & Tricks button from SE30 to get performance improving tips.
Using this you can improve the performance by analyzing your code part by part.
->To turn runtim analysis on within ABAP code insert the following code
SET RUN TIME ANALYZER ON.
->To turn runtim analysis off within ABAP code insert the following code
SET RUN TIME ANALYZER OFF.
->Always check the driver internal tables is not empty, while using FOR ALL ENTRIES
->Avoid for all entries in JOINS
->Try to avoid joins and use FOR ALL ENTRIES.
->Try to restrict the joins to 1 level only ie only for tables
->Avoid using Select *.
->Avoid having multiple Selects from the same table in the same object.
->Try to minimize the number of variables to save memory.
->The sequence of fields in 'where clause' must be as per primary/secondary index ( if any)
->Avoid creation of index as far as possible
->Avoid operators like <>, > , < & like % in where clause conditions
->Avoid select/select single statements in loops.
->Try to use 'binary search' in READ internal table. -->Ensure table is sorted before using BINARY SEARCH.
->Avoid using aggregate functions (SUM, MAX etc) in selects ( GROUP BY , HAVING,)
->Avoid using ORDER BY in selects
->Avoid Nested Selects
->Avoid Nested Loops of Internal Tables
->Try to use FIELD SYMBOLS.
->Try to avoid into Corresponding Fields of
->Avoid using Select Distinct, Use DELETE ADJACENT
Check the following Links
Re: performance tuning
Re: Performance tuning of program
http://www.sapgenie.com/abap/performance.htm
http://www.thespot4sap.com/Articles/SAPABAPPerformanceTuning_PerformanceAnalysisTools.asp
check the below link
http://www.sap-img.com/abap/performance-tuning-for-data-selection-statement.htm
See the following link if it's any help:
http://www.thespot4sap.com/Articles/SAPABAPPerformanceTuning_PerformanceAnalysisTools.asp
Check also http://service.sap.com/performance
and
books like
http://www.sap-press.com/product.cfm?account=&product=H951
http://www.sap-press.com/product.cfm?account=&product=H973
http://www.sap-img.com/abap/more-than-100-abap-interview-faqs.htm
http://www.thespot4sap.com/Articles/SAPABAPPerformanceTuning_PerformanceAnalysisTools.asp
Performance tuning for Data Selection Statement
http://www.sap-img.com/abap/performance-tuning-for-data-selection-statement.htm
Debugger
http://help.sap.com/saphelp_47x200/helpdata/en/c6/617ca9e68c11d2b2ab080009b43351/content.htm
http://www.cba.nau.edu/haney-j/CIS497/Assignments/Debugging.doc
http://help.sap.com/saphelp_erp2005/helpdata/en/b3/d322540c3beb4ba53795784eebb680/frameset.htm
Run Time Analyser
http://help.sap.com/saphelp_47x200/helpdata/en/c6/617cafe68c11d2b2ab080009b43351/content.htm
SQL trace
http://help.sap.com/saphelp_47x200/helpdata/en/d1/801f7c454211d189710000e8322d00/content.htm
CATT - Computer Aided Testing Too
http://help.sap.com/saphelp_47x200/helpdata/en/b3/410b37233f7c6fe10000009b38f936/frameset.htm
Test Workbench
http://help.sap.com/saphelp_47x200/helpdata/en/a8/157235d0fa8742e10000009b38f889/frameset.htm
Coverage Analyser
http://help.sap.com/saphelp_47x200/helpdata/en/c7/af9a79061a11d4b3d4080009b43351/content.htm
Runtime Monitor
http://help.sap.com/saphelp_47x200/helpdata/en/b5/fa121cc15911d5993d00508b6b8b11/content.htm
Memory Inspector
http://help.sap.com/saphelp_47x200/helpdata/en/a2/e5fc84cc87964cb2c29f584152d74e/content.htm
ECATT - Extended Computer Aided testing tool.
http://help.sap.com/saphelp_47x200/helpdata/en/20/e81c3b84e65e7be10000000a11402f/frameset.htm
Just refer to these links...
performance
Performance
Performance Guide
performance issues...
Performance Tuning
Performance issues
performance tuning
performance tuning
You can go to the transaction SE30 to have the runtime analysis of your program.Also try the transaction SCI , which is SAP Code Inspector.
edited by,
Naveenan -
How to measure the performance of sql query?
Hi Experts,
How to measure the performance, efficiency and cpu cost of a sql query?
What are all the measures available for an sql query?
How to identify i am writing optimal query?
I am using Oracle 9i...
It ll be useful for me to write efficient query....
Thanks & Regardspsram wrote:
Hi Experts,
How to measure the performance, efficiency and cpu cost of a sql query?
What are all the measures available for an sql query?
How to identify i am writing optimal query?
I am using Oracle 9i... You might want to start with a feature of SQL*Plus: The AUTOTRACE (TRACEONLY) option which executes your statement, fetches all records (if there is something to fetch) and shows you some basic statistics information, which include the number of logical I/Os performed, number of sorts etc.
This gives you an indication of the effectiveness of your statement, so that can check how many logical I/Os (and physical reads) had to be performed.
Note however that there are more things to consider, as you've already mentioned: The CPU bit is not included in these statistics, and the work performed by SQL workareas (e.g. by hash joins) is also credited only very limited (number of sorts), but e.g. it doesn't cover any writes to temporary segments due to sort or hash operations spilling to disk etc.
You can use the following approach to get a deeper understanding of the operations performed by each row source:
alter session set statistics_level=all;
alter session set timed_statistics = true;
select /* findme */ ... <your query here>
SELECT
SUBSTR(LPAD(' ',DEPTH - 1)||OPERATION||' '||OBJECT_NAME,1,40) OPERATION,
OBJECT_NAME,
CARDINALITY,
LAST_OUTPUT_ROWS,
LAST_CR_BUFFER_GETS,
LAST_DISK_READS,
LAST_DISK_WRITES,
FROM V$SQL_PLAN_STATISTICS_ALL P,
(SELECT *
FROM (SELECT *
FROM V$SQL
WHERE SQL_TEXT LIKE '%findme%'
AND SQL_TEXT NOT LIKE '%V$SQL%'
AND PARSING_USER_ID = SYS_CONTEXT('USERENV','CURRENT_USERID')
ORDER BY LAST_LOAD_TIME DESC)
WHERE ROWNUM < 2) S
WHERE S.HASH_VALUE = P.HASH_VALUE
AND S.CHILD_NUMBER = P.CHILD_NUMBER
ORDER BY ID
/Check the V$SQL_PLAN_STATISTICS_ALL view for more statistics available. In 10g there is a convenient function DBMS_XPLAN.DISPLAY_CURSOR which can show this information with a single call, but in 9i you need to do it yourself.
Note that "statistics_level=all" adds a significant overhead to the processing, so use with care and only when required:
http://jonathanlewis.wordpress.com/2007/11/25/gather_plan_statistics/
http://jonathanlewis.wordpress.com/2007/04/26/heisenberg/
Regards,
Randolf
Oracle related stuff blog:
http://oracle-randolf.blogspot.com/
SQLTools++ for Oracle (Open source Oracle GUI for Windows):
http://www.sqltools-plusplus.org:7676/
http://sourceforge.net/projects/sqlt-pp/ -
Do you have an idea how to improve the performance ?
Hi All,
Greeting,
I'm doing SEM IP. Regarding the performance, do you have some thought about this ?
So I have planning report for project report . As we know, if we forecast against project, means the date itself is the life of the project itself.
It means it could be more than 10 years (forecast period) and 10 years (actual period). Currently I segregate between actual and forecast into different info cube .
But the performance of the planning report is slow now. Do you have an idea about this how to increase the performance. The performance I mentioned here is when we're going to the report (after putting in the value in the selection screen).
The other question, at this moment, I have a multiprovider than this multi provider consist 2 info cubes ( actual and forecast ). Than my aggregation is sitting on top of that multi-provider .
My question whether that's approach correct or not ? Or do we have to create 1 aggregate (only for forecast), than I have multi-provider consisting forecasting aggregation and actual cube .
than my query will sit on top of that multi-provider ?
Which one is better ??
Thanks a lot all,
really need your help,Hi,
For the performance tuning, you can consider any of the following three methods,
1. Indices
With an increasing number of data records in the InfoCube, not only the load but also the query performance can be reduced. This is attributed to the increasing demands on the system for maintaining indexes. The indexes that are created in the fact table for each dimension allow you to easily find and select the data.
2. Partitioning
By using partitioning you can split up the whole dataset for an InfoCube into several, smaller, physically independent and redundancy-free units. Thanks to this separation, performance is increased when reporting, or also when deleting data from the InfoCube.
3. Aggregates
Aggregates make it possible to access InfoCube data quickly in Reporting. Aggregates serve, in a similar way to database indexes, to improve performance.
4. Compressing the Infocube
Infocube compression means aggregation of the data ignoring the request idu2019s. After compression, the system need not perform aggregation using the request ID every time you execute a query.
And I feel that as per your scenario, you need to do first compress the data based on user requirements and have only the required data in the infocube.
And for the approach regarding the Aggregation level design, choosing between the two approaches depends on the user requirements. For example,
If you have aggregation level created on top of multiprovider containing actual and forecast cube, in your report (created on top of aggregation level) you can view the key figure values present in both the cubes, which is not possible in the other approach.
So this approach is suited if your requirement is to view the records from both the cubes in your report (Comparing planning and actual values).
The second approach is used if your requirement is only to report on planning forecast cube.
Hopes this solves your issue.
Regards,
Balajee -
How to test the performed SAP SCRIPT
Hi friends can any one help for
how to test the performed SAP SCRIPT. What are the necessary codes or anything else for performing itPraveen,
Can you be much clear with your query? What do you mean by performing? Do you mean how to execute it ?
Regards,
Vinod. -
How to improve the performance of serialization/deserialization?
Hi, Friends,
I have a question about how to improve the performance of serialization/deserialization.
When an object is serialized, the entire tree of objects rooted at the object is also serialized. When it is deserialized, the tree is reconstructed. For example, suppose a serializable Father object contains (a serializable field of) an array of Child objects. When a Father object is serialized, so is the array of Child objects.
For the sake of performance consideration, when I need to deserialize a Father object, I don't want to deserialize any Child object. However, I should be able to know that Father object has children. I should also be able to deserialize any child of that Father object when necessary.
Could you tell me how to achieve the above idea?
Thanks.
YoubinYou could try something like this...
import java.io.*;
import java.util.*;
class Child implements Serializable {
int id;
Child(int _id) { id=_id; }
public String toString() { return String.valueOf(id); }
class Father implements Serializable
Child[] children = new Child[10];
public Father() {
Arrays.fill(children, new Child(1001));
public void readObject(ObjectInputStream stream)
throws IOException, ClassNotFoundException
int numchildren = stream.readInt();
for(int i=0; i<numchildren; i++)
children[i] = (Child)stream.readObject();
stream.close();
public void writeObject(ObjectOutputStream stream) throws IOException
stream.writeInt(children.length);
for(int i=0; i<children.length; i++)
stream.writeObject(children);
stream.close();
Child[] getChildren() { return children; }
class FatherProxy
int numchildren;
String filename;
public FatherProxy(String _filename) throws IOException
filename = _filename;
ObjectInputStream ois =
new ObjectInputStream(new FileInputStream(filename));
numchildren = ois.readInt();
ois.close();
int getNumChildren() { return numchildren; }
Child[] getChildren() throws IOException, ClassNotFoundException
ObjectInputStream ois =
new ObjectInputStream(new FileInputStream(filename));
Father f = (Father)ois.readObject();
ois.close();
return f.getChildren();
public class fatherref
public static void main(String[] args) throws Exception
// create the serialized file
Father f = new Father();
ObjectOutputStream oos =
new ObjectOutputStream(new FileOutputStream("father.ser"));
oos.writeObject(f);
oos.close();
// read in just what is needed -- numchildren
FatherProxy fp = new FatherProxy("father.ser");
System.out.println("numchildren: " + fp.getNumChildren());
// do some processing
// you need the rest -- children
Child[] c = fp.getChildren();
System.out.println("children:");
for(int i=0; i<c.length; i++)
System.out.println("i " + i + ": " + c[i]); -
How to improve the performance of the query
Hi,
Help me by giving tips how to improve the performance of the query. Can I post the query?
SureshBelow is the formatted query and no wonder it is taking lot of time. Will give you a list of issues soon after analyzing more. Till then understand the pitfalls yourself from this formatted query.
SELECT rt.awb_number,
ar.activity_id as task_id,
t.assignee_org_unit_id,
t.task_type_code,
ar.request_id
FROM activity_task ar,
request_task rt,
task t
WHERE ar.activity_id =t.task_id
AND ar.request_id = rt.request_id
AND ar.complete_status != 'act.stat.closed'
AND t.assignee_org_unit_id in (SELECT org_unit_id
FROM org_unit
WHERE org_unit_id in (SELECT oo.org_unit_id
FROM org_unit oo
WHERE oo.org_unit_id='3'
OR oo.parent_id ='3'
OR parent_id in (SELECT oo.org_unit_id
FROM org_unit oo
WHERE oo.org_unit_id='3'
OR oo.parent_id ='3'
AND has_queue=1
AND ar.parent_task_id not in (SELECT tt.task_id
FROM task tt
WHERE tt.assignee_org_unit_id in (SELECT org_unit_id
FROM org_unit
WHERE org_unit_id in (SELECT oo.org_unit_id
FROM org_unit oo
WHERE oo.org_unit_id='3'
OR oo.parent_id ='3'
OR parent_id in (SELECT oo.org_unit_id
FROM org_unit oo
WHERE oo.org_unit_id='3'
OR oo.parent_id ='3'
AND has_queue=1
AND rt.awb_number is not null
ORDER BY rt.awb_numberCheers
Sarma. -
How to improve the performance of General information in MSS
HI,
We are facing with critical performance issue in General information screen of MSS.
For one employee number of subordinates are more than 3500 and because of this no of database hits for fetching all the records are more than 20,000 and each database hit is taking some time and overall time for fetching all the records is around 2 minutes which is not acceptable.
so we want to cut down the number of hierarchy levels shown to the manager or by keeping the same number of levels how to increase the performance .
Any inputs will be highly appreciated and rewarded with points for sure
Bala DuvvuriHi,
We have problem in performance because when we call General information screen for managers in MSS it reads the data from HRP1001 and if manager is having more data then it will take time.
we rectified this problem by creating an index that caches all the users who have more number of objects .
we created a job that creates index and execute that every day -
HI All, How to improve the performance in given query?
HI All,
How to improve the performance in given query?
Query is..
PARAMETERS : p_vbeln type lips-vbeln.
DATA : par_charg TYPE LIPS-CHARG,
par_werks TYPE LIPS-WERKS,
PAR_MBLNR TYPE MSEG-MBLNR .
SELECT SINGLE charg
werks
INTO (par_charg, par_werks)
FROM lips
WHERE vbeln = p_vbeln.
IF par_charg IS NOT INITIAL.
SELECT single max( mblnr )
INTO par_mblnr
FROM mseg
WHERE bwart EQ '101'
AND werks EQ par_werks (index on werks only)
AND charg EQ par_charg.
ENDIF.
Regards
SteveHi steve,
Can't you use the material in your query (and not only the batch)?
I am assuming your system has an index MSEG~M by MANDT + MATNR + WERKS (+ other fields). Depending on your system (how many different materials you have), this will probably speed up the query considerably.
Anyway, in our system we ended up by creating an index by CHARG, but leave as a last option, only if selecting by matnr and werks is not good enough for your scenario.
Hope this helps,
Rui Dantas
Maybe you are looking for
-
Performance of PL/SQL vs external C function.
Do anyone know how much performance difference there is for a high computation function implemented in PL/SQL vs a external C function? I know that this is a impossible question to answer precisely. But I'm interested in peoples experiences with this
-
Names of files with names in national encoding
Hello. I have created the downloading of files following the example, which oracle gives (http://download.oracle.com/docs/cd/E14373_01/appdev.32/e13363/up_dn_files.htm#CJAHDJDA - Create Download Page for Embedded PL/SQL Gateway). The name of file in
-
Erased contacts when updating N8 to Belle
Hi everybody! I really hope some of you can help me! I have updated my Nokia N8 to Nokia Belle with Nokia Updater for Mac but I cannot find contacts, sms and notes. All disappeared and unfortunately I don't have a backup. It is urgent and important.
-
Update to 10.6.7 causes constant kernel panics
I installed 10.6.7 on my MacPro, after installing I ended up with a Blue Screen. After unplugging al the cables I could start up the system. Now when trying to get connected to the internet I immediately get a Kernel Panic (wireless or ethernet). Wha
-
Beginner Question- Unable to Use Eyedropper and Targeted Adjustment Tools
When trying to use the eyedropper or targeted adjustment tools (in the HSL menu), I will grab the tool and hover over my photo and my cursor changes to the magnifying glass. When using the eyedropper the preview will reflect the white balance but whe