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: 

performance problem

Former Member
0 Kudos

hi experts,

This is my coding part, am facing performance problem.

it goes to time exceed. how to solve this, any changes needs to be applied.

pls suggest me on this. thanks in advance.

Regards

Rajaram.

REPORT ZSAB_SO1.

TABLES : mkpf,mseg,t247.

TYPE-POOLS : slis.

DATA : fcat TYPE slis_t_fieldcat_alv,

ls_fcat LIKE LINE OF fcat,

fheader TYPE TABLE OF slis_listheader WITH NON-UNIQUE DEFAULT KEY

WITH HEADER LINE INITIAL SIZE 0.

DATA : i_repid LIKE sy-repid,

gs_layout TYPE slis_layout_alv,

flag type n.

*Internal Table

DATA : BEGIN OF itab OCCURS 0,

mblnr like mseg-mblnr,

budat like mkpf-budat,

KDAUF like mseg-KDAUF,

KDPOS like mseg-KDPOS,

matnr like mseg-matnr,

WERKS like mseg-werks,

ERFMG like mseg-ERFMG,

ERFME like mseg-ERFME,

BWART like mseg-BWART,

maktx like makt-maktx,

WMENG like vbep-WMENG,

VRKME like vbep-VRKME,

end of itab.

DATA : BEGIN OF itab1 OCCURS 0,

  • mblnr like mseg-mblnr,

lights,

kdauf(90) type c,

kdpos like mseg-kdpos,

  • budat like mkpf-budat,

matnr like mseg-matnr,

werks like mseg-werks,

erfmg like mseg-erfmg,

erfme like mseg-erfme,

bwart like mseg-BWART,

maktx like makt-maktx,

WMENG like vbep-WMENG,

ABGRU like vbap-ABGRU,

status(10) type c,

end of itab1.

DATA : BEGIN OF it_final OCCURS 0,

  • mblnr like mseg-mblnr,

lights,

budat like mkpf-budat,

KDAUF like mseg-KDAUF,

  • kdauf(90) type c,

KDPOS like mseg-KDPOS,

matnr like mseg-matnr,

WERKS like mseg-werks,

ERFMG like mseg-ERFMG,

ERFME like mseg-ERFME,

BWART like mseg-BWART,

maktx like makt-maktx,

WMENG like vbep-WMENG,

ABGRU like vbap-ABGRU,

AEDAT like vbap-AEDAT,

status(10) type c,

month(10) type c,

ltx LIKE t247-ltx,

ktx LIKE t247-ktx,

end of it_final.

DATA : begin of ipos occurs 0,

kda(20) type n,

pos(20) type n,

OBJECTCLAS like cdpos-OBJECTCLAS,

OBJECTID like cdpos-OBJECTID,

CHANGENR like cdpos-CHANGENR,

TABNAME like cdpos-TABNAME,

TABKEY like cdpos-TABKEY,

FNAME like cdpos-FNAME,

CHNGIND like cdpos-CHNGIND,

VALUE_NEW like cdpos-VALUE_NEW,

VALUE_OLD like cdpos-VALUE_OLD,

UDATE like cdhdr-UDATE,

UTIME like cdhdr-UTIME,

CHANGENR1 like cdhdr-CHANGENR,

end of ipos.

DATA : begin of it1 occurs 0,

kda(90) type c,

pos like mseg-kdpos,

OBJECTCLAS like cdpos-OBJECTCLAS,

OBJECTID like cdpos-OBJECTID,

CHANGENR like cdpos-CHANGENR,

TABNAME like cdpos-TABNAME,

TABKEY like cdpos-TABKEY,

FNAME like cdpos-FNAME,

CHNGIND like cdpos-CHNGIND,

VALUE_NEW like cdpos-VALUE_NEW,

VALUE_OLD like cdpos-VALUE_OLD,

UDATE like cdhdr-UDATE,

UTIME like cdhdr-UTIME,

CHANGENR1 like cdhdr-CHANGENR,

matnr like vbap-matnr,

BWART like mseg-BWART,

ERFMG like mseg-ERFMG,

werks like vbap-werks,

end of it1.

*data : it1 like ipos occurs 0 with header line.

data : itab2 like itab1 occurs 0 with header line.

data : e_itab2 like line of itab2.

SELECTION-SCREEN BEGIN OF BLOCK bk1 WITH FRAME TITLE text-001.

SELECT-OPTIONS: zdate FOR mkpf-budat OBLIGATORY.

SELECT-OPTIONS: zpl FOR mseg-WERKS OBLIGATORY.

SELECTION-SCREEN END OF BLOCK bk1.

start-of-selection.

gs_layout-colwidth_optimize = 'X'.

  • Select statement for read all the delivery document

SELECT mseg~mblnr

mkpf~budat

mseg~kdauf

mseg~kdpos

mseg~matnr

mseg~werks

mseg~erfmg

mseg~erfme

mseg~BWART

from mseg

inner join

mkpf on mkpfmblnr EQ msegmblnr

into table itab

where mkpf~budat in zdate and

mseg~werks in zpl and

mseg~kdauf ne ' ' and

( mseg~BWART = '601' or

mseg~bwart = '602').

if sy-subrc = 0.

loop at itab.

if zpl-low is not initial and zpl-high is not initial.

if ( itab-werks not between zpl-low and zpl-high ).

delete itab.

endif.

endif.

if zpl-high is initial and itab-werks <> zpl-low.

delete it1.

endif.

endloop.

endif.

*if itab is not initial.

select cdpos~OBJECTCLAS

cdpos~OBJECTID

cdpos~CHANGENR

cdpos~TABNAME

cdpos~TABKEY

cdpos~FNAME

cdpos~CHNGIND

cdpos~VALUE_NEW

cdpos~VALUE_OLD

from cdpos into corresponding fields of table it1

where tabname = 'VBAP' and

fname = 'ABGRU'.

*endif.

*endif.

loop at it1.

if zdate-high is not initial.

select single CHANGENR UDATE UTIME

from cdhdr

into (it1-CHANGENR1 , it1-UDATE , it1-UTIME)

where CHANGENR = it1-CHANGENR and

UDATE BETWEEN ZDATE-LOW AND ZDATE-HIGH.

IF SY-SUBRC = 0.

modify it1.

ELSE.

DELETE IT1.

ENDIF.

else.

select single CHANGENR UDATE UTIME

from cdhdr

into (it1-CHANGENR1 , it1-UDATE , it1-UTIME)

where CHANGENR = it1-CHANGENR and

UDATE = ZDATE-LOW.

IF SY-SUBRC = 0.

modify it1.

ELSE.

DELETE IT1.

ENDIF.

endif.

endloop.

loop at it1.

it1-kda = it1-tabkey+3(10).

it1-pos = it1-tabkey+14(6).

*it1-kda = it1-tabkey+5(8).

*it1-pos = it1-tabkey+14(6).

modify it1.

endloop.

delete adjacent duplicates from it1 comparing kda pos.

loop at it1.

select single vbeln

posnr

matnr

WERKS

from vbap

into (it1-kda , it1-pos , it1-matnr , it1-werks)

where vbeln = it1-kda and posnr = it1-pos.

modify it1.

endloop.

loop at it1.

if zpl-low is not initial and zpl-high is not initial.

if ( it1-werks not between zpl-low and zpl-high ).

delete it1.

else.

move it1-kda to itab-kdauf.

move it1-pos to itab-kdpos.

move it1-matnr to itab-matnr.

move it1-bwart to itab-bwart.

move it1-erfmg to itab-erfmg.

move it1-werks to itab-werks.

move it1-UDATE to itab-budat.

append itab.

  • flag = 1.

endif.

endif.

if zpl-high is initial and it1-werks <> zpl-low.

delete it1.

elseif zpl-high is initial.

  • if flag = 1.

  • exit.

  • endif.

move it1-kda to itab-kdauf.

move it1-pos to itab-kdpos.

move it1-matnr to itab-matnr.

move it1-bwart to itab-bwart.

move it1-erfmg to itab-erfmg.

move it1-werks to itab-werks.

move it1-UDATE to itab-budat.

append itab.

endif.

endloop.

delete adjacent duplicates from it1 comparing kda pos.

*if itab is initial.

*exit.

*endif.

sort itab.

if itab is not initial.

select a~mblnr

a~kdauf

a~kdpos

a~matnr

a~werks

a~erfmg

a~erfme

a~BWART

b~budat

from mseg as a

inner join mkpf as b on

amblnr = bmblnr

into corresponding fields of table itab1

for all entries in itab

where a~kdauf = itab-kdauf

and a~kdpos = itab-kdpos and

( abwart = '601' or abwart = '602' ) and

a~WERKS = itab-werks and

b~budat le itab-budat.

endif.

if sy-subrc = 0.

loop at itab.

loop at itab1.

if itab-kdauf = itab1-kdauf and itab-kdpos = itab1-kdpos.

flag = 0.

exit.

else.

flag = 1.

endif.

endloop.

if flag = 1.

  • read table itab1 with key kdauf <> itab-kdauf.

select single VBELN

POSNR

wmeng

from vbep

into (itab-kdauf , itab-kdpos , itab-wmeng)

where VBELN = itab-kdauf and

POSNR = itab-kdpos.

move itab-kdauf to itab1-kdauf.

move itab-kdpos to itab1-kdpos.

move itab-wmeng to itab1-wmeng.

move itab-matnr to itab1-matnr.

move itab-bwart to itab1-bwart.

move itab-erfmg to itab1-erfmg.

move itab-werks to itab1-werks.

append itab1.

endif.

endloop.

else.

loop at itab.

select single VBELN

POSNR

wmeng

VRKME

from vbep

into (itab-kdauf , itab-kdpos , itab-wmeng , itab-VRKME)

where VBELN = itab-kdauf and

POSNR = itab-kdpos.

move itab-kdauf to itab1-kdauf.

move itab-kdpos to itab1-kdpos.

move itab-wmeng to itab1-wmeng.

move itab-matnr to itab1-matnr.

move itab-bwart to itab1-bwart.

move itab-erfmg to itab1-erfmg.

move itab-werks to itab1-werks.

move itab-VRKME to itab1-erfme.

append itab1.

endloop.

endif.

loop at itab1.

if zpl-low is not initial and zpl-high is initial.

if ( itab1-werks NE zpl-low ).

delete itab1.

endif.

endif.

endloop.

loop at itab1.

select single maktx

from makt into (itab1-maktx)

where matnr = itab1-matnr.

modify itab1.

endloop.

loop at itab1.

move-corresponding itab1 to itab2.

collect itab2.

endloop.

sort itab2 by kdauf kdpos bwart.

loop at itab2.

read table itab2 into e_itab2 with key kdauf = itab2-kdauf kdpos = itab2-kdpos bwart = '602'.

if sy-subrc eq 0.

delete itab2 index sy-tabix.

itab2-erfmg = itab2-erfmg - e_itab2-erfmg.

endif.

modify itab2.

endloop.

if itab2 is not initial.

select cdpos~OBJECTCLAS

cdpos~OBJECTID

cdpos~CHANGENR

cdpos~TABNAME

cdpos~TABKEY

cdpos~FNAME

cdpos~CHNGIND

cdpos~VALUE_NEW

cdpos~VALUE_OLD

from cdpos into corresponding fields of table ipos

for all entries in itab2

where tabname = 'VBAP' and

fname = 'ABGRU' and

OBJECTID = itab2-kdauf.

endif.

if sy-subrc = 0.

loop at ipos.

ipos-kda = ipos-tabkey+5(8).

ipos-pos = ipos-tabkey+14(6).

modify ipos.

endloop.

loop at ipos.

select single CHANGENR UDATE UTIME

from cdhdr

into (ipos-CHANGENR1 , ipos-UDATE , ipos-UTIME)

where CHANGENR = ipos-CHANGENR.

  • and OBJECTID = ipos-kda.

modify ipos.

endloop.

endif.

loop at itab2.

select single WMENG

from vbep into (itab2-WMENG)

where vbeln = itab2-kdauf and

posnr = itab2-kdpos.

select single ABGRU

from vbap into (itab2-ABGRU)

where vbeln = itab2-kdauf and

posnr = itab2-kdpos.

modify itab2.

endloop.

loop at itab2.

move-corresponding itab2 to it_final.

append it_final.

endloop.

sort itab descending by kdauf kdpos budat descending.

loop at it_final.

read table itab with key kdauf = it_final-kdauf kdpos = it_final-kdpos.

if sy-subrc = 0.

it_final-budat = itab-budat.

modify it_final.

endif.

endloop.

sort it_final by budat descending.

*sort ipos by udate UTIME descending.

sort ipos DESCENDING by kda pos UDATE UTIME .

loop at ipos.

if zdate-high is not initial and ipos-udate GT zdate-high.

delete ipos.

elseif zdate-high is initial and ipos-udate GT zdate-low.

delete ipos.

endif.

endloop.

sort ipos DESCENDING by kda pos UDATE UTIME .

loop at it_final.

read table ipos with key kda = it_final-kdauf pos = it_final-kdpos.

if sy-subrc = 0.

it_final-budat = ipos-udate.

endif.

if it_final-erfmg GE it_final-wmeng.

it_final-status ='COMPLETED'.

it_final-lights = '3'.

else.

if it_final-erfmg LT it_final-wmeng.

if ipos-VALUE_NEW is not initial and ipos-kda = it_final-kdauf and ipos-pos = it_final-kdpos.

it_final-status ='COMPLETED'.

it_final-lights = '3'.

else.

it_final-status ='OPEN'.

it_final-lights = '1'.

endif.

endif.

endif.

modify it_final.

endloop.

loop at it_final.

*if it_final-werks <> zpl.

*delete it_final.

SELECT SINGLE ktx

ltx

INTO (it_final-ktx , it_final-ltx)

FROM t247

WHERE spras = sy-langu AND

mnr EQ it_final-budat+4(2).

translate it_final-ktx to lower case.

translate it_final-ktx(1) to upper case.

modify it_final.

endloop.

perform edit_mask.

i_repid = sy-repid.

PERFORM fieldcat.

gs_layout-lights_fieldname = 'LIGHTS'.

gs_layout-lights_tabname = 'IT_FINAL'.

  • ALV GRID

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

EXPORTING

i_callback_program = i_repid

it_fieldcat = fcat

i_save = 'A'

is_layout = gs_layout

TABLES

t_outtab = it_final

EXCEPTIONS

program_error = 1

OTHERS = 2.

FORM fieldcat .

MOVE sy-repid TO i_repid.

ls_fcat-tabname = 'IT_FINAL'.

ls_fcat-fieldname = 'LIGHTS'.

ls_fcat-outputlen = 10.

ls_fcat-seltext_m = 'STATUS'.

APPEND ls_fcat TO fcat.

ls_fcat-tabname = 'IT_FINAL'.

ls_fcat-fieldname = 'WERKS'.

ls_fcat-outputlen = 4.

ls_fcat-seltext_m = 'Plant'.

APPEND ls_fcat TO fcat.

ls_fcat-tabname = 'IT_FINAL'.

ls_fcat-fieldname = 'BUDAT'.

ls_fcat-outputlen = 10.

ls_fcat-seltext_m = 'Posting Date'.

APPEND ls_fcat TO fcat.

ls_fcat-tabname = 'IT_FINAL'.

ls_fcat-fieldname = 'KTX'.

ls_fcat-outputlen = 3.

ls_fcat-seltext_m = 'Month'.

APPEND ls_fcat TO fcat.

  • ls_fcat-tabname = 'IT_FINAL'.

  • ls_fcat-fieldname = 'MBLNR'.

  • ls_fcat-outputlen = 10.

  • ls_fcat-seltext_m = 'Document'.

  • APPEND ls_fcat TO fcat.

ls_fcat-tabname = 'IT_FINAL'.

ls_fcat-fieldname = 'KDAUF'.

ls_fcat-outputlen = 10.

ls_fcat-seltext_m = 'Sales Document'.

APPEND ls_fcat TO fcat.

ls_fcat-tabname = 'IT_FINAL'.

ls_fcat-fieldname = 'KDPOS'.

ls_fcat-outputlen = 4.

ls_fcat-seltext_m = 'Item'.

APPEND ls_fcat TO fcat.

ls_fcat-tabname = 'IT_FINAL'.

ls_fcat-fieldname = 'MATNR'.

ls_fcat-outputlen = 20.

ls_fcat-seltext_m = 'Material'.

APPEND ls_fcat TO fcat.

ls_fcat-tabname = 'IT_FINAL'.

ls_fcat-fieldname = 'MAKTX'.

ls_fcat-outputlen = 40.

ls_fcat-seltext_m = 'Description'.

APPEND ls_fcat TO fcat.

ls_fcat-tabname = 'IT_FINAL'.

ls_fcat-fieldname = 'WMENG'.

ls_fcat-outputlen = 8.

ls_fcat-seltext_m = 'Ord.Qty'.

APPEND ls_fcat TO fcat.

ls_fcat-tabname = 'IT_FINAL'.

ls_fcat-fieldname = 'ERFMG'.

ls_fcat-outputlen = 8.

ls_fcat-seltext_m = 'PGI Done'.

APPEND ls_fcat TO fcat.

ls_fcat-tabname = 'IT_FINAL'.

ls_fcat-fieldname = 'ERFME'.

ls_fcat-outputlen = 3.

ls_fcat-seltext_m = 'UoM'.

APPEND ls_fcat TO fcat.

ls_fcat-tabname = 'IT_FINAL'.

ls_fcat-fieldname = 'STATUS'.

ls_fcat-outputlen = 12.

ls_fcat-seltext_m = 'Status'.

APPEND ls_fcat TO fcat.

ENDFORM. "fieldcat

form edit_mask.

loop at it_final.

CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT'

EXPORTING

INPUT = it_final-kdauf

IMPORTING

OUTPUT = it_final-kdauf.

CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT'

EXPORTING

INPUT = it_final-kdpos

IMPORTING

OUTPUT = it_final-kdpos.

modify it_final.

endloop.

endform. "edit_mask

2 REPLIES 2

Former Member
0 Kudos

Hi Rajaram,

please avoid using SELECT inside LOOP which will the major cause for low performance of ur code.

and try to use Parallel cursor algorithm when you use loop inside another loop.

Thanks and Regards,

S.N.Venkatesh

Former Member
0 Kudos

Hi,

U have used select inside the loop. That's the main problem. Use FOR ALL ENTRIES. After getting values from first select query, use FOR ALL ENTRIES of first internal table. Don't use select inside loop. And also, it will take time to retrieve from MSEG table, so pass all the key fields. Check SY-SUBRC after each query. Rewrite the coding using above points, it will definitely work.

Reward if found useful.