Добрый день!
Имеется стандартный отчет. В один прекрасный момент он из просто долгоиграющего превратился не в НеприличноСуперДолгоиграющего, время формирования увеличилось в десятки раз!
Проверили возможные причины и произошедшие в этот период события, которые могли привести к такому "превращению":
1. изменение железа - не производилось;
2. установка нот - была одна. Её откат не дал существенных улучшений.
3. рост объема данных - всё линейно, всё как обычно;
4. увеличение нагрузки на сервер другими отчетами/приложениями - не замечено, всё как обычно.
Осталась ещё одна:
5. Обновили ядро до SAP Kernel Release - 700, Patch Level - 302.
Проверить её пока не удалось, т.к. не осталось ни одного сервера со старой версией. Поэтому, форумчане, нужна ваша помощь. Запустите програмку (см. код ниже) в фоне, чтобы сравнить время выполнения по разным версиям ядра. В программе кусок кода того самого долгоиграющего отчета, на выполнение которого тратится основное время, и генератор данных для него. Понятно, что разность железа будет вносить свои коррективы, но все-таки я надеюсь, не столь ощутимо. У нас на разных серверах время выполнения отличается не существенно.
Code:
*&---------------------------------------------------------------------*
*& Report Z_OBOROT_TEST
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT z_oborot_test.
DATA i TYPE i.
TYPES:
type_link(63) TYPE c,
type_tblsb(4) TYPE c,
type_gazprst TYPE beszug,
type_1c(1) TYPE c,
abap_bool TYPE c LENGTH 1.
TYPES:
begin of J_3RMLISTDOK,
XMATNR TYPE MATNR,
BWTAR TYPE BWTAR_D,
WERK TYPE WERKS_D,
LGORT TYPE LGORT_D,
charg TYPE charg_d,
SOBKZ TYPE SOBKZ,
LINKK(24) TYPE c,
J_3RFTYPEDOC(1) TYPE c,
BUDAT TYPE BUDAT,
BELEGNR TYPE MBLNR,
MZEILE TYPE MBLPO,
BWART TYPE BWART,
XBELNR TYPE BELNR_D,
BUZEI TYPE BUZEI,
XKTNR(4) TYPE c,
VKNTR(12) TYPE c,
ITEMS(5) TYPE c,
XMEINS TYPE MEINS,
XMENSH_IN TYPE QUAN1_9,
XMENSH_OUT TYPE QUAN1_9,
XDMSHB_IN TYPE SUMM9,
XDMSHB_OUT TYPE SUMM9,
XCHANGPRICE TYPE SUMM9,
XWAERS TYPE WAERS,
XWRBT_IN TYPE SUMM9,
XWRBT_OUT TYPE SUMM9,
BWAERS TYPE WAERS,
HKONT TYPE HKONT,
XBLNR TYPE XBLNR1,
EBELN TYPE EBELN,
RESWK TYPE RESWK,
PSPNR TYPE PS_POSNR,
VBELN TYPE VBELN,
POSNR TYPE POSNR,
VTWEG TYPE VTWEG,
KUNNR_AG(10) TYPE c,
NAME_AG TYPE NAME_AG,
KUNNR_WE(10) TYPE c,
NAME_WE TYPE NAME_WE,
LIFNR TYPE ELIFN,
NAME_LIFNR TYPE NAME1_LF,
MFRNR TYPE MFRNR,
NAME_PRDLIFNR(30) TYPE c,
ROUTE TYPE ROUTE,
COLOR_BANNER TYPE CHAR3,
end of J_3RMLISTDOK,
begin of J_3RMLISTDOKW,
FIELD_LINK(63) TYPE C,
XMATNR TYPE MATNR,
BWTAR TYPE BWTAR_D,
WERK TYPE WERKS_D,
LGORT TYPE LGORT_D,
CHARG TYPE CHARG_D,
SOBKZ TYPE SOBKZ,
LINKK(24) TYPE C,
J_3RFTYPEDOC TYPE C,
BUDAT TYPE BUDAT,
BELEGNR TYPE MBLNR,
MZEILE TYPE MBLPO,
BWART TYPE BWART,
XBELNR TYPE BELNR_D,
BUZEI TYPE BUZEI,
XKTNR(4) TYPE C,
VKNTR(12) TYPE C,
ITEMS(5) TYPE C,
XMEINS TYPE MEINS,
XMENSH_IN TYPE QUAN1_9,
XMENSH_OUT TYPE QUAN1_9,
XDMSHB_IN TYPE SUMM9,
XDMSHB_OUT TYPE SUMM9,
XCHANGPRICE TYPE SUMM9,
XWAERS TYPE WAERS,
XWRBT_IN TYPE SUMM9,
XWRBT_OUT TYPE SUMM9,
BWAERS TYPE WAERS,
HKONT TYPE HKONT,
XBLNR TYPE XBLNR1,
EBELN TYPE EBELN,
RESWK TYPE RESWK,
PSPNR TYPE PS_POSNR,
VBELN TYPE VBELN,
POSNR TYPE POSNR,
VTWEG TYPE VTWEG,
KUNNR_AG(10) TYPE C,
NAME_AG TYPE NAME_AG,
KUNNR_WE(10) TYPE C,
NAME_WE TYPE NAME_WE,
LIFNR TYPE ELIFN,
NAME_LIFNR TYPE NAME1_LF,
MFRNR TYPE MFRNR,
NAME_PRDLIFNR(30) TYPE C,
ROUTE TYPE ROUTE,
COLOR_BANNER TYPE CHAR3,
XBUKRS TYPE BUKRS,
XBWKEY TYPE BWKEY,
XGJAHR TYPE GJAHR,
XHKONT TYPE HKONT,
BVORG TYPE BVORG,
LATER TYPE C,
OVERVALUE TYPE C,
INCLD TYPE C,
DELETED TYPE C,
INVOICE TYPE C,
PRICVAR TYPE C,
NOTRIGHTS TYPE C,
TBLSB(4) TYPE C,
SJAHR TYPE GJAHR,
SMBLN TYPE MBLNR,
SMBLP TYPE MBLPO,
SJHNR TYPE MJAHR,
SBLNR TYPE MBLNR,
SZILE TYPE MBLPO,
NPREI TYPE NPREI,
PEINH TYPE PEINH,
LBKUMCURRENT TYPE LBKUM,
LBKUMCOMMON TYPE LBKUM,
end of J_3RMLISTDOKW,
begin of j_3rmlistmatw,
FIELD_LINK(63) TYPE C,
XMATNR TYPE MATNR,
BWTAR TYPE BWTAR_D,
WERK TYPE WERKS_D,
LGORT TYPE LGORT_D,
CHARG TYPE CHARG_D,
SOBKZ TYPE SOBKZ,
LINKK(24) TYPE C,
MAKTX TYPE MAKTX,
BEGPRICE1 TYPE SUMM9,
WAERS TYPE WAERS,
YMEINS TYPE MEINS,
BEGREMN TYPE QUAN1_9,
ENDREMN TYPE QUAN1_9,
BEGSUM TYPE SUMM9,
ENDSUM TYPE SUMM9,
BKLAS TYPE BKLAS,
XSAKNR TYPE SAKNR,
EKGRP TYPE EKGRP,
MTART TYPE MTART,
MATKL TYPE MATKL,
YBUKRS TYPE BUKRS,
BISMT TYPE BISMT,
DELTLBKUMD TYPE QUAN1_9,
DELTLBKUMK TYPE QUAN1_9,
DELTSALKD TYPE SUMM9,
DELTSALKK TYPE SUMM9,
YCHANGPRICE TYPE SUMM9,
BANNER_DOC TYPE C,
BWKEY TYPE BWKEY,
BWTTY TYPE BWTTY_D,
TBLSB(4) TYPE C,
LASTDATE TYPE DATUM,
VPRSV TYPE VPRSV,
STPRS TYPE STPRS,
BWMOD TYPE BWMOD,
KTOPL TYPE KTOPL,
LBKUM TYPE LBKUM,
PSPNR TYPE PS_PSP_PNR,
VBELN TYPE VBELN,
POSNR TYPE POSNR,
SORTL TYPE PARTID,
NOTRIGHTS TYPE C,
end of j_3rmlistmatw.
TYPES:
BEGIN OF type_hide_field,
xbukrs TYPE bukrs, " CC
xbwkey TYPE bwkey,
xgjahr TYPE gjahr, " document year
xhkont TYPE hkont, " GL account
bvorg TYPE bvorg,
later(1) TYPE c, " this is sign - BUDAT > so_budat-HIGH
overvalue(1) TYPE c, " the document is overvalue
incld(1) TYPE c, " o?uouoyo o?oEy o n?u?y?o y? ?uu?oo
deleted(1) TYPE c,
invoice(1) TYPE c, " the document is invoice
pricvar(1) TYPE c, " price variance
notrights(1) TYPE c, " document permission banner
tblsb TYPE type_tblsb, " valuated type table (MBEW, EBEW, QBEW)
END OF type_hide_field,
BEGIN OF type_bsim_bkpf,
matnr TYPE matnr,
bwkey TYPE bwkey,
bwtar TYPE bwtar_d,
belnr TYPE belnr_d,
gjahr TYPE gjahr,
bukrs TYPE bukrs,
stblg TYPE stblg,
stjah TYPE stjah,
buzei TYPE buzei,
bvorg TYPE bvorg,
menge TYPE menge_d,
shkzg TYPE shkzg,
meins TYPE meins,
dmbtr TYPE dmbtr,
budat TYPE budat,
cpudt TYPE cpudt,
cputm TYPE cputm,
buzid TYPE buzid,
awtyp TYPE awtyp,
blart TYPE blart,
awkey TYPE awkey,
xblnr TYPE xblnr,
waers TYPE waers,
monat TYPE monat,
vbel2 TYPE vbeln_va,
posn2 TYPE posnr_va,
projk TYPE ps_psp_pnr,
awkbl TYPE belnr_d,
awkgj TYPE gjahr,
END OF type_bsim_bkpf,
BEGIN OF type_overval,
field_link TYPE type_link.
INCLUDE TYPE j_3rmlistdok.
INCLUDE TYPE type_hide_field.
TYPES:
sjahr TYPE mjahr, " canceled document year
smbln TYPE mblnr, " canceled document number
sjhnr TYPE mjahr, " canceled doc. year search streeng
sblnr TYPE mblnr, " canceled doc. number search streeng
nprei TYPE nprei, " new price
peinh TYPE peinh, " price unit
lbkumcurrent TYPE type_gazprst,
lbkumcommon TYPE type_gazprst,
lost TYPE type_1c,
END OF type_overval,
type_docmat TYPE j_3rmlistdokw.
TYPES:
type_listmat TYPE j_3rmlistmatw,
tt_listmat TYPE STANDARD TABLE OF type_listmat,
tt_bsim_bkpf TYPE STANDARD TABLE OF type_bsim_bkpf "1247791
WITH NON-UNIQUE KEY bwkey bwtar matnr,
tt_overvalue TYPE SORTED TABLE OF type_overval
WITH NON-UNIQUE KEY
xbukrs xmatnr xhkont bwtar xbwkey "tblsb
budat xbelnr buzei,
tt_docmat TYPE STANDARD TABLE OF type_docmat.
CONSTANTS:
gc_true TYPE type_1c VALUE 'X',
abap_true TYPE abap_bool VALUE 'X',
abap_false TYPE abap_bool VALUE ' '.
DATA:
pt_listmat TYPE STANDARD TABLE OF type_listmat,
lw_listmat TYPE type_listmat,
pt_bsim_bkpf TYPE tt_bsim_bkpf,
lw_bsim_bkpf TYPE type_bsim_bkpf,
ppt_overval TYPE tt_overvalue,
pt_overval TYPE tt_overvalue,
lw_overval TYPE type_overval,
lt_ind1_docover TYPE SORTED TABLE OF type_overval
WITH NON-UNIQUE KEY xbelnr lgort,
lw_ind1_docover TYPE type_overval,
pt_docmat TYPE tt_docmat,
lw_docmat TYPE type_docmat,
lt_ind2_docmat TYPE SORTED TABLE OF type_docmat
WITH NON-UNIQUE KEY xbukrs xbelnr buzei pspnr vbeln posnr,
lw_ind2_docmat TYPE type_docmat,
lw_ind3_docmat TYPE type_docmat,
pp_field_link TYPE type_link,
l_matnr TYPE matnr VALUE '000000000000000001',
l_matnr_c(18) TYPE c,
l_bwtar TYPE bwtar_d VALUE 'ВИД ОЦЕНКИ',
l_werks TYPE werks_d VALUE 'WEKR',
l_lgort TYPE lgort_d,
l_charg TYPE charg_d VALUE 'ВИД ОЦЕНКИ',
l_sobkz TYPE sobkz,
l_sortl TYPE partid,
p_dmbtr TYPE j_3rfinsum,
l_dmbtr TYPE j_3rfinsum,
l_menge TYPE menge_d,
l_bukrs TYPE bukrs VALUE 'RU01',
doc_num(10) TYPE c VALUE '4800000000',
n_day(2) TYPE n,
* c_day(2) TYPE c,
p_percentall TYPE i,
p_percentcur TYPE i,
l_belnr TYPE belnr_d,
l_rec TYPE sytabix,
l_lbkumcur TYPE type_gazprst,
l_lbkumcom TYPE type_gazprst,
lv_lgort_cleared TYPE boole_d,
lv_listmat_sorted TYPE boole_d,
lv_index LIKE sy-tabix,
t_1 TYPE i,
t_2 TYPE i,
g_cycle TYPE i VALUE 1,
l_time TYPE i.
DO 200 TIMES.
l_lgort = sy-index.
CONCATENATE
l_matnr l_bwtar
l_werks l_lgort
l_charg l_sobkz
l_sortl
INTO lw_listmat-field_link.
lw_listmat-xmatnr = l_matnr.
lw_listmat-bwtar = l_bwtar.
lw_listmat-werk = l_werks.
lw_listmat-lgort = l_lgort.
lw_listmat-charg = l_charg.
lw_listmat-waers = 'RUB'.
lw_listmat-ymeins = 'TO'.
lw_listmat-bwkey = l_werks.
lw_listmat-tblsb = 'MBEW'.
lw_listmat-endremn = sy-tabix + 100 / sy-tabix.
APPEND lw_listmat TO pt_listmat.
ENDDO.
CLEAR p_percentcur.
DO 500 TIMES.
ADD 1 TO p_percentcur.
lw_bsim_bkpf-matnr = l_matnr.
lw_bsim_bkpf-bwkey = l_werks.
lw_bsim_bkpf-bwtar = l_bwtar.
doc_num = doc_num + 1.
lw_bsim_bkpf-belnr = doc_num.
lw_bsim_bkpf-gjahr = 2011.
lw_bsim_bkpf-bukrs = l_bukrs.
lw_bsim_bkpf-buzei = 1.
lw_bsim_bkpf-menge = sy-tabix + 100 / sy-tabix.
lw_bsim_bkpf-shkzg = 'H'.
lw_bsim_bkpf-meins = 'TO'.
lw_bsim_bkpf-dmbtr = sy-index / sy-tabix * 1000.
n_day = ( ( p_percentcur * 31 / 500 ) / 10 ) * 10.
IF n_day = 0.
n_day = n_day + 1.
CONCATENATE '201108' n_day INTO lw_bsim_bkpf-budat.
ELSE.
CONCATENATE '201108' n_day INTO lw_bsim_bkpf-budat.
ENDIF.
lw_bsim_bkpf-cputm = sy-timlo.
lw_bsim_bkpf-buzid = 'M'.
lw_bsim_bkpf-blart = 'PR'.
CONCATENATE lw_bsim_bkpf-belnr lw_bsim_bkpf-gjahr INTO lw_bsim_bkpf-awkey.
lw_bsim_bkpf-waers = 'RUB'.
lw_bsim_bkpf-monat = sy-datum+4(2).
APPEND lw_bsim_bkpf TO pt_bsim_bkpf.
ENDDO.
doc_num = '5000000000'.
CLEAR p_percentcur.
DO 50 TIMES.
ADD 1 TO p_percentcur.
CLEAR lw_docmat.
lw_docmat-later = gc_true.
lw_docmat-xbukrs = l_bukrs.
lw_docmat-xmatnr = l_matnr.
lw_docmat-werk = l_werks.
l_lgort = sy-index.
lw_docmat-lgort = l_lgort.
lw_docmat-charg = l_charg.
lw_docmat-tblsb = 'MBEW'.
* lw_docmat-sobkz = pw_mseg_mkpf-sobkz.
* lw_docmat-budat = pw_mseg_mkpf-budat.
n_day = ( ( p_percentcur * 31 / 50 ) / 10 ) * 10.
IF n_day = 0.
n_day = n_day + 1.
CONCATENATE '201108' n_day INTO lw_docmat-budat.
ELSE.
CONCATENATE '201108' n_day INTO lw_docmat-budat.
ENDIF.
doc_num = doc_num + 1.
lw_docmat-belegnr = 100 + doc_num.
lw_docmat-xgjahr = 2011.
lw_docmat-mzeile = 1.
* lw_docmat-xgjahr = pw_bsim_bkpf-gjahr.
* lw_docmat-belegnr = pw_mseg_mkpf-mblnr. " material document number
* lw_docmat-mzeile = pw_mseg_mkpf-zeile. " material document item
* lw_docmat-sjahr = pw_mseg_mkpf-sjahr. " erased document year
* lw_docmat-smbln = pw_mseg_mkpf-smbln. " erased document number
* lw_docmat-smblp = pw_mseg_mkpf-smblp. " erased document item
* lw_docmat-sjhnr = pw_mseg_mkpf-mjahr. " material document year
lw_docmat-sblnr = 100 + doc_num.
* lw_docmat-szile = pw_mseg_mkpf-zeile. " material document item
* Movement Type (Inventory Management)
lw_docmat-bwart = 'ZZZ'.
lw_docmat-bwtar = l_bwtar. " Valuation Type
* lw_docmat-xblnr = pw_bsim_bkpf-xblnr. " Reference Document Number
lw_docmat-xbelnr = doc_num.
lw_docmat-buzei = 1.
lw_docmat-xhkont = '1000000000'.
* lw_docmat-xktnr = p_xktid.
* lw_docmat-vkntr = p_xktnr.
* lw_docmat-items = p_xitem.
lw_docmat-xmeins = 'TO'.
lw_docmat-bwaers = 'RUB'.
lw_docmat-xwaers = 'RUB'.
* lw_docmat-bvorg = pw_bsim_bkpf-bvorg.
* lw_docmat-pspnr = pw_mseg_mkpf-ps_psp_pnr.
lw_docmat-j_3rftypedoc = 'U'.
lw_docmat-xmensh_in = sy-tabix + 100 / sy-tabix.
lw_docmat-xdmshb_in = sy-index / sy-tabix * 1000.
l_matnr_c = l_matnr.
WRITE l_matnr_c TO l_matnr RIGHT-JUSTIFIED.
CONCATENATE
l_matnr l_bwtar
l_werks l_lgort
l_charg l_sobkz
l_sortl
INTO lw_docmat-field_link.
* lw_docmat-incld = p_incld.
APPEND lw_docmat TO pt_docmat.
ENDDO.
LOOP AT pt_listmat INTO lw_listmat.
LOOP AT pt_bsim_bkpf INTO lw_bsim_bkpf
WHERE bwkey = lw_listmat-bwkey
AND bwtar = lw_listmat-bwtar
AND matnr = lw_listmat-xmatnr.
lw_overval-xmeins = lw_listmat-ymeins.
lw_overval-xbukrs = lw_listmat-ybukrs.
lw_overval-xmatnr = lw_listmat-xmatnr.
lw_overval-xgjahr = lw_bsim_bkpf-gjahr.
lw_overval-xbelnr = lw_bsim_bkpf-belnr.
lw_overval-sjhnr = lw_bsim_bkpf-gjahr.
lw_overval-sblnr = lw_bsim_bkpf-belnr.
lw_overval-sjahr = lw_bsim_bkpf-stjah.
lw_overval-smbln = lw_bsim_bkpf-stblg.
lw_overval-werk = lw_listmat-werk.
lw_overval-lgort = lw_listmat-lgort.
lw_overval-charg = lw_listmat-charg.
lw_overval-sobkz = lw_listmat-sobkz.
lw_overval-tblsb = lw_listmat-tblsb.
lw_overval-budat = lw_bsim_bkpf-budat.
lw_overval-bwtar = lw_listmat-bwtar.
lw_overval-xbwkey = lw_listmat-bwkey.
lw_overval-bwaers = lw_bsim_bkpf-waers.
lw_overval-xwaers = lw_listmat-waers.
lw_overval-overvalue = gc_true.
* lw_overval-nprei = pw_bseg-nprei.
* lw_overval-peinh = pw_bseg-peinh.
lw_overval-hkont = '1000000000'.
lw_overval-tblsb = 'MBEW'.
* lw_overval-invoice = p_invoice.
* lw_overval-pricvar = p_pricvar.
lw_overval-bvorg = lw_bsim_bkpf-bvorg.
lw_overval-buzei = lw_bsim_bkpf-buzei.
lw_overval-j_3rftypedoc = 'U'.
* lw_overval-pspnr = p_pspnr.
* lw_overval-vbeln = p_vbeln.
* lw_overval-posnr = p_posnr.
* lw_overval-lost = p_lost.
* lw_overval-notrights = lw_listmat-notrights.
p_dmbtr = lw_overval-xdmshb_out = - lw_bsim_bkpf-dmbtr.
lw_overval-xwrbt_out = - lw_bsim_bkpf-dmbtr.
l_matnr_c = l_matnr.
WRITE l_matnr_c TO l_matnr RIGHT-JUSTIFIED.
CONCATENATE
l_matnr l_bwtar
l_werks l_lgort
l_charg l_sobkz
l_sortl
INTO lw_overval-field_link.
INSERT lw_overval INTO TABLE pt_overval.
ENDLOOP.
ENDLOOP.
*************************************************************
GET RUN TIME FIELD t_1.
FIELD-SYMBOLS: <fs_over> TYPE type_overval,
<fs_over_2> TYPE type_overval, "1557283
<fs_listmat> TYPE type_listmat.
LOOP AT pt_listmat ASSIGNING <fs_listmat>.
<fs_listmat>-begremn = <fs_listmat>-begremn + <fs_listmat>-lbkum.
<fs_listmat>-endremn = <fs_listmat>-endremn + <fs_listmat>-lbkum.
ENDLOOP.
*describe table pt_overval lines l_prcntall.
*if l_prcntall is initial.
* exit.
*endif.
SORT pt_docmat STABLE BY xmatnr bwtar werk "1557283
tblsb pspnr vbeln posnr budat.
SORT pt_listmat BY xmatnr bwtar werk "1557283
tblsb pspnr vbeln posnr sortl lgort charg sobkz.
* calc material quantity in each storage for division
* cost document overvalue
LOOP AT pt_overval ASSIGNING <fs_over>.
ADD 1 TO p_percentcur.
* l_rec = sy-tabix.
* if document is overvalue
* if <fs_over>-invoice is initial.
l_belnr = <fs_over>-bvorg(10).
IF NOT l_belnr IS INITIAL
AND l_belnr NE <fs_over>-xbelnr.
CONTINUE.
ENDIF.
PERFORM calc_quantity_date
USING <fs_over>
pt_listmat[] "1557283
pt_docmat[] "1557283
'20110831'
CHANGING
<fs_over>-lbkumcommon
<fs_over>-lbkumcurrent.
CLEAR l_dmbtr.
* if document is invoice
* else.
* move: 1 to <fs_over>-lbkumcommon,
* 1 to <fs_over>-lbkumcurrent.
* endif.
IF <fs_over>-lbkumcommon NE 0.
IF <fs_over>-xdmshb_in NE 0.
l_dmbtr = <fs_over>-xdmshb_in
* <fs_over>-lbkumcurrent
/ <fs_over>-lbkumcommon.
<fs_over>-xdmshb_in = l_dmbtr.
ELSE.
l_dmbtr = <fs_over>-xdmshb_out
* <fs_over>-lbkumcurrent
/ <fs_over>-lbkumcommon.
<fs_over>-xdmshb_out = l_dmbtr.
ENDIF.
ENDIF.
IF NOT l_dmbtr IS INITIAL.
CLEAR: lw_docmat. "1557283
MOVE-CORRESPONDING <fs_over> TO lw_docmat. "#EC ENHOK
INSERT lw_docmat INTO TABLE pt_docmat. "1557283
ENDIF.
ENDLOOP.
* fill index table
lt_ind1_docover[] = pt_overval[].
* fill amount in bind document from document overvalue
LOOP AT pt_overval ASSIGNING <fs_over_2> "1557283
WHERE invoice IS INITIAL
AND NOT bvorg IS INITIAL.
ADD 1 TO p_percentcur.
l_rec = sy-tabix.
l_belnr = <fs_over_2>-bvorg(10). "1557283
IF l_belnr IS INITIAL OR
l_belnr EQ <fs_over_2>-xbelnr. "1557283
CONTINUE.
ELSE.
l_lgort = <fs_over_2>-lgort. "1557283
CLEAR: l_lbkumcom, l_lbkumcur.
READ TABLE lt_ind1_docover INTO lw_ind1_docover
WITH KEY xbelnr = l_belnr
lgort = l_lgort
BINARY SEARCH.
IF sy-subrc IS INITIAL.
l_lbkumcur = lw_ind1_docover-lbkumcurrent.
l_lbkumcom = lw_ind1_docover-lbkumcommon.
ELSE.
* a document was post before date begin the report
READ TABLE pt_overval INDEX l_rec ASSIGNING <fs_over>.
PERFORM calc_quantity_date
USING <fs_over>
pt_listmat[] "1557283
pt_docmat[] "1557283
'20110831'
CHANGING
l_lbkumcom l_lbkumcur.
ENDIF.
ENDIF.
READ TABLE pt_overval INDEX l_rec ASSIGNING <fs_over>.
CHECK sy-subrc IS INITIAL.
CLEAR l_dmbtr.
<fs_over>-lbkumcurrent = l_lbkumcur.
<fs_over>-lbkumcommon = l_lbkumcom.
IF <fs_over>-lbkumcommon NE 0.
* l_rec1 = sy-tabix.
IF <fs_over>-xdmshb_in NE 0.
l_dmbtr = <fs_over>-xdmshb_in
* <fs_over>-lbkumcurrent
/ <fs_over>-lbkumcommon.
<fs_over>-xdmshb_in = l_dmbtr.
ELSE.
l_dmbtr = <fs_over>-xdmshb_out
* <fs_over>-lbkumcurrent
/ <fs_over>-lbkumcommon.
<fs_over>-xdmshb_out = l_dmbtr.
ENDIF.
ENDIF.
IF NOT l_dmbtr IS INITIAL.
CLEAR: lw_docmat. "1557283
MOVE-CORRESPONDING <fs_over> TO lw_docmat. "#EC ENHOK
INSERT lw_docmat INTO TABLE pt_docmat. "1557283
ENDIF.
ENDLOOP.
* free work memory
REFRESH: lt_ind1_docover. "1557283
FREE lt_ind1_docover.
* fill index table
lt_ind2_docmat[] = pt_docmat[].
LOOP AT pt_overval ASSIGNING <fs_over>.
IF <fs_over>-lost IS INITIAL.
READ TABLE lt_ind2_docmat TRANSPORTING NO FIELDS
WITH KEY xbukrs = <fs_over>-xbukrs
xbelnr = <fs_over>-xbelnr
buzei = <fs_over>-buzei
pspnr = <fs_over>-pspnr
vbeln = <fs_over>-vbeln
posnr = <fs_over>-posnr
BINARY SEARCH.
ELSE.
READ TABLE lt_ind2_docmat TRANSPORTING NO FIELDS
WITH KEY xbukrs = <fs_over>-xbukrs
xbelnr = <fs_over>-xbelnr
buzei = <fs_over>-buzei
hkont = <fs_over>-hkont.
ENDIF.
CHECK NOT sy-subrc IS INITIAL.
CLEAR: l_lgort, lv_lgort_cleared, lv_index. "1557283 start
* for overvalue document warehouse definition
READ TABLE pt_docmat WITH KEY xmatnr = <fs_over>-xmatnr
bwtar = <fs_over>-bwtar werk = <fs_over>-werk
BINARY SEARCH TRANSPORTING NO FIELDS.
lv_index = sy-tabix.
LOOP AT pt_docmat INTO lw_ind3_docmat
FROM lv_index
WHERE xmatnr = <fs_over>-xmatnr
AND bwtar = <fs_over>-bwtar
AND werk = <fs_over>-werk. "1557283 end
CHECK lw_ind3_docmat-lgort = <fs_over>-lgort
AND lw_ind3_docmat-charg = <fs_over>-charg.
l_lgort = <fs_over>-lgort.
CHECK lw_ind3_docmat-budat <= <fs_over>-budat.
l_lgort = lw_ind3_docmat-lgort.
CLEAR: lw_docmat, lw_ind2_docmat. "1557283
MOVE-CORRESPONDING <fs_over> TO lw_docmat. "#EC ENHOK
MOVE-CORRESPONDING <fs_over> TO lw_ind2_docmat. "#EC ENHOK
lw_docmat-lgort = l_lgort.
lw_ind2_docmat-lgort = l_lgort.
INSERT lw_docmat INTO TABLE pt_docmat. "1557283
INSERT lw_ind2_docmat INTO TABLE lt_ind2_docmat.
CLEAR l_lgort.
lv_lgort_cleared = abap_true. "1506298
EXIT.
ENDLOOP.
IF NOT l_lgort IS INITIAL.
CLEAR: lw_docmat, lw_ind2_docmat. "1557283
MOVE-CORRESPONDING <fs_over> TO lw_docmat. "#EC ENHOK
MOVE-CORRESPONDING <fs_over> TO lw_ind2_docmat. "#EC ENHOK
lw_docmat-lgort = l_lgort.
lw_ind2_docmat-lgort = l_lgort.
INSERT lw_docmat INTO TABLE pt_docmat. "1557283
INSERT lw_ind2_docmat INTO TABLE lt_ind2_docmat.
ELSEIF lv_lgort_cleared = abap_false. "1506298 start
* search for matching listmat entry
IF lv_listmat_sorted = abap_false.
SORT pt_listmat BY field_link.
lv_listmat_sorted = abap_true.
ENDIF.
READ TABLE pt_listmat ASSIGNING <fs_listmat>
WITH KEY field_link = <fs_over>-field_link
BINARY SEARCH.
IF sy-subrc IS INITIAL.
l_lgort = <fs_listmat>-lgort.
<fs_listmat>-banner_doc = gc_true.
CLEAR: lw_docmat, lw_ind2_docmat. "1557283
MOVE-CORRESPONDING <fs_over> TO lw_docmat. "#EC ENHOK
MOVE-CORRESPONDING <fs_over> TO lw_ind2_docmat. "#EC ENHOK
lw_docmat-lgort = l_lgort.
lw_ind2_docmat-lgort = l_lgort.
INSERT lw_docmat INTO TABLE pt_docmat. "1557283
INSERT lw_ind2_docmat INTO TABLE lt_ind2_docmat.
ENDIF. "1506298 end
ENDIF.
ENDLOOP.
GET RUN TIME FIELD t_2.
IF t_1 > t_2.
l_time = 2147483647 - t_1 + t_2.
ADD 1 TO g_cycle.
ELSE.
l_time = t_2 - t_1.
ENDIF.
WRITE: / g_cycle, ':', l_time.
*&---------------------------------------------------------------------*
*& Form calc_quantity_date
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->PW_OVER text
* -->PT_IND1_LISTMAT text
* -->PT_IND7_DOCMAT text
* -->PSO_BUDAT_HIGH text
* -->P_LBKUMCOM text
* -->P_LBKUMCUR text
*----------------------------------------------------------------------*
FORM calc_quantity_date
USING pw_over TYPE type_overval
pt_ind1_listmat TYPE tt_listmat "1557283
pt_ind7_docmat TYPE tt_docmat "1557283
pso_budat_high TYPE budat
CHANGING p_lbkumcom TYPE type_gazprst
p_lbkumcur TYPE type_gazprst.
DATA:
lv_index LIKE sy-tabix, "1557283
l_dmbtr TYPE type_gazprst. "1170655
FIELD-SYMBOLS: "1259372
<fs_ind1_listmat> TYPE type_listmat, "1259372
<fs_ind7_docmat> TYPE type_docmat. "1259372
READ TABLE pt_ind1_listmat WITH KEY xmatnr = pw_over-xmatnr "1557283 start
bwtar = pw_over-bwtar werk = pw_over-werk
BINARY SEARCH TRANSPORTING NO FIELDS.
lv_index = sy-tabix.
* two similar blocks below with different loop conditions only "1604108 start
* (for performance reasons)
IF pw_over-lost IS INITIAL.
LOOP AT pt_ind1_listmat ASSIGNING <fs_ind1_listmat> "1259372
FROM lv_index "1557283 end
WHERE xmatnr = pw_over-xmatnr
AND bwtar = pw_over-bwtar
AND werk = pw_over-werk
AND tblsb = pw_over-tblsb
AND pspnr = pw_over-pspnr
AND vbeln = pw_over-vbeln
AND posnr = pw_over-posnr
AND linkk = pw_over-linkk. "1397170
IF <fs_ind1_listmat>-lgort = pw_over-lgort
AND <fs_ind1_listmat>-charg = pw_over-charg
AND <fs_ind1_listmat>-sobkz = pw_over-sobkz.
* calc quantity in current storage on date end period
ADD <fs_ind1_listmat>-endremn TO p_lbkumcur.
ENDIF.
* calc quantity in current plant on date end period
ADD <fs_ind1_listmat>-endremn TO p_lbkumcom.
ENDLOOP.
ELSE.
LOOP AT pt_ind1_listmat ASSIGNING <fs_ind1_listmat>
FROM lv_index
WHERE xmatnr = pw_over-xmatnr
AND bwtar = pw_over-bwtar
AND werk = pw_over-werk
AND xsaknr = pw_over-hkont.
IF <fs_ind1_listmat>-lgort = pw_over-lgort
AND <fs_ind1_listmat>-charg = pw_over-charg
AND <fs_ind1_listmat>-sobkz = pw_over-sobkz.
* calc quantity in current storage on date end period
ADD <fs_ind1_listmat>-endremn TO p_lbkumcur.
ENDIF.
* calc quantity in current plant on date end period
ADD <fs_ind1_listmat>-endremn TO p_lbkumcom.
ENDLOOP.
ENDIF. "1604108 end
* the table key is: xmatnr bwtar werk tblsb pspnr vbeln posnr
READ TABLE pt_ind7_docmat WITH KEY xmatnr = pw_over-xmatnr "1557283 start
bwtar = pw_over-bwtar werk = pw_over-werk
BINARY SEARCH TRANSPORTING NO FIELDS.
lv_index = sy-tabix.
* two similar blocks below with different loop conditions only "1604108 start
* (for performance reasons)
IF pw_over-lost IS INITIAL.
LOOP AT pt_ind7_docmat ASSIGNING <fs_ind7_docmat> "1259372
FROM lv_index "1557283 end
WHERE xmatnr = pw_over-xmatnr
AND bwtar = pw_over-bwtar
AND werk = pw_over-werk
AND tblsb = pw_over-tblsb
AND pspnr = pw_over-pspnr
AND vbeln = pw_over-vbeln
AND posnr = pw_over-posnr
AND budat > pw_over-budat "1506298
AND budat <= pso_budat_high
AND linkk = pw_over-linkk. "1397170
* calc quantity in storage and in plant for date overvalue
IF <fs_ind7_docmat>-lgort EQ pw_over-lgort
AND <fs_ind7_docmat>-charg EQ pw_over-charg
AND <fs_ind7_docmat>-sobkz EQ pw_over-sobkz.
IF <fs_ind7_docmat>-xmensh_in IS INITIAL.
l_dmbtr = ABS( <fs_ind7_docmat>-xmensh_out ).
ADD l_dmbtr TO p_lbkumcur.
ADD l_dmbtr TO p_lbkumcom.
ELSE.
SUBTRACT <fs_ind7_docmat>-xmensh_in
FROM p_lbkumcur.
SUBTRACT <fs_ind7_docmat>-xmensh_in
FROM p_lbkumcom.
ENDIF.
ELSE.
IF <fs_ind7_docmat>-xmensh_in IS INITIAL.
l_dmbtr = ABS( <fs_ind7_docmat>-xmensh_out ).
ADD l_dmbtr TO p_lbkumcom.
ELSE.
SUBTRACT <fs_ind7_docmat>-xmensh_in
FROM p_lbkumcom.
ENDIF.
ENDIF.
ENDLOOP.
ELSE.
LOOP AT pt_ind7_docmat ASSIGNING <fs_ind7_docmat>
FROM lv_index
WHERE xmatnr = pw_over-xmatnr
AND bwtar = pw_over-bwtar
AND werk = pw_over-werk
AND budat > pw_over-budat
AND budat <= pso_budat_high
AND hkont = pw_over-hkont.
* quantity in storage and in plant for date overvalue
IF <fs_ind7_docmat>-lgort EQ pw_over-lgort
AND <fs_ind7_docmat>-charg EQ pw_over-charg
AND <fs_ind7_docmat>-sobkz EQ pw_over-sobkz.
IF <fs_ind7_docmat>-xmensh_in IS INITIAL.
l_dmbtr = ABS( <fs_ind7_docmat>-xmensh_out ).
ADD l_dmbtr TO p_lbkumcur.
ADD l_dmbtr TO p_lbkumcom.
ELSE.
SUBTRACT <fs_ind7_docmat>-xmensh_in
FROM p_lbkumcur.
SUBTRACT <fs_ind7_docmat>-xmensh_in
FROM p_lbkumcom.
ENDIF.
ELSE.
IF <fs_ind7_docmat>-xmensh_in IS INITIAL.
l_dmbtr = ABS( <fs_ind7_docmat>-xmensh_out ).
ADD l_dmbtr TO p_lbkumcom.
ELSE.
SUBTRACT <fs_ind7_docmat>-xmensh_in
FROM p_lbkumcom.
ENDIF.
ENDIF.
ENDLOOP.
ENDIF. "1604108 end
ENDFORM. " calc_quantity_date
Чистоту кода просьба не комментировать, т.к. сам не АБАПер.