Skip to Content
author's profile photo Former Member
Former Member

please help me in this urgent (perfromance Tuning)

hi ,

it is taking total time 30 min to excute, but it has to be run for 5 min.

i have 2 lkh records in BSEG and 60000 in Bkpf, i am giving the code below ,

REPORT zgbf_vat_report

NO STANDARD PAGE HEADING

MESSAGE-ID zit.

************************************************************************

  • Program : ZGBF_VAT_REPORT

*eject

*----


  • TYPE-POOLS DEFINATION

*----


TYPE-POOLS: slis. " ALV Global types

*eject

*----


  • TYPE DEFINATION

*----


  • Structure the declare Document number tables.

TYPES : BEGIN OF ty_bkpf ,

bukrs TYPE bukrs , "Company Code

belnr TYPE belnr_d , "Document number

gjahr TYPE gjahr , "Fiscal Year

budat TYPE budat , "Posting date

monat TYPE monat , "Posting period

waers TYPE waers , "Currency Key

awkey TYPE awkey , "Reference Key

END OF ty_bkpf ,

  • Structure to store controlling area

BEGIN OF ty_tka02 ,

bukrs TYPE bukrs , "Company code

kokrs TYPE kokrs , "Controlling Area

END OF ty_tka02 ,

  • Structure the declare Document number line item tables.

BEGIN OF ty_bseg ,

bukrs TYPE bukrs , "Company Code

belnr TYPE belnr_d , "Document number

gjahr TYPE gjahr , "Fiscal Year

koart TYPE koart , "Account type

shkzg TYPE shkzg , "Debit/Credit Indicator

mwskz TYPE mwskz , "Tax indicator

dmbtr TYPE dmbtr , "Amount in local currency

saknr TYPE saknr , "GL Account

hkont TYPE hkont , "GL Account

prctr TYPE prctr , "Profit Centre

END OF ty_bseg ,

  • Structure to store Calculated total per Line item.

BEGIN OF ty_total ,

hkont TYPE hkont , "GL Account

bukrs TYPE bukrs , "Company Code

belnr TYPE belnr_d , "Document number

monat TYPE monat , "Posting period

gjahr TYPE gjahr , "Fiscal Year

prctr TYPE prctr , "Profit Centre

name TYPE ktext , "Profit Centre name

awkey TYPE awkey , "Reference Key

budat TYPE budat , "Posting date

mwskz TYPE mwskz , "Tax indicator

amt TYPE dmbtr , "Amount

END OF ty_total .

*eject

*----


  • CONSTANT DEFINATION

*----


CONSTANTS : c_a TYPE koart VALUE 'A' , "Account type

c_d TYPE koart VALUE 'D' , "Account type

c_k TYPE koart VALUE 'K' , "Account type

c_m TYPE koart VALUE 'M' , "Account type

c_s TYPE koart VALUE 'S' , "Account type

c_debit TYPE shkzg VALUE 'H' , "Debit Indicator

c_credit TYPE shkzg VALUE 'S' , "Credit Indicator

c_x TYPE char1 VALUE 'X' , "Flag

c_table TYPE slis_tabname

VALUE 'WT_TOTAL', "List Table

*--


ALV Field Catalog Fields--


c_bukrs TYPE slis_fieldname

VALUE 'BUKRS', "Company Code

c_hkont TYPE slis_fieldname

VALUE 'HKONT', "GL Account

c_prctr TYPE slis_fieldname

VALUE 'PRCTR', "Profit Centre

c_name TYPE slis_fieldname

VALUE 'NAME', "Profit Centre Name

c_belnr TYPE slis_fieldname

VALUE 'BELNR', "Document Number

c_awkey TYPE slis_fieldname

VALUE 'AWKEY', "Reference Key

c_budat TYPE slis_fieldname

VALUE 'BUDAT', "Posting Date

c_monat TYPE slis_fieldname

VALUE 'MONAT', "Posting period

c_gjahr TYPE slis_fieldname

VALUE 'GJAHR', "Fiscal Year

c_mwskz TYPE slis_fieldname

VALUE 'MWSKZ', "Tax Code

c_amt TYPE slis_fieldname

VALUE 'AMT' . "Amount

*--


ALV Field Catalog Fields--


*eject

*----


  • DATA DEFINATION

*----


DATA : w_bukrs TYPE t001-bukrs , "Company Code

w_belnr TYPE bkpf-belnr , "Document Number

w_monat TYPE bkpf-monat , "Posting Period

w_budat TYPE bkpf-budat , "Posting Date

w_hkont TYPE bseg-hkont , "GL Account

w_prctr TYPE bseg-prctr , "Profit Centre

w_gjahr TYPE bkpf-gjahr , "Fiscal Year

w_saknr TYPE ska1-saknr , "G/L Account

w_debit TYPE dmbtr ,

w_credit TYPE dmbtr ,

w_total TYPE dmbtr ,

w_calcamt TYPE dmbtr ,

w_diff TYPE p DECIMALS 2 VALUE 1.

*eject

*----


  • WORKAREA DEFINATION

*----


DATA : ws_total TYPE ty_total,

ws_total1 TYPE ty_total.

*eject

*----


  • INTERNAL TABLE DEFINATION

*----


  • Internal table to collect document numbers from BKPF.

DATA : wt_bkpf TYPE STANDARD TABLE OF ty_bkpf,

  • Internal table to store Controlling Area.

wt_tka02 TYPE STANDARD TABLE OF ty_tka02,

  • Internal table to collect document numbers line items from BSEG

wt_bseg TYPE STANDARD TABLE OF ty_bseg,

  • Internal table to collect calculated amount for each line item.

wt_total TYPE STANDARD TABLE OF ty_total.

*eject

*----


  • SELECTION SCREEN DEFINATION

*----


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

SELECT-OPTIONS : s_bukrs FOR w_bukrs OBLIGATORY, "Company Code

s_hkont FOR w_hkont OBLIGATORY, "GL Account

s_prctr FOR w_prctr , "Profit Centre

s_belnr FOR w_belnr , "Document Number

s_monat FOR w_monat OBLIGATORY

NO-EXTENSION , "Posting Period

s_gjahr FOR w_gjahr OBLIGATORY, "Fiscal Year

s_budat FOR w_budat , "Posting Date

s_saknr FOR w_saknr OBLIGATORY. "Accounts range

SELECTION-SCREEN END OF BLOCK b1.

*eject

*----


  • FIELD-SYMBOLS

*----


FIELD-SYMBOLS : <fs1> LIKE LINE OF wt_bkpf ,

<fs2> LIKE LINE OF wt_bseg .

*eject

*----


  • AT SELECTION-SCREEN

*----


AT SELECTION-SCREEN.

  • Validate the Company Code entered by the user on the screen.

PERFORM validate_company_code.

  • Validate the General Ledger Account number entered by the user on the

  • screen.

PERFORM validate_general_ledger_acc.

  • Validate the posting period entered by the user on the screen.

PERFORM validate_posting_period.

  • Validate the Profit Centre entered by the user on the screen.

PERFORM validate_profit_centre.

*eject

*----


  • START-OF-SELECTION

*----


START-OF-SELECTION.

  • Collect the documents for the information entered by the user on the

  • screen.

PERFORM collect_document_number.

  • Collect the Line items for Document numbers selected from BKPF.

PERFORM collect_document_line_items.

  • Calculate the amount for each line item.

PERFORM calculate_amount.

*eject

*----


  • END-OF-SELECTION

*----


END-OF-SELECTION.

  • Display all the succesull and error entries on to a list.

PERFORM display_report.

*eject

&----


*& Form validate_company_code

&----


  • Description :

  • Validate the comany code entered by the user on the screen.

----


FORM validate_company_code.

  • Check the Company Code entered by the user on the screen exists in the

  • table T001.

  • Using Select up to 1 rows instead of Select single in order to avoid the

  • Equality check warning in SLIN.

SELECT bukrs

UP TO 1 ROWS

FROM t001

INTO w_bukrs

WHERE bukrs IN s_bukrs.

ENDSELECT.

IF sy-subrc NE 0.

MESSAGE e999 WITH 'Invalid Company Code.Please check the Company Code'(002).

ENDIF.

ENDFORM. " validate_company_code

*eject

&----


*& Form validate_general_ledger_acc

&----


  • Description :

  • Validate the General Ledger Account number entered by the user

  • on the screen.

----


FORM validate_general_ledger_acc.

  • Check the General Ledger Account number entered by the user

  • on the screen exists in the table SKB1 .

  • Using Select up to 1 rows instead of Select single in order to avoid the

  • Equality check warning in SLIN.

SELECT saknr

UP TO 1 ROWS

FROM skb1

INTO w_hkont

WHERE bukrs IN s_bukrs

AND saknr IN s_hkont.

ENDSELECT.

IF sy-subrc NE 0.

MESSAGE e999 WITH 'Invalid VAT G/L Account number'(003).

ENDIF.

  • Check the General Ledger Account number entered by the user

  • on the screen exists in the table SKB1 .

  • Using Select up to 1 rows instead of Select single in order to avoid the

  • Equality check warning in SLIN.

SELECT saknr

UP TO 1 ROWS

FROM skb1

INTO w_saknr

WHERE bukrs IN s_bukrs

AND saknr IN s_saknr.

ENDSELECT.

IF sy-subrc NE 0.

MESSAGE e999 WITH 'Invalid VAT Accounts range'(018).

ENDIF.

ENDFORM. " validate_general_ledger_acc

*eject

&----


*& Form validate_posting_period

&----


  • Description :

  • Validate the posting period entered by the user on the selection

  • screen.

----


FORM validate_posting_period .

  • Check the Low value of the posting period entered by the user.

IF NOT s_monat-low BETWEEN 1 AND 12.

MESSAGE e999 WITH 'Please enter a valid posting period range'(019).

ENDIF.

  • Check the high value of the posting period entered by the user.

IF NOT s_monat-high BETWEEN 1 AND 12.

MESSAGE e999 WITH 'Please enter a valid posting period range'(019).

ENDIF.

ENDFORM. " validate_posting_period

*eject

&----


*& Form validate_profit_centre

&----


  • Description :

  • Validate the Profit Centre entered by the user on the screen.

----


FORM validate_profit_centre .

  • Check the Profit Centre entered by the user on the screen

  • exists in the table CEPC .

SELECT prctr

UP TO 1 ROWS

FROM cepc

INTO w_prctr

WHERE prctr IN s_prctr.

ENDSELECT.

IF sy-subrc NE 0.

MESSAGE e999 WITH 'Invalid Profit Centre.'(004).

ENDIF.

ENDFORM. " validate_profit_centre

*eject

&----


*& Form collect_document_number

&----


  • Description :

  • Collect the document numbers from the table BKPF for the

  • information entered by the user on the screen.

----


FORM collect_document_number.

CLEAR wt_bkpf.

  • Selecting the document numbers.

SELECT bukrs

belnr

gjahr

budat

monat

awkey

FROM bkpf

INTO TABLE wt_bkpf

WHERE bukrs IN s_bukrs

AND belnr IN s_belnr

AND gjahr IN s_gjahr

AND budat IN s_budat

AND monat IN s_monat.

IF NOT wt_bkpf IS INITIAL.

SORT wt_bkpf BY bukrs belnr gjahr.

ELSE.

MESSAGE s999 WITH 'No Documents selected'(005).

LEAVE LIST-PROCESSING.

ENDIF.

  • Populate the controlling area.

SELECT bukrs

kokrs

FROM tka02

INTO TABLE wt_tka02

FOR ALL ENTRIES IN wt_bkpf

WHERE bukrs EQ wt_bkpf-bukrs.

IF sy-subrc EQ 0.

SORT wt_tka02 BY bukrs kokrs.

ENDIF.

ENDFORM. " collect_document_number

*eject

&----


*& Form collect_document_line_items

&----


  • Description :

  • Collect all the Line items for the document number collected

  • from BKPF.

----


FORM collect_document_line_items.

DATA : wtl_tempbseg TYPE STANDARD TABLE OF ty_bseg,

wtl_temp TYPE STANDARD TABLE OF ty_bseg,

ws_bseg type ty_bseg.

ranges : r_belnr for bseg-belnr. "RD1K932061

FIELD-SYMBOLS <lfs2> LIKE LINE OF wt_bseg .

CLEAR wt_bseg.

  • Selecting Line items from BSEG.

SELECT bukrs

belnr

gjahr

koart

shkzg

mwskz

dmbtr

saknr

hkont

prctr

FROM bseg

INTO TABLE wt_bseg

FOR ALL ENTRIES IN wt_bkpf

WHERE bukrs EQ wt_bkpf-bukrs

AND belnr EQ wt_bkpf-belnr

AND gjahr EQ wt_bkpf-gjahr.

  • { Begin of changes : RD1K927478

  • AND prctr IN s_prctr.

  • } End of changes : RD1K927478

IF sy-subrc NE 0.

MESSAGE s999 WITH 'No data selected'(006).

LEAVE LIST-PROCESSING.

ELSE.

  • Collect only those Document numbers whose Account numbers match with

  • the Account numbers entered by the user on the screen.

  • Step 1.

  • Collect all the document numbers into a Temporary table

*{ Begin of change : RD1K932061

  • APPEND LINES OF wt_bseg TO wtl_tempbseg.

  • Step 2.

  • Search in the parent table whether the GL Account nunbers

  • selected match with the GL Account number entered by the user

  • on the screen.

  • LOOP AT wt_bseg ASSIGNING <fs2> WHERE hkont IN s_hkont.

  • READ TABLE wtl_temp WITH KEY belnr = <fs2>-belnr

  • TRANSPORTING NO FIELDS.

  • IF sy-subrc NE 0.

  • Step3.

  • Collect all the other line items with their respective

  • GL Account numbers for the Document number whose GL Account

  • number matches with the GL Account number entered by the user

  • on the screen.

  • LOOP AT wtl_tempbseg ASSIGNING <lfs2> WHERE belnr EQ <fs2>-belnr.

  • APPEND <lfs2> TO wtl_temp.

  • ENDLOOP.

  • ENDIF.

  • ENDLOOP. "LOOP AT wt_bseg ASSIGNING <fs2>.

  • Collect only those Document numbers whose Account numbers match with

  • the Account numbers entered by the user on the screen.

  • IF NOT wtl_temp IS INITIAL.

LOOP AT wt_bseg into ws_bseg."ASSIGNING <fs2>.

IF ws_bseg-hkont IN s_hkont.

r_belnr-low = ws_bseg-belnr.

r_belnr-sign = 'I'.

r_belnr-option = 'EQ'.

APPEND r_belnr.

ENDIF.

ENDLOOP.

*loop at wt_bseg into ws_bseg where belnr not in r_belnr.

DELETE wt_bseg WHERE belnr NOT IN r_belnr.

  • CLEAR wt_bseg.

  • APPEND LINES OF wtl_temp TO wt_bseg.

*} End of change : RD1K932061

  • Delete entries from the table where Account type is not 'A' or 'M' or 'S'.

DELETE wt_bseg WHERE koart NE c_a

AND koart NE c_d

AND koart NE c_k

AND koart NE c_m

AND koart NE c_s.

IF wt_bseg IS INITIAL.

MESSAGE s999 WITH 'No data selected'(006).

LEAVE LIST-PROCESSING.

ELSE.

SORT wt_bseg BY belnr hkont prctr.

ENDIF.

*{ Begin of change : RD1K932061

  • ELSE.

  • CLEAR wt_bseg.

  • MESSAGE s999 WITH 'No data selected'(006).

  • LEAVE LIST-PROCESSING.

  • ENDIF. "IF NOT wtl_temp IS INITIAL.

*} End of change : RD1K932061

ENDIF. "SY-SUBRC Check on BSEG SELECT

ENDFORM. " collect_document_line_items

*eject

&----


*& Form calculate_amount

&----


  • Description :

  • Calculate the amount for each line item selected in the table

  • wt_bseg based on the Debit/Credit Indicator.

----


FORM calculate_amount .

TYPES : BEGIN OF tyl_prctr ,

bukrs TYPE bukrs ,

prctr TYPE prctr ,

belnr TYPE belnr_d,

gjahr TYPE gjahr ,

hkont TYPE hkont , "AMP30072007

dmbtr TYPE dmbtr ,

END OF tyl_prctr ,

BEGIN OF tyl_docu ,

belnr TYPE belnr_d ,

bukrs TYPE bukrs ,

gjahr TYPE gjahr ,

amt TYPE dmbtr ,

END OF tyl_docu ,

BEGIN OF tyl_hkont ,

hkont TYPE hkont ,

bukrs TYPE bukrs ,

belnr TYPE belnr_d ,

prctr TYPE prctr ,

mwskz TYPE mwskz ,

monat TYPE monat ,

gjahr TYPE gjahr ,

dmbtr TYPE dmbtr ,

END OF tyl_hkont ,

BEGIN OF tyl_prname ,

spras TYPE spras ,

prctr TYPE prctr ,

kokrs TYPE kokrs ,

ktext TYPE ktext ,

END OF tyl_prname .

  • Local Constants

CONSTANTS cl_en TYPE spras VALUE 'E'. "Language Key

  • Local Vairables.

DATA wl_dmbtr TYPE dmbtr .

  • Local work Areas

DATA : wsl_prctr TYPE tyl_prctr ,

wsl_docu TYPE tyl_docu ,

wsl_hkont TYPE tyl_hkont ,

wsl_prname TYPE tyl_prname .

  • Local Internal table

DATA : wtl_temp TYPE STANDARD TABLE OF ty_bseg ,

wtl_temp1 TYPE STANDARD TABLE OF ty_bseg ,

wtl_prctr TYPE STANDARD TABLE OF tyl_prctr,

wtl_docu TYPE STANDARD TABLE OF tyl_docu ,

wtl_hkont TYPE STANDARD TABLE OF tyl_hkont,

wtl_prname TYPE STANDARD TABLE OF tyl_prname,

  • { Begin of changes : RD1K927298

wtl_tempbseg TYPE STANDARD TABLE OF ty_bseg ,

  • } End of changes : RD1K927298

  • { Begin of changes : RD1K928339

wsl_bseg TYPE ty_bseg ,

wsl_tempbseg TYPE ty_bseg .

  • } End of changes : RD1K928339

  • Local field-symbols.

FIELD-SYMBOLS : <lfs1> LIKE LINE OF wtl_temp,

<lfs2> LIKE LINE OF wtl_temp.

  • Collect all the document numbers with Account Type

  • 'A' or 'M' or 'S' in the temp table.

  • { Begin of changes : RD1K927298

  • LOOP AT wt_bseg ASSIGNING <fs2>.

  • IF <fs2>-hkont NOT IN s_saknr.

  • IF <fs2>-koart EQ c_a

  • OR <fs2>-koart EQ c_m

  • OR <fs2>-koart EQ c_s.

  • APPEND <fs2> TO wtl_temp.

  • ENDIF.

  • ELSEIF <fs2>-hkont IN s_saknr.

  • IF <fs2>-koart EQ c_d

  • OR <fs2>-koart EQ c_k

  • OR <fs2>-koart EQ c_s.

  • APPEND <fs2> TO wtl_temp1.

  • ENDIF.

  • ENDIF.

  • ENDLOOP.

  • } End of changes : RD1K927298

  • * Collect all the document numbers with Account Type

  • 'A' or 'M' or 'S' or 'K', OR 'D' in the temp table.

  • { Begin of changes : RD1K927298

LOOP AT wt_bseg ASSIGNING <fs2>.

CASE <fs2>-koart.

WHEN c_a

OR c_m.

APPEND <fs2> TO wtl_temp.

WHEN c_s.

IF <fs2>-hkont NOT IN s_saknr.

APPEND <fs2> TO wtl_temp.

ELSEIF <fs2>-hkont IN s_saknr.

APPEND <fs2> TO wtl_temp1.

ENDIF.

WHEN c_k

OR c_d.

IF <fs2>-hkont IN s_saknr.

APPEND <fs2> TO wtl_temp1.

ENDIF.

ENDCASE.

ENDLOOP.

  • } End of changes : RD1K927298

SORT : wtl_temp BY bukrs belnr gjahr,

wtl_temp1 BY bukrs belnr gjahr.

LOOP AT wtl_temp ASSIGNING <lfs1>.

READ TABLE wtl_temp1 ASSIGNING <lfs2> WITH KEY bukrs = <lfs1>-bukrs

belnr = <lfs1>-belnr

gjahr = <lfs1>-gjahr

BINARY SEARCH.

IF sy-subrc EQ 0.

DELETE wtl_temp1 WHERE bukrs EQ <lfs1>-bukrs

AND belnr EQ <lfs1>-belnr

AND gjahr EQ <lfs1>-gjahr.

ENDIF.

ENDLOOP.

CLEAR : w_debit ,

w_credit .

IF NOT wtl_temp[] IS INITIAL.

  • Get the amounts per Document number.

LOOP AT wtl_temp ASSIGNING <lfs1>.

CASE <lfs1>-shkzg.

WHEN c_debit .

w_debit = w_debit + <lfs1>-dmbtr.

WHEN c_credit.

w_credit = w_credit + <lfs1>-dmbtr.

ENDCASE.

AT END OF belnr.

wsl_docu-amt = w_credit - w_debit.

MOVE : <lfs1>-bukrs TO wsl_docu-bukrs,

<lfs1>-belnr TO wsl_docu-belnr,

<lfs1>-gjahr TO wsl_docu-gjahr.

APPEND wsl_docu TO wtl_docu.

CLEAR : w_debit ,

w_credit ,

wsl_docu .

ENDAT.

ENDLOOP.

  • Get the amounts per profit centre.

CLEAR : w_debit ,

w_credit .

LOOP AT wtl_temp ASSIGNING <lfs1>.

READ TABLE wtl_prctr WITH KEY bukrs = <lfs1>-bukrs

belnr = <lfs1>-belnr

gjahr = <lfs1>-gjahr

prctr = <lfs1>-prctr

hkont = <lfs1>-hkont "AMP31072007

TRANSPORTING NO FIELDS.

IF sy-subrc NE 0.

MOVE : <lfs1>-bukrs TO wsl_prctr-bukrs,

<lfs1>-belnr TO wsl_prctr-belnr,

<lfs1>-gjahr TO wsl_prctr-gjahr,

<lfs1>-prctr TO wsl_prctr-prctr,

<lfs1>-hkont TO wsl_prctr-hkont. "AMP30072007

LOOP AT wt_bseg ASSIGNING <fs2> WHERE bukrs EQ <lfs1>-bukrs

AND belnr EQ <lfs1>-belnr

AND gjahr EQ <lfs1>-gjahr

AND prctr EQ <lfs1>-prctr

AND hkont EQ <lfs1>-hkont. "AMP30072007

CASE <fs2>-shkzg.

WHEN c_debit .

w_debit = w_debit + <fs2>-dmbtr.

WHEN c_credit.

w_credit = w_credit + <fs2>-dmbtr.

ENDCASE.

ENDLOOP.

wsl_prctr-dmbtr = w_credit - w_debit.

APPEND wsl_prctr TO wtl_prctr.

CLEAR : wsl_prctr ,

w_debit ,

w_credit .

ELSE.

CONTINUE.

ENDIF.

ENDLOOP.

SORT : wtl_docu BY bukrs belnr gjahr,

wtl_prctr BY bukrs belnr gjahr prctr.

  • { Begin of changes : RD1K928339

  • { Begin of changes : RD1K927298

  • CLEAR wtl_tempbseg.

  • *

    • APPEND LINES OF wt_bseg TO wtl_tempbseg.

    • { Begin of changes : RD1K927374

    • SORT wtl_tempbseg BY bukrs belnr gjahr shkzg hkont.

    • DELETE ADJACENT DUPLICATES FROM wtl_tempbseg COMPARING shkzg hkont.

  • SORT wtl_tempbseg BY bukrs belnr gjahr hkont.

  • DELETE ADJACENT DUPLICATES FROM wtl_tempbseg COMPARING hkont.

    • } End of changes : RD1K927374

    • } End of changes : RD1K927298

  • } End of chanegs : RD1K928339

    • { Begin of changes : RD1K928339

    CLEAR : wsl_bseg ,

    wsl_tempbseg .

    LOOP AT wt_bseg INTO wsl_bseg WHERE hkont IN s_hkont.

    *{ Begin of change : RD1K932061

    • MOVE-CORRESPONDING wsl_bseg TO wsl_tempbseg.

    • APPEND wsl_tempbseg TO wtl_tempbseg.

    APPEND wsl_bseg TO wtl_tempbseg.

    CLEAR : wsl_bseg .

    • wsl_tempbseg .

    *} End of change : RD1K932061

    ENDLOOP.

    *{ Begin of change : RD1K932061

    • SORT wtl_tempbseg BY bukrs belnr gjahr hkont.

    • DELETE ADJACENT DUPLICATES FROM wtl_tempbseg COMPARING bukrs belnr gjahr hkont.

    *} End of change : RD1K932061

    • } End of changes : RD1K928339

    • Calculate the amount per GL Account Line item for Account type

    • 'A' or 'M' or 'S'.

    • { Begin of changes : RD1K927298

    • LOOP AT wt_bseg ASSIGNING <fs2> WHERE hkont IN s_hkont.

    • LOOP AT wtl_tempbseg ASSIGNING <fs2> WHERE hkont IN s_hkont.

    LOOP AT wtl_tempbseg ASSIGNING <fs2>.

    • } End of changes : RD1K927298

    CLEAR wl_dmbtr.

    IF <fs2>-shkzg EQ c_debit.

    wl_dmbtr = <fs2>-dmbtr * -1.

    ELSE.

    wl_dmbtr = <fs2>-dmbtr.

    ENDIF.

    • Fetch the total amount for the corresponding document number

    • from the temp table of Dcoument Number.

    CLEAR wsl_docu.

    READ TABLE wtl_docu INTO wsl_docu WITH KEY bukrs = <fs2>-bukrs

    belnr = <fs2>-belnr

    gjahr = <fs2>-gjahr

    BINARY SEARCH.

    IF sy-subrc EQ 0.

    • { Begin of changes : RD1K928121

    IF wsl_docu-amt IS INITIAL.

    LOOP AT wt_bseg ASSIGNING <lfs2> WHERE bukrs EQ <fs2>-bukrs

    AND belnr EQ <fs2>-belnr

    AND gjahr EQ <fs2>-gjahr

    AND ( koart EQ c_a

    OR koart EQ c_m

    OR koart EQ c_s )

    AND hkont EQ <fs2>-hkont.

    CLEAR w_calcamt.

    IF <lfs2>-shkzg EQ c_debit.

    w_calcamt = <lfs2>-dmbtr * -1.

    ELSE.

    w_calcamt = <lfs2>-dmbtr.

    ENDIF.

    • Get the header data for the document number.

    READ TABLE wt_bkpf ASSIGNING <fs1> WITH KEY bukrs = <lfs2>-bukrs

    belnr = <lfs2>-belnr

    gjahr = <lfs2>-gjahr

    BINARY SEARCH.

    IF sy-subrc EQ 0.

    MOVE : <lfs2>-hkont TO ws_total-hkont,

    <lfs2>-mwskz TO ws_total-mwskz,

    <lfs2>-prctr TO ws_total-prctr,

    <fs1>-bukrs TO ws_total-bukrs,

    <fs1>-belnr TO ws_total-belnr,

    <fs1>-monat TO ws_total-monat,

    <fs1>-budat TO ws_total-budat,

    <fs1>-gjahr TO ws_total-gjahr,

    <fs1>-awkey TO ws_total-awkey,

    w_calcamt TO ws_total-amt .

    APPEND ws_total TO wt_total.

    CLEAR ws_total.

    ENDIF.

    ENDLOOP.

    ELSE.

    • } End of changes : RD1K928121

    CLEAR wsl_prctr .

    • Fetch the total amount for the corresponding Profit Centre

    • from the temp table of Profit.

    • READ TABLE wtl_prctr INTO wsl_prctr WITH KEY bukrs = <fs2>-bukrs

    • belnr = <fs2>-belnr

    • gjahr = <fs2>-gjahr

    • BINARY SEARCH.

    • IF sy-subrc EQ 0.

    LOOP AT wtl_prctr INTO wsl_prctr WHERE bukrs EQ <fs2>-bukrs

    AND belnr EQ <fs2>-belnr

    AND gjahr EQ <fs2>-gjahr.

    MOVE wsl_prctr-prctr TO ws_total-prctr.

    CLEAR : w_calcamt.

    IF NOT wsl_docu-amt IS INITIAL.

    w_calcamt = ( wsl_prctr-dmbtr / wsl_docu-amt ) * wl_dmbtr.

    • { Begin of changes : RD1K927362

    • ELSE.

    • { Begin of changes : RD1K927354

    • w_calcamt = wl_dmbtr.

    • } End of changes : RD1K927354

    • } End of changes : RD1K927362

    ENDIF.

    • Get the header data for the document number.

    READ TABLE wt_bkpf ASSIGNING <fs1> WITH KEY bukrs = <fs2>-bukrs

    belnr = <fs2>-belnr

    gjahr = <fs2>-gjahr

    BINARY SEARCH.

    IF sy-subrc EQ 0.

    MOVE : <fs2>-hkont TO ws_total-hkont,

    <fs2>-mwskz TO ws_total-mwskz,

    <fs1>-bukrs TO ws_total-bukrs,

    <fs2>-belnr TO ws_total-belnr,

    <fs1>-monat TO ws_total-monat,

    <fs1>-budat TO ws_total-budat,

    <fs1>-gjahr TO ws_total-gjahr,

    <fs1>-awkey TO ws_total-awkey,

    w_calcamt TO ws_total-amt .

    APPEND ws_total TO wt_total.

    CLEAR ws_total.

    ENDIF.

    • ENDIF.

    CLEAR wsl_prctr.

    ENDLOOP.

    ENDIF.

    ENDIF. "if sy-subrc eq 0.

    ENDLOOP.

    • Calculate the reconciliation amount.

    PERFORM reconcile_amount.

    ENDIF. "IF NOT wtl_temp[] IS INITIAL.

    CLEAR : w_debit ,

    w_credit ,

    w_total ,

    w_calcamt .

    • Carrying out the reconciltiation calculation

    IF NOT wtl_temp1 IS INITIAL.

    LOOP AT wtl_temp1 ASSIGNING <lfs1> WHERE hkont IN s_hkont.

    READ TABLE wt_bkpf ASSIGNING <fs1> WITH KEY bukrs = <lfs1>-bukrs

    belnr = <lfs1>-belnr

    gjahr = <lfs1>-gjahr

    BINARY SEARCH.

    IF sy-subrc EQ 0.

    • { Begin of changes : RD1K928075

    • READ TABLE wtl_hkont WITH KEY hkont = <lfs1>-hkont

    • bukrs = <lfs1>-bukrs

    • belnr = <lfs1>-belnr

    • monat = <fs1>-monat

    • gjahr = <fs1>-gjahr

    • TRANSPORTING NO FIELDS.

    • IF sy-subrc NE 0.

    • MOVE : <lfs1>-hkont TO wsl_hkont-hkont,

    • <lfs1>-bukrs TO wsl_hkont-bukrs,

    • <lfs1>-belnr TO wsl_hkont-belnr,

    • <lfs1>-gjahr TO wsl_hkont-gjahr,

    • <lfs1>-mwskz TO wsl_hkont-mwskz,

    • <fs1>-monat TO wsl_hkont-monat,

    • <lfs1>-prctr TO wsl_hkont-prctr.

    • LOOP AT wt_bseg ASSIGNING <fs2> WHERE bukrs EQ <lfs1>-bukrs

    • AND belnr EQ <lfs1>-belnr

    • AND gjahr EQ <lfs1>-gjahr

    • AND hkont EQ <lfs1>-hkont.

    • CASE <fs2>-shkzg.

    • WHEN c_debit .

    • w_debit = w_debit + <fs2>-dmbtr.

    • WHEN c_credit.

    • w_credit = w_credit + <fs2>-dmbtr.

    • ENDCASE.

    • ENDLOOP.

    • w_total = w_credit - w_debit.

    • w_calcamt = w_total - <lfs1>-dmbtr.

    • IF w_calcamt LT w_diff.

    • MOVE <lfs1>-dmbtr TO wsl_hkont-dmbtr.

    • ELSE.

    • MOVE w_total TO wsl_hkont-dmbtr.

    • ENDIF.

    • APPEND wsl_hkont TO wtl_hkont.

    • CLEAR : wsl_hkont,

    • w_debit ,

    • w_credit,

    • w_total .

    • ELSE.

    • CLEAR : wsl_hkont,

    • w_debit ,

    • w_credit,

    • w_total ,

    • w_calcamt.

    • CONTINUE.

    • ENDIF.

    MOVE : <fs1>-bukrs TO ws_total-bukrs,

    <fs1>-belnr TO ws_total-belnr,

    <fs1>-gjahr TO ws_total-gjahr,

    <fs1>-monat TO ws_total-monat,

    <fs1>-awkey TO ws_total-awkey,

    <fs1>-budat TO ws_total-budat,

    <lfs1>-hkont TO ws_total-hkont,

    <lfs1>-mwskz TO ws_total-mwskz,

    <lfs1>-prctr TO ws_total-prctr.

    • Store the amount based on Debit/Credit Indicator.

    IF <lfs1>-shkzg EQ c_debit.

    ws_total-amt = -1 * <lfs1>-dmbtr.

    ELSE.

    ws_total-amt = <lfs1>-dmbtr.

    ENDIF.

    APPEND ws_total TO wt_total.

    • } End of changes : RD1K928075

    ENDIF.

    ENDLOOP.

    • { Begin of changes : RD1K928075

    • LOOP AT wtl_temp1 ASSIGNING <lfs1>.

    • READ TABLE wt_bkpf ASSIGNING <fs1> WITH KEY bukrs = <lfs1>-bukrs

    • belnr = <lfs1>-belnr

    • gjahr = <lfs1>-gjahr

    • BINARY SEARCH.

    • IF sy-subrc EQ 0.

    • MOVE : <fs1>-monat TO ws_total-monat,

    • <fs1>-bukrs TO ws_total-bukrs,

    • <fs1>-belnr TO ws_total-belnr,

    • <fs1>-gjahr TO ws_total-gjahr,

    • <fs1>-awkey TO ws_total-awkey,

    • <fs1>-budat TO ws_total-budat.

    • READ TABLE wtl_hkont INTO wsl_hkont WITH KEY bukrs = <fs1>-bukrs

    • belnr = <fs1>-belnr

    • gjahr = <fs1>-gjahr

    • monat = <fs1>-monat

    • hkont = <lfs1>-hkont.

    • IF sy-subrc EQ 0.

    • MOVE : wsl_hkont-hkont TO ws_total-hkont ,

    • wsl_hkont-dmbtr TO ws_total-amt ,

    • wsl_hkont-prctr TO ws_total-prctr ,

    • wsl_hkont-mwskz TO ws_total-mwskz .

    • APPEND ws_total TO wt_total.

    • CLEAR ws_total.

    • ENDIF.

    • ENDIF.

    • ENDLOOP.

    • } End of changes : RD1K928075

    ENDIF.

    CHECK NOT wt_total IS INITIAL.

    • Get the Profit Centre Name.

    IF NOT wt_tka02 IS INITIAL.

    SELECT spras

    prctr

    kokrs

    ktext

    FROM cepct

    INTO TABLE wtl_prname

    FOR ALL ENTRIES IN wt_tka02

    WHERE spras EQ cl_en

    AND kokrs EQ wt_tka02-kokrs.

    IF sy-subrc EQ 0.

    SORT wtl_prname BY prctr.

    ENDIF.

    ENDIF.

    • Assign the corresponding Profit Centre Name to the Profit Centre

    LOOP AT wt_total INTO ws_total.

    CLEAR wsl_prname.

    READ TABLE wtl_prname INTO wsl_prname WITH KEY prctr = ws_total-prctr

    BINARY SEARCH.

    IF sy-subrc EQ 0.

    MOVE wsl_prname-ktext TO ws_total-name.

    MODIFY wt_total FROM ws_total.

    ENDIF.

    ENDLOOP.

    ENDFORM. " calculate_amount

    *eject

    &----


    *& Form reconcile_amount

    &----


    • text

    ----


    • --> p1 text

    • <-- p2 text

    ----


    FORM reconcile_amount .

    • Carry out the reconciliation calculation.

    SORT wt_total BY hkont bukrs belnr monat gjahr amt.

    CLEAR : w_debit ,

    w_credit ,

    w_total ,

    w_calcamt,

    ws_total1.

    LOOP AT wt_total INTO ws_total.

    • { Begin of changes :RD1K928121

    • { Begin of changes : RD1K927362

  • IF ws_total-amt IS INITIAL.

  • LOOP AT wt_bseg ASSIGNING <fs2> WHERE bukrs EQ ws_total-bukrs

  • AND belnr EQ ws_total-belnr

  • AND gjahr EQ ws_total-gjahr

  • AND ( koart EQ c_a

  • OR koart EQ c_m

    • { Begin of changes : RD1K928075

  • OR koart EQ c_d

  • OR koart EQ c_k

    • } End of changes : RD1K928075

  • OR koart EQ c_s )

  • AND hkont EQ ws_total-hkont.

    • { Begin of changes : RD1K928114

    • AND prctr EQ ws_total-prctr.

    • } End of changes : RD1K928114

  • IF <fs2>-shkzg EQ c_debit.

  • ws_total-amt = <fs2>-dmbtr * -1.

  • ELSE.

  • ws_total-amt = <fs2>-dmbtr.

  • ENDIF.

    • { Begin of changes : RD1K928114

  • ws_total-prctr = <fs2>-prctr.

    • } End of changes : RD1K928114

  • MODIFY wt_total FROM ws_total.

  • ENDLOOP.

  • ELSE.

  • } End of changes : RD1K928121

  • MOVE ws_total TO ws_total1.

    AT END OF gjahr.

    SUM.

    READ TABLE wt_bkpf ASSIGNING <fs1> WITH KEY bukrs = ws_total1-bukrs

    belnr = ws_total1-belnr

    gjahr = ws_total1-gjahr

    monat = ws_total1-monat.

    IF sy-subrc EQ 0.

    LOOP AT wt_bseg ASSIGNING <fs2> WHERE bukrs EQ <fs1>-bukrs

    AND belnr EQ <fs1>-belnr

    AND gjahr EQ <fs1>-gjahr

    AND ( koart EQ c_a

    OR koart EQ c_m

    OR koart EQ c_d

    OR koart EQ c_k

    OR koart EQ c_s )

    AND hkont EQ ws_total1-hkont.

    CASE <fs2>-shkzg.

    WHEN c_debit .

    w_debit = w_debit + <fs2>-dmbtr.

    WHEN c_credit.

    w_credit = w_credit + <fs2>-dmbtr.

    ENDCASE.

    ENDLOOP.

    • Total as per GL Account.

    w_total = w_credit - w_debit.

    CLEAR : w_debit ,

    w_credit .

    w_calcamt = ws_total-amt - w_total.

    IF w_calcamt LT w_total

    AND w_calcamt LT w_diff.

    w_calcamt = ABS( w_calcamt ).

    ws_total1-amt = ws_total1-amt + w_calcamt.

    CLEAR : w_calcamt,

    w_total .

    MODIFY wt_total FROM ws_total1.

    ENDIF.

    ENDIF.

    ENDAT.

    • { Begin of changes : RD1K927362

    • ENDIF.

    • } End of changes : RD1K927362

    CLEAR ws_total1.

    ENDLOOP.

    ENDFORM. " reconcile_amount

    *eject

    &----


    *& Form display_report

    &----


    • Description :

    • Display the list

    ----


    FORM display_report .

    • Macro definition

    DEFINE m_fieldcat.

    ls_fieldcat-fieldname = &1.

    ls_fieldcat-seltext_m = &2.

    ls_fieldcat-tabname = &3.

    ls_fieldcat-outputlen = &4.

    append ls_fieldcat to lt_fieldcat.

    END-OF-DEFINITION.

    DEFINE m_sort.

    ls_sort-fieldname = &1.

    ls_sort-tabname = &2.

    ls_sort-up = c_x.

    append ls_sort to lt_sort.

    END-OF-DEFINITION.

    DATA : ls_fieldcat TYPE slis_fieldcat_alv ,

    lt_fieldcat TYPE slis_t_fieldcat_alv, " Field catalog

    ls_layout TYPE slis_layout_alv ,

    lt_sort TYPE slis_t_sortinfo_alv, " Sort table

    ls_sort LIKE LINE OF lt_sort.

    ls_layout-group_change_edit = c_x.

    ls_layout-colwidth_optimize = c_x.

    ls_layout-zebra = c_x.

    ls_layout-detail_popup = c_x.

    ls_layout-get_selinfos = c_x.

    ls_layout-max_linesize = '250'.

    • Build Fieldcatalog for the report.

    m_fieldcat c_bukrs text-007 c_table '12'.

    m_fieldcat c_hkont text-008 c_table '12'.

    m_fieldcat c_prctr text-009 c_table '13'.

    m_fieldcat c_name text-010 c_table '20'.

    m_fieldcat c_belnr text-011 c_table '19'.

    m_fieldcat c_awkey text-012 c_table '18'.

    m_fieldcat c_budat text-013 c_table '12'.

    m_fieldcat c_monat text-014 c_table '14'.

    m_fieldcat c_gjahr text-015 c_table '11'.

    m_fieldcat c_mwskz text-016 c_table '08'.

    m_fieldcat c_amt text-017 c_table '16'.

    • Build sort table for the report.

    m_sort c_bukrs c_table.

    m_sort c_hkont c_table.

    m_sort c_prctr c_table.

    m_sort c_belnr c_table.

    • DELETE Profit Centre from the output list which are not requested. added on 08/11/2007 by Panky

    DELETE wt_total WHERE prctr NOT IN s_prctr.

    *End of Insert by Panky

    • Calling the Function module to display the list.

    CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

    EXPORTING

    i_callback_program = sy-cprog

    is_layout = ls_layout

    i_default = c_x

    it_fieldcat = lt_fieldcat[]

    it_sort = lt_sort

    TABLES

    t_outtab = wt_total

    EXCEPTIONS

    program_error = 1

    OTHERS = 2.

    IF sy-subrc NE 0.

    ELSE.

    ENDIF.

    ENDFORM. " display_report

    Edited by: Adarsh Priya chary yellenki on Apr 9, 2008 8:55 AM

    Add a comment
    10|10000 characters needed characters exceeded

    Related questions

    3 Answers

    • Posted on Apr 09, 2008 at 08:31 AM

      I will not make a code review, it is anyway quite useless.

      Run the code and do the SQL trace and maybe also the ABAP trace, as explained here. Post the top 5 of the SQL statement summary, complete lines.

      SQL trace:

      /people/siegfried.boes/blog/2007/09/05/the-sql-trace-st05-150-quick-and-easy

      SE30

      /people/siegfried.boes/blog/2007/11/13/the-abap-runtime-trace-se30--quick-and-easy

      Siegfried

      Add a comment
      10|10000 characters needed characters exceeded

    • author's profile photo Former Member
      Former Member
      Posted on Apr 09, 2008 at 09:14 AM

      hi....

      i think u r using many select query stmts in ur code....that is y run time is more....

      i can give a few tips where in u can reduce de exexution time.....i am not sure whether it will be get reduced to 5 mins...but lets try...

      avoid select endselect stmts.....instead of using selectin upto 1 rows.....use select single n avoid de endselect.

      u r using dis at around 4 to 5 places.....

      use read table stmts with binary search after sorting the itab

      i think where max execution time is where u r using select stmts with lots of where condns.....try fetching from de DB with less condns and den filter ur itab contents with de rest of ur condns.

      and also when ur for all entries itab contains lot of records ur select query will still tak lotz of time.wat i can suggest is dis....but u must be very careful here....lotz of testing must be done....

      avoid de for all entries stmt ...fetch ur records from DB without dis stmt and den populate ur int table. after dat loop at dat itab and using read table stmt filter ur int table contents with de for all entries int table....

      make sure de data u get is correct by comparing it with ur current program n de modified ....if at all u r using dis logic....i have tried dis n it has worked for me.....thats y i am suggesting u dis....

      also plz go 2 de debugging moden chk 4 which select query stmt is takiin lotz of time n apply dis logic onli 4 those select stmts ..not for all!!!!

      Reward pts if useful

      Regards

      winnie

      Edited by: Winnie Clarence on Apr 9, 2008 11:16 AM

      Add a comment
      10|10000 characters needed characters exceeded

      • Former Member Former Member

        hi...

        i see dat in dose forms....u r loopin g at the same itab again n again...plz avoid dat by doin it onli once....try twisting de logic a bit....for performance sake

        and also plz avoid loop within a loop.....its dangerous!!!! try using read stmts instead of looping....

        winnie

    • Posted on Apr 10, 2008 at 08:02 AM

      First check the total times in the STAD, statistical records

      Call STAD after 2 executions of your programm, restrict to your user, what is the reponse time, CPU time, DB time?

      Large DB time, go to SQL trace it should always work.

      Large CPU time, go to SE30, read my blog for setting of measurement restictions, increase file size, select 'aggregation by call'

      Siegfried

      Add a comment
      10|10000 characters needed characters exceeded

    Before answering

    You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
    You must be Logged in to submit an answer.

    Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.