Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Optimization tips plz....

Former Member
0 Kudos

hi,

i am pasting the following code plz suggest the optimization tips ASAP.

Reward points are guaranteed.

&----


*& Include ZPMR_RG_CHAP7_PROCESS *

&----


START-OF-SELECTION.

IF s_period-high IS INITIAL.

s_period-high = sy-datum.

s_period-option = 'BT'.

MODIFY s_period INDEX 1.

ENDIF.

SELECT a~aufnr

a~auart

a~objnr

c~ilart

INTO TABLE i_ords

FROM aufk AS a INNER JOIN afih AS c ON aaufnr = caufnr

INNER JOIN afko AS d ON aaufnr = daufnr

WHERE ( a~auart IN ('ES01' , 'CC03') )

  • AND ( c~ilart IN ('U' , 'P' , 'O' , 'C') )

AND ( d~getri <> '00000000' )

AND ( a~idat2 IN s_period ) .

i_cc03_ords[] = i_ords[].

DELETE i_ords WHERE auart <> 'ES01'.

IF NOT i_ords[] IS INITIAL.

SELECT objnr stat chgnr inact FROM jcds INTO TABLE i_nttab FOR ALL

ENTRIES IN i_ords

WHERE objnr = i_ords-objnr AND

( ( stat = 'E0035' ) OR ( stat = 'E0039' ) ) .

SORT i_nttab DESCENDING BY objnr stat chgnr.

DELETE ADJACENT DUPLICATES FROM i_nttab COMPARING objnr stat.

DELETE i_nttab WHERE inact = 'X' .

DESCRIBE TABLE i_nttab LINES v_noes.

ENDIF.

DELETE i_ords WHERE ( ilart <> 'U' ) AND ( ilart <> 'P' ) AND

( ilart <> 'C' ) AND ( ilart <> 'O' ) .

i_ordscp[] = i_ords[].

DELETE i_ordscp WHERE ilart <> 'C' .

DESCRIBE TABLE i_ordscp LINES v_int.

*for uncontrolled esc-histogram.

i_ordscp[] = i_ords[].

DELETE i_ordscp WHERE ilart = 'C' .

IF NOT i_ordscp[] IS INITIAL.

SELECT aaufnr agstrp agsuzp biedd b~iedz INTO CORRESPONDING FIELDS

OF TABLE i_uncont

FROM afko AS a INNER JOIN afru AS b

ON aaufnr = baufnr

FOR ALL ENTRIES IN i_ordscp

WHERE aaufnr = i_ordscp-aufnr AND bgrund = 'ONS'

AND b~stzhl = '00000000' .

SORT i_uncont ASCENDING BY aufnr iedd iedz.

DELETE ADJACENT DUPLICATES FROM i_uncont COMPARING aufnr.

ENDIF.

*Form for Uncontrolled escapes.

PERFORM uncontroll_escapes.

CLEAR: i_uncont[],i_uncont.

CLEAR : i_ordscp[],i_ordscp.

*For Controlled Esc-histogram

i_ordscp[] = i_ords[].

DELETE i_ordscp WHERE ilart <> 'C' .

IF NOT i_ordscp[] IS INITIAL.

*selecting afru details for base orders.

SELECT aufnr iedd iedz grund aueru FROM afru INTO TABLE i_base_afru

FOR ALL ENTRIES IN i_ordscp WHERE aufnr = i_ordscp-aufnr.

*selecting basic start date of orders

SELECT aufnr gstrp gsuzp FROM afko INTO CORRESPONDING FIELDS OF TABLE

i_contafko FOR ALL ENTRIES

IN i_ordscp WHERE aufnr = i_ordscp-aufnr.

*deleting orders that are not final confirmed.

LOOP AT i_base_afru INTO wa_base_afru WHERE grund = 'COM'.

IF wa_base_afru-aueru = ' '.

DELETE i_base_afru WHERE aufnr = wa_base_afru-aufnr.

ENDIF.

CLEAR wa_base_afru.

ENDLOOP.

ENDIF.

*Form for Controlled Escapes

PERFORM controlled_escapes.

CLEAR : i_ordscp[],i_ordscp.

i_ordscp[] = i_ords[].

DELETE i_ordscp WHERE ilart <> 'O' .

IF NOT i_ordscp[] IS INITIAL.

SELECT objnr stat chgnr udate utime FROM jcds INTO TABLE i_tecotab FOR

ALL ENTRIES IN i_ordscp WHERE objnr = i_ordscp-objnr

AND stat EQ 'I0045' .

SORT i_tecotab DESCENDING BY objnr chgnr.

DELETE ADJACENT DUPLICATES FROM i_tecotab COMPARING objnr.

SELECT aufnr gstrp gsuzp FROM afko INTO CORRESPONDING FIELDS OF TABLE

i_defer FOR ALL ENTRIES IN

i_ordscp WHERE aufnr = i_ordscp-aufnr.

ENDIF.

*For Jobs deferred.

PERFORM defer_28days.

*Selecting open orders.

PERFORM select_open_ords.

PERFORM cc03_process.

PERFORM proj_process.

*select notification number.

IF NOT i_ords[] IS INITIAL.

SELECT aufnr qmnum FROM afih INTO TABLE i_qmnum FOR ALL ENTRIES IN

i_ords WHERE aufnr = i_ords-aufnr.

ENDIF.

SORT i_qmnum BY aufnr.

SORT i_notitem BY classif.

*Reading Class Characteristics

LOOP AT i_ords INTO wa_ords.

READ TABLE i_qmnum INTO wa_qmnum WITH KEY aufnr = wa_ords-aufnr.

IF sy-subrc EQ 0.

CALL FUNCTION 'BAPI_ALM_NOTIF_GET_DETAIL'

EXPORTING

number = wa_qmnum-qmnum

  • IMPORTING

  • NOTIFHEADER_EXPORT =

  • NOTIFHDTEXT =

TABLES

  • NOTLONGTXT =

notitem = i_notitem

  • NOTIFCAUS =

  • NOTIFACTV =

  • NOTIFTASK =

  • NOTIFPARTNR =

return = i_return

.

IF ( i_return[] IS INITIAL ) AND NOT ( i_notitem[] IS INITIAL ).

READ TABLE i_notitem INTO wa_notitem

WITH KEY classif = 'EM_LIS_SITE_DTS' .

IF sy-subrc NE 0.

CONTINUE.

ELSE.

CONCATENATE wa_notitem-notif_no wa_notitem-item_key INTO l_object.

CALL FUNCTION 'BAPI_OBJCL_GETDETAIL'

EXPORTING

objectkey = l_object

objecttable = c_objtab

classnum = wa_notitem-classif

classtype = wa_notitem-class_type

keydate = sy-datum

language = sy-langu

TABLES

allocvaluesnum = i_charnum

allocvalueschar = i_charval

allocvaluescurr = i_valcurr

return = i_return1.

IF NOT i_charval[] IS INITIAL.

READ TABLE i_charval WITH KEY charact = 'EM_LISPRESSURE'.

IF sy-subrc EQ 0.

CASE i_charval-value_neutral.

WHEN 'HP'.

ADD 1 TO v_hp.

WHEN 'IP'.

ADD 1 TO v_ip.

WHEN 'MP'.

ADD 1 TO v_mp.

WHEN 'LP'.

ADD 1 TO v_lp.

ENDCASE.

ENDIF.

ENDIF.

ENDIF.

ENDIF.

ENDIF.

CLEAR: wa_notitem, l_object, i_charnum[], i_charval[], i_valcurr[],

i_return[],i_notitem[],wa_qmnum.

ENDLOOP.

v_tot = v_hp + v_ip + v_mp + v_lp.

PERFORM display_output.

TOP-OF-PAGE .

FORMAT COLOR COL_HEADING.

CALL FUNCTION 'ZPM_HEADER_ROUTINE'

EXPORTING

datum = sy-datum

pagno = sy-pagno

title1 = 'Wales & West Utilities'

title2 = 'RIGS Chapter 7'

uname = sy-uname.

&----


*& Form uncontroll_escapes

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM uncontroll_escapes .

LOOP AT i_uncont INTO wa_uncont.

CONCATENATE wa_uncont-iedd wa_uncont-iedz INTO v_fco.

CONCATENATE wa_uncont-gstrp wa_uncont-gsuzp INTO v_bas.

CALL FUNCTION 'CCU_TIMESTAMP_DIFFERENCE'

EXPORTING

timestamp1 = v_fco

timestamp2 = v_bas

IMPORTING

difference = v_diff.

IF v_diff BETWEEN 0 AND 900.

ADD 1 TO v_fcol1.

ELSEIF v_diff BETWEEN 901 AND 1800.

ADD 1 TO v_fcol2.

ELSEIF v_diff BETWEEN 1801 AND 2700.

ADD 1 TO v_fcol3.

ELSEIF v_diff BETWEEN 2701 AND 3600.

ADD 1 TO v_fcol4.

ELSEIF v_diff GT 3600.

ADD 1 TO v_fcol5.

ENDIF.

ADD v_diff TO v_unc_tot.

CLEAR: v_fco,v_bas,wa_uncont,v_diff.

ENDLOOP.

v_tot_uc = ( v_fcol1 + v_fcol2 + v_fcol3 + v_fcol4 + v_fcol5 ).

v_uc_mean = ( v_unc_tot / v_tot_uc ).

v_uc_mean = v_uc_mean / 60 . "in minutes

ENDFORM. " uncontroll_escapes

&----


*& Form Controlled_escapes

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM controlled_escapes .

*Deleting suborders with COM status - but not final conf indicator.

LOOP AT i_suborder INTO wa_suborder WHERE grund = 'COM'.

IF wa_suborder-aueru = ' '.

DELETE i_suborder WHERE suborder = wa_suborder-suborder.

ENDIF.

CLEAR wa_suborder.

ENDLOOP.

SORT i_base_afru BY aufnr.

SORT i_contafko BY aufnr.

LOOP AT i_ordscp INTO wa_ords.

READ TABLE i_base_afru INTO wa_base_afru WITH KEY aufnr = wa_ords-aufnr

grund = 'ONS'.

IF sy-subrc = 0.

CONCATENATE wa_base_afru-iedd wa_base_afru-iedz INTO v_ons.

READ TABLE i_contafko INTO wa_contafko WITH KEY aufnr = wa_ords-aufnr.

CONCATENATE wa_contafko-gstrp wa_contafko-gsuzp INTO v_com.

ENDIF.

CALL FUNCTION 'CCU_TIMESTAMP_DIFFERENCE'

EXPORTING

timestamp1 = v_ons

timestamp2 = v_com

IMPORTING

difference = v_cont_diff.

ADD v_cont_diff TO v_cont_tot.

*----


IF v_cont_diff BETWEEN 0 AND 900.

ADD 1 TO v_fcol21.

ELSEIF v_cont_diff BETWEEN 901 AND 1800.

ADD 1 TO v_fcol22.

ELSEIF v_cont_diff BETWEEN 1801 AND 2700.

ADD 1 TO v_fcol23.

ELSEIF v_cont_diff BETWEEN 2701 AND 3600.

ADD 1 TO v_fcol24.

ELSEIF v_cont_diff BETWEEN 3601 AND 4500.

ADD 1 TO v_fcol25.

ELSEIF v_cont_diff BETWEEN 4501 AND 5400.

ADD 1 TO v_fcol26.

ELSEIF v_cont_diff BETWEEN 5401 AND 6300.

ADD 1 TO v_fcol27.

ELSEIF v_cont_diff BETWEEN 6301 AND 7200.

ADD 1 TO v_fcol28.

ELSEIF v_cont_diff GT 7200.

ADD 1 TO v_fcol29.

ENDIF.

CLEAR : wa_contafko,v_cont_diff,wa_base_afru.

ENDLOOP.

v_tot_cont = ( v_fcol21 + v_fcol22 + v_fcol23 + v_fcol24 +

v_fcol25 + v_fcol26 + v_fcol27 + v_fcol28 + v_fcol29 ).

CATCH SYSTEM-EXCEPTIONS arithmetic_errors = 5.

v_cont_mean = v_cont_tot / v_tot_cont.

ENDCATCH.

v_cont_mean = v_cont_mean / 60.

ENDFORM. " Controlled_escapes

&----


*& Form defer_28days

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM defer_28days .

*selecting afru details for base orders.

IF NOT i_ordscp[] IS INITIAL.

CLEAR: i_base_afru[],i_base_afru.

SELECT aufnr iedd iedz grund aueru FROM afru INTO TABLE i_base_afru

FOR ALL ENTRIES IN i_ordscp WHERE aufnr = i_ordscp-aufnr.

ENDIF.

SORT i_defer BY aufnr.

SORT i_tecotab BY objnr.

LOOP AT i_ordscp INTO wa_ords.

READ TABLE i_defer INTO wa_defer WITH KEY aufnr = wa_ords-aufnr.

IF sy-subrc = 0.

READ TABLE i_tecotab INTO wa_tecotab WITH KEY objnr = wa_ords-objnr.

IF sy-subrc = 0.

CONCATENATE wa_defer-gstrp wa_defer-gsuzp INTO v_bas.

CONCATENATE wa_tecotab-udate wa_tecotab-utime INTO v_fco.

CALL FUNCTION 'CCU_TIMESTAMP_DIFFERENCE'

EXPORTING

timestamp1 = v_fco

timestamp2 = v_bas

IMPORTING

difference = v_diff.

ENDIF.

ENDIF.

IF v_diff BETWEEN 2505600 AND 3024000.

ADD 1 TO v_fcol31.

ELSEIF v_diff BETWEEN 3024001 AND 3628800.

ADD 1 TO v_fcol32.

ELSEIF v_diff BETWEEN 3628801 AND 4233600.

ADD 1 TO v_fcol33.

ELSEIF v_diff BETWEEN 4233601 AND 4838400.

ADD 1 TO v_fcol34.

ELSEIF v_diff GT 4838400 .

ADD 1 TO v_fcol35.

ENDIF.

*calculation for median.

*----


DELETE i_base_afru WHERE grund <> 'ONS' AND grund <> 'COM' AND

grund <> 'SUS'.

CLEAR: v_ons,v_com.

READ TABLE i_base_afru INTO wa_base_afru WITH KEY aufnr = wa_ords-aufnr

grund = 'ONS'.

IF sy-subrc = 0.

CONCATENATE wa_base_afru-iedd wa_base_afru-iedz INTO v_ons.

READ TABLE i_base_afru INTO wa_base_afru WITH KEY aufnr = wa_ords-aufnr

grund = 'COM'.

CONCATENATE wa_base_afru-iedd wa_base_afru-iedz INTO v_com.

ENDIF.

CALL FUNCTION 'CCU_TIMESTAMP_DIFFERENCE'

EXPORTING

timestamp1 = v_com

timestamp2 = v_ons

IMPORTING

difference = v_diff_xm.

DO.

CLEAR: v_sus,v_ons,wa_base_afru,v_index3.

READ TABLE i_base_afru INTO wa_base_afru WITH KEY

aufnr = wa_ords-aufnr

grund = 'SUS'.

IF sy-subrc = 0.

CONCATENATE wa_base_afru-iedd wa_base_afru-iedz INTO v_sus.

CLEAR wa_base_afru.

v_index3 = sy-tabix.

DELETE i_base_afru INDEX v_index3.

  • v_index3 = v_index3 + 1.

READ TABLE i_base_afru INTO wa_base_afru INDEX v_index3 .

IF sy-subrc = 0.

DELETE i_base_afru INDEX v_index3.

CONCATENATE wa_base_afru-iedd wa_base_afru-iedz INTO v_ons.

CALL FUNCTION 'CCU_TIMESTAMP_DIFFERENCE'

EXPORTING

timestamp1 = v_ons

timestamp2 = v_sus

IMPORTING

difference = v_diff_xs.

ENDIF.

ELSE.

DELETE i_base_afru WHERE aufnr = wa_ords-aufnr.

EXIT.

ENDIF.

ENDDO.

v_diff = ( v_diff_xm - v_diff_xs ).

ADD v_diff TO v_def_tot.

*----


*add v_diff to v_def_tot.

CLEAR: v_fco,v_bas , v_diff_xm,

v_diff_xs,wa_base_afru,v_ons,v_sus,v_com,v_diff.

ENDLOOP.

CATCH SYSTEM-EXCEPTIONS arithmetic_errors = 5.

v_def_ptot = ( v_def_tot ) / ( ( 86400 ) *

( v_fcol31 + v_fcol32 + v_fcol33 + v_fcol34 + v_fcol35 ) ).

ENDCATCH.

ENDFORM. " defer_28days

&----


*& Form select_open_ords

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM select_open_ords .

DATA: v_year(4) TYPE c.

CLEAR s_period.

IF sy-datum+4(2) GE '05'.

CONCATENATE sy-datum+0(4) '04' '01' INTO s_period-low.

MOVE sy-datum TO s_period-high.

MOVE 'BT' TO s_period-option.

MOVE 'I' TO s_period-sign.

MODIFY s_period INDEX 1.

ELSE.

v_year = sy-datum+0(4).

v_year = v_year - 1.

CONCATENATE v_year '04' '01'

INTO s_period-low.

MOVE sy-datum TO s_period-high.

MOVE 'BT' TO s_period-option .

MOVE 'I' TO s_period-sign.

MODIFY s_period INDEX 1.

ENDIF.

SELECT aaufnr bgstrp b~gsuzp FROM

aufk AS a INNER JOIN afko AS b ON aaufnr = baufnr

INNER JOIN afih AS c ON aaufnr = caufnr

INTO TABLE i_openords

WHERE aidat2 = '00000000' AND cilart = 'O' AND b~gstrp IN s_period.

SORT i_openords ASCENDING BY gstrp gsuzp.

READ TABLE i_openords INTO wa_openords INDEX 1.

WRITE wa_openords-gstrp TO v_oldest DD/MM/YYYY.

ENDFORM. " select_open_ords

&----


*& Form cc03_process

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM cc03_process .

CLEAR i_cc03_ords1[]. i_cc03_ords1[] = i_cc03_ords[].

DELETE i_cc03_ords1 WHERE ilart <> 'SNH'.

DESCRIBE TABLE i_cc03_ords1 LINES v_snh.

CLEAR i_cc03_ords1[]. i_cc03_ords1[] = i_cc03_ords[].

DELETE i_cc03_ords1 WHERE ilart <> 'SNX'.

DESCRIBE TABLE i_cc03_ords1 LINES v_snx.

CLEAR i_cc03_ords1[]. i_cc03_ords1[] = i_cc03_ords[].

DELETE i_cc03_ords1 WHERE ilart <> 'SHE'.

DESCRIBE TABLE i_cc03_ords1 LINES v_seh.

CLEAR i_cc03_ords1[]. i_cc03_ords1[] = i_cc03_ords[].

DELETE i_cc03_ords1 WHERE ilart <> 'UI' AND ilart <> 'IG'.

DESCRIBE TABLE i_cc03_ords1 LINES v_uig.

v_stot = v_snh + v_snx + v_seh + v_uig.

ENDFORM. " cc03_process

&----


*& Form Proj_process

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM proj_process .

SELECT apspnr apspid bpspnr bprart FROM proj AS a

INNER JOIN prps AS b

ON apspnr = bpsphi INTO TABLE i_proj

WHERE aplfaz IN s_period AND bprart = 'DC' .

*select count( * ) from proj into v_nwtot1 where profl = 'ZG7CUPR' and

*plfaz in s_period.

SELECT apspnr apspid bpspnr bprart FROM proj AS a

INNER JOIN prps AS b

ON apspnr = bpsphi INTO TABLE i_proj1

WHERE aplfaz IN s_period AND aprofl = 'ZG7CUPR' .

LOOP AT i_proj INTO wa_proj.

CALL FUNCTION 'BAPI_PROJECT_GETINFO'

EXPORTING

project_definition = wa_proj-pspid

with_activities = 'X'

IMPORTING

e_project_definition = i_projdef

return = i_return_proj

TABLES

e_wbs_element_table = i_wbselmnts

e_activity_table = i_nwact.

IF NOT i_return_proj-type = 'E'.

LOOP AT i_nwact.

v_nwact = v_nwact + i_nwact-work_activity.

ENDLOOP.

ENDIF.

CLEAR: wa_proj, i_nwact[],i_nwact.

ENDLOOP.

v_nwact = v_nwact / 1000.

DESCRIBE TABLE i_proj LINES v_nwtot.

CLEAR: wa_proj, i_nwact[],i_nwact,i_projdef,i_return_proj,

i_wbselmnts[].

DESCRIBE TABLE i_proj1 LINES v_nwtot1.

ENDFORM. " Proj_process

1 ACCEPTED SOLUTION

0 Kudos

Hi,

Try avoiding negative checking in SELECT statement like NOT <> etc. Negative statements take more time than the positive statements.

Also try and create a DATABASE VIEW instead of creating INNER JOINS. Then buffers come in to picture. using JOINS will not be off benefit if the actual tables are buffered. You can create view and set buffering for the view.

Regards,

Sesh

4 REPLIES 4

0 Kudos

Hi,

Try avoiding negative checking in SELECT statement like NOT <> etc. Negative statements take more time than the positive statements.

Also try and create a DATABASE VIEW instead of creating INNER JOINS. Then buffers come in to picture. using JOINS will not be off benefit if the actual tables are buffered. You can create view and set buffering for the view.

Regards,

Sesh

Former Member
0 Kudos

Performance tuning for Data Selection Statement

http://www.sap-img.com/abap/performance-tuning-for-data-selection-statement.htm

Performance optimization is Improving the execution time of a program without changing the functionality.

You can see a report performance in SE30(Runtime analysis)and SQLtrace(ST05).

ST05 tells you the list of selected statements.

You should remember some points when you tuning the code

In select stmnt,in where condition you should use proper index.

Try to avoid select stmnts inside the Loop..Endloop with Read statement followed by binary search.

Try to avoid joins more than 2 tables.

For more optimization techniques you see Tips in SE30.

U can also check blogs there is an article.

Keyword Performance tuning.

Please see this

http://www.erpgenie.com/sap/abap/performance.htm

You check the perf by various ways .e.g you can use SCI tcode i.e sap code inspector it's tool used forto check for abap code for perf analysis.

http://help.sap.com/saphelp_nw04/helpdata/en/56/fd3b87d203064aa925256ff88d931b/content.htm

http://help.sap.com/saphelp_nw04/helpdata/en/a1/3323c0a4e37f47a671b7c5a5083362/content.htm

Also check the foll links.

http://www.sapdevelopment.co.uk/perform/performhome.htm

http://www.erpgenie.com/abap/performance.htm

good article

http://www.thespot4sap.com/articles/SAPABAPPerformanceTuning_ABAPSort.asp

some hands on notes.

http://www.erpgenie.com/abap/performance.htm

http://www.thespot4sap.com/Articles/SAPABAPPerformanceTuning_PerformanceAnalysisTools.asp

http://www.sap-img.com/abap/performance-tuning-for-data-selection-statement.htm

Performance tuning for Data Selection Statement

For all entries

The for all entries creates a where clause, where all the entries in the driver table are combined with OR. If the number of

entries in the driver table is larger than rsdb/max_blocking_factor, several similar SQL statements are executed to limit the

length of the WHERE clause.

The plus

Large amount of data

Mixing processing and reading of data

Fast internal reprocessing of data

Fast

The Minus

Difficult to program/understand

Memory could be critical (use FREE or PACKAGE size)

Some steps that might make FOR ALL ENTRIES more efficient:

Removing duplicates from the the driver table

Sorting the driver table

If possible, convert the data in the driver table to ranges so a BETWEEN statement is used instead of and OR statement:

FOR ALL ENTRIES IN i_tab

WHERE mykey >= i_tab-low and

mykey <= i_tab-high.

Nested selects

The plus:

Small amount of data

Mixing processing and reading of data

Easy to code - and understand

The minus:

Large amount of data

when mixed processing isn’t needed

Performance killer no. 1

Select using JOINS

The plus

Very large amount of data

Similar to Nested selects - when the accesses are planned by the programmer

In some cases the fastest

Not so memory critical

The minus

Very difficult to program/understand

Mixing processing and reading of data not possible

Use the selection criteria

SELECT * FROM SBOOK.

CHECK: SBOOK-CARRID = 'LH' AND

SBOOK-CONNID = '0400'.

ENDSELECT.

SELECT * FROM SBOOK

WHERE CARRID = 'LH' AND

CONNID = '0400'.

ENDSELECT.

Use the aggregated functions

C4A = '000'.

SELECT * FROM T100

WHERE SPRSL = 'D' AND

ARBGB = '00'.

CHECK: T100-MSGNR > C4A.

C4A = T100-MSGNR.

ENDSELECT.

SELECT MAX( MSGNR ) FROM T100 INTO C4A

WHERE SPRSL = 'D' AND

ARBGB = '00'.

Select with view

SELECT * FROM DD01L

WHERE DOMNAME LIKE 'CHAR%'

AND AS4LOCAL = 'A'.

SELECT SINGLE * FROM DD01T

WHERE DOMNAME = DD01L-DOMNAME

AND AS4LOCAL = 'A'

AND AS4VERS = DD01L-AS4VERS

AND DDLANGUAGE = SY-LANGU.

ENDSELECT.

SELECT * FROM DD01V

WHERE DOMNAME LIKE 'CHAR%'

AND DDLANGUAGE = SY-LANGU.

ENDSELECT.

Select with index support

SELECT * FROM T100

WHERE ARBGB = '00'

AND MSGNR = '999'.

ENDSELECT.

SELECT * FROM T002.

SELECT * FROM T100

WHERE SPRSL = T002-SPRAS

AND ARBGB = '00'

AND MSGNR = '999'.

ENDSELECT.

ENDSELECT.

Select … Into table

REFRESH X006.

SELECT * FROM T006 INTO X006.

APPEND X006.

ENDSELECT

SELECT * FROM T006 INTO TABLE X006.

Select with selection list

SELECT * FROM DD01L

WHERE DOMNAME LIKE 'CHAR%'

AND AS4LOCAL = 'A'.

ENDSELECT

SELECT DOMNAME FROM DD01L

INTO DD01L-DOMNAME

WHERE DOMNAME LIKE 'CHAR%'

AND AS4LOCAL = 'A'.

ENDSELECT

Key access to multiple lines

LOOP AT TAB.

CHECK TAB-K = KVAL.

" ...

ENDLOOP.

LOOP AT TAB WHERE K = KVAL.

" ...

ENDLOOP.

Copying internal tables

REFRESH TAB_DEST.

LOOP AT TAB_SRC INTO TAB_DEST.

APPEND TAB_DEST.

ENDLOOP.

TAB_DEST[] = TAB_SRC[].

Modifying a set of lines

LOOP AT TAB.

IF TAB-FLAG IS INITIAL.

TAB-FLAG = 'X'.

ENDIF.

MODIFY TAB.

ENDLOOP.

TAB-FLAG = 'X'.

MODIFY TAB TRANSPORTING FLAG

WHERE FLAG IS INITIAL.

Deleting a sequence of lines

DO 101 TIMES.

DELETE TAB_DEST INDEX 450.

ENDDO.

DELETE TAB_DEST FROM 450 TO 550.

Linear search vs. binary

READ TABLE TAB WITH KEY K = 'X'.

READ TABLE TAB WITH KEY K = 'X' BINARY SEARCH.

Comparison of internal tables

DESCRIBE TABLE: TAB1 LINES L1,

TAB2 LINES L2.

IF L1 <> L2.

TAB_DIFFERENT = 'X'.

ELSE.

TAB_DIFFERENT = SPACE.

LOOP AT TAB1.

READ TABLE TAB2 INDEX SY-TABIX.

IF TAB1 <> TAB2.

TAB_DIFFERENT = 'X'. EXIT.

ENDIF.

ENDLOOP.

ENDIF.

IF TAB_DIFFERENT = SPACE.

" ...

ENDIF.

IF TAB1[] = TAB2[].

" ...

ENDIF.

Modify selected components

LOOP AT TAB.

TAB-DATE = SY-DATUM.

MODIFY TAB.

ENDLOOP.

WA-DATE = SY-DATUM.

LOOP AT TAB.

MODIFY TAB FROM WA TRANSPORTING DATE.

ENDLOOP.

Appending two internal tables

LOOP AT TAB_SRC.

APPEND TAB_SRC TO TAB_DEST.

ENDLOOP

APPEND LINES OF TAB_SRC TO TAB_DEST.

Deleting a set of lines

LOOP AT TAB_DEST WHERE K = KVAL.

DELETE TAB_DEST.

ENDLOOP

DELETE TAB_DEST WHERE K = KVAL.

Tools available in SAP to pin-point a performance problem

The runtime analysis (SE30)

SQL Trace (ST05)

Tips and Tricks tool

The performance database

Optimizing the load of the database

Using table buffering

Using buffered tables improves the performance considerably. Note that in some cases a stament can not be used with a buffered table, so when using these staments the buffer will be bypassed. These staments are:

Select DISTINCT

ORDER BY / GROUP BY / HAVING clause

Any WHERE clasuse that contains a subquery or IS NULL expression

JOIN s

A SELECT... FOR UPDATE

If you wnat to explicitly bypass the bufer, use the BYPASS BUFFER addition to the SELECT clause.

Use the ABAP SORT Clause Instead of ORDER BY

The ORDER BY clause is executed on the database server while the ABAP SORT statement is executed on the application server. The datbase server will usually be the bottleneck, so sometimes it is better to move thje sort from the datsbase server to the application server.

If you are not sorting by the primary key ( E.g. using the ORDER BY PRIMARY key statement) but are sorting by another key, it could be better to use the ABAP SORT stament to sort the data in an internal table. Note however that for very large result sets it might not be a feasible solution and you would want to let the datbase server sort it.

Avoid ther SELECT DISTINCT Statement

As with the ORDER BY clause it could be better to avoid using SELECT DISTINCT, if some of the fields are not part of an index. Instead use ABAP SORT + DELETE ADJACENT DUPLICATES on an internal table, to delete duplciates.

SE30 - gives you a run time analysis and points out the issues more at design time.

ST05 - Is the most useful if you want to track time taken for execution of each of the sections.

SM50 - Will give you a work process overview, not sure at a program level how can it help you.

Some times you will have to use a combination of SE30 and ST05.

I would like to use St05 personally.

If helpful rEward points by clicking the radio button on left hand side of the answer ..

-regards,

nanda

Former Member
0 Kudos

Your SELECTs are using key fields, so I don't think that's the problem. But you do some:


LOOP AT ...
  READ TABLE ...
  READ TABLE ...
ENDLOOP.

These are essentially nested loops. If you sort the tables you are reading and then use the BINARY SEARCH option of the READ statement, your run time should be reduced.

Rob

Former Member
0 Kudos

resolved