Skip to Content
author's profile photo
Former Member

Performanc is very Poor

Hi Experts

This report works fine but its performance is very poor. End users affected badly due to its performance. I have used BSEG table, will it be a reason for this, if so how to handle this situation.

How to improve its performance. Can anyone help me on this.

Thanks in advance.

Regards

Rajaram

&----


*& Report ZPV

&----


REPORT zpv.

&----


  • Data Declarations

&----


TABLES : payr, bkpf,bseg.

DATA : ibseg TYPE TABLE OF bseg WITH HEADER LINE.

DATA : ibsegx TYPE TABLE OF bseg WITH HEADER LINE.

DATA : count TYPE c VALUE 0.

DATA: BEGIN OF item OCCURS 0,

xblnr TYPE bkpf-xblnr, "Reference Document No

budat TYPE bkpf-budat, "Posting Date

gamt TYPE bseg-wrbtr, "Gross Amt

tds TYPE bseg-wrbtr, "TDS

otd TYPE bseg-wrbtr, "Other Deductions

namt TYPE bseg-wrbtr, "Netamount

END OF item.

DATA: BEGIN OF ibsegy OCCURS 0,

dmbtr TYPE bseg-dmbtr,

qbshb TYPE bseg-qbshb,

wskto TYPE bseg-wskto,

nebtr TYPE bseg-nebtr,

END OF ibsegy.

DATA: BEGIN OF ibsegz OCCURS 0,

shkzg TYPE bseg-shkzg,

dmbtr TYPE bseg-dmbtr,

qbshb TYPE bseg-qbshb,

wskto TYPE bseg-wskto,

nebtr TYPE bseg-nebtr,

END OF ibsegz.

DATA: v_banks TYPE bnka-banks,

v_bankl TYPE bnka-bankl,

v_banka TYPE bnka-bankl,

v_ort01 TYPE bnka-brnch,

v_sfname TYPE rs38l_fnam,

v_shkzg TYPE bseg-shkzg,

lv_dmbtr TYPE bseg-dmbtr.

&----


  • Selection-screen

&----


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

PARAMETERS : p_bukrs TYPE payr-zbukr OBLIGATORY DEFAULT '1000',

"Company Code

p_vblnr TYPE payr-vblnr OBLIGATORY, "Voucher No

p_gjahr TYPE payr-gjahr OBLIGATORY memory id GJR.

" DEFAULT sy-datum+0(4)

.

"Fiscal Year

SELECTION-SCREEN END OF BLOCK b1.

&----


  • Start-of-selection

&----


START-OF-SELECTION.

PERFORM retrieve_data.

PERFORM dispaly_smartform.

&----


*& Form Retrieve_data

&----


FORM retrieve_data .

  • Retrieve Payer Details

SELECT SINGLE * FROM payr WHERE zbukr = p_bukrs

AND vblnr = p_vblnr

AND gjahr = p_gjahr

AND voidr = '00'.

  • IF sy-subrc IS NOT INITIAL.

  • SELECT SINGLE * FROM payr WHERE zbukr = p_bukrs

  • AND vblnr = p_vblnr

  • AND gjahr = p_gjahr.

  • ENDIF.

  • For Posting Key 29.

PERFORM item_details_29_25.

  • GET data based on Clearing Documents

                        • IF sy-subrc NE 0. gkb

                        SELECT * FROM bseg

                        INTO TABLE ibseg

                        WHERE augbl = p_vblnr

                        AND bukrs = p_bukrs

                        AND koart = 'K'

                        • AND gjahr = p_gjahr " gkb

                        AND auggj = p_gjahr

                        AND belnr NE p_vblnr.

                        LOOP AT ibseg.

                        • Net Amount

                        • If Amount is Credited

                        IF ibseg-shkzg EQ 'H'.

                        IF ibseg-skfbt IS NOT INITIAL.

                        item-gamt = ibseg-skfbt. "Gross Amt

                        ELSE.

                        item-gamt = ibseg-dmbtr. "Gross Amt gkb

                        ENDIF.

                        item-otd = ibseg-wskto. "Other Deductions

                        • tds

                        SELECT SINGLE dmbtr FROM bseg INTO item-tds

                        WHERE belnr EQ ibseg-belnr

                        AND gjahr EQ ibseg-gjahr

                        AND bukrs EQ ibseg-bukrs

                        AND ktosl EQ 'WIT'.

                        IF sy-subrc NE 0.

                        item-tds = ibseg-qbshb. "TDS

                        ENDIF.

                        • ITEM-NAMT = IBSEG-DMBTR. "Net Amount

                        • if tds is available tds = gross amount - other deductions

                        IF item-otd IS INITIAL.

                        item-namt = ibseg-dmbtr. "Net Amount

                        ELSE.

                        item-namt = item-gamt - item-otd .

                        ENDIF. "if ITEM-OTD is initial.

                            • added by

                            IF item-namt is initial.

                            select single dmbtr from bsak into lv_dmbtr

                            where bukrs = ibseg-bukrs

                            and lifnr = ibseg-lifnr

                            and belnr = ibseg-belnr

                            and gjahr = ibseg-gjahr

                            and blart LIKE 'C%'.

                            lv_dmbtr = lv_dmbtr * -1.

                            MOVE lv_dmbtr to item-namt.

                            ENDIF.

                            • Retrieve Reference Document no and Posting date

                            SELECT SINGLE * FROM bkpf WHERE belnr = ibseg-belnr

                            AND gjahr = ibseg-gjahr.

                            IF sy-subrc IS INITIAL.

                            item-xblnr = bkpf-xblnr. " Refernce Number

                            item-budat = bkpf-budat. "Posting Date

                            ENDIF.

                            • If amount is debited

                            ELSEIF ibseg-shkzg EQ 'S'.

                            • IF Posting equal to 25

                            IF ibseg-bschl EQ '25' .

                            item-gamt = ibseg-dmbtr. "Gross Amt

                            • tds

                            SELECT SINGLE dmbtr FROM bseg INTO item-tds

                            WHERE belnr EQ ibseg-belnr

                            AND gjahr EQ ibseg-gjahr

                            AND bukrs EQ ibseg-bukrs

                            AND ktosl EQ 'WIT'.

                            IF sy-subrc NE 0.

                            item-tds = ibseg-qbshb. "TDS

                            ENDIF.

                            • ITEM-TDS = IBSEG-QBSHB. "TDS

                            item-otd = ibseg-wskto. "Other Deductions

                            • ITEM-NAMT = IBSEG-NEBTR * -1. " Net Amount

                            • if tds Value is vailable

                            IF item-otd IS INITIAL.

                            item-namt = ibseg-nebtr * -1. "Net Amount

                            ELSE.

                            item-namt = item-gamt - item-otd * -1.

                            ENDIF. "if ITEM-OTD is initial.

                            IF item-namt is initial.

                            select single dmbtr from bsak into lv_dmbtr

                            where bukrs = ibseg-bukrs

                            and lifnr = ibseg-lifnr

                            and belnr = ibseg-belnr

                            and gjahr = ibseg-gjahr

                            and blart LIKE 'C%'.

                            lv_dmbtr = lv_dmbtr * -1.

                            MOVE lv_dmbtr to item-namt.

                            ENDIF.

                            • Retrieve Header Details

                            SELECT SINGLE * FROM bkpf WHERE belnr = ibseg-belnr

                            AND gjahr = ibseg-gjahr.

                            IF sy-subrc IS INITIAL.

                            item-xblnr = bkpf-xblnr. " Refernce Number

                            item-budat = bkpf-budat. "Posting Date

                            ENDIF.

                            ****gkb

                            • ELSEIF ibseg-bschl EQ '26'.

                            • CLEAR bseg.

                            • SELECT SINGLE * FROM bseg

                            • WHERE augbl = ibseg-belnr

                            • AND bukrs = p_bukrs

                            • AND gjahr = ibseg-gjahr

                            • AND belnr NE ibseg-belnr.

                            *

                            • item-gamt = bseg-nebtr. "Gross Amt

                            • item-gamt = bseg-dmbtr. "Gross Amt

                          • item-tds = bseg-qbshb. "TDS

                          • item-otd = bseg-wskto. "Other Deductions

                            • item-namt = bseg-nebtr * -1. "Net Amount

                          • item-namt = bseg-dmbtr * -1. "Net Amount

                          • *

                                        • IF bseg-dmbtr EQ bseg-nebtr.

                                        • bseg-nebtr = bseg-dmbtr - bseg-qbshb.

                                        • ENDIF.

                                        *

                                          • if tds is not initial.

                                        • IF item-otd IS INITIAL.

                                          • item-namt = bseg-nebtr * -1. "Net Amount

                                        • item-gamt = bseg-nebtr . "Net Amount

                                        • ELSE.

                                        • item-gamt = item-gamt - item-otd .

                                        • ENDIF. "if ITEM-OTD is initial.

                                        • *

                                          *

                                            • Retrieve Header Details

                                          • SELECT SINGLE * FROM bkpf WHERE belnr = bseg-belnr

                                          • AND gjahr = bseg-gjahr.

                                          • IF sy-subrc IS INITIAL.

                                          • item-xblnr = bkpf-xblnr. " Refernce Number

                                          • item-budat = bkpf-budat. "Posting Date

                                          • ENDIF.

                                          • ****gkb

                                            elseif ibseg-bschl eq '27' .

                                            item-gamt = ibseg-dmbtr. "Gross Amt

                                            • tds

                                            select single dmbtr from bseg into item-tds

                                            where belnr eq ibseg-belnr

                                            and gjahr eq ibseg-gjahr

                                            and bukrs eq ibseg-bukrs

                                            and ktosl eq 'WIT'.

                                            if sy-subrc ne 0.

                                            item-tds = ibseg-qbshb. "TDS

                                            endif.

                                            • ITEM-TDS = IBSEG-QBSHB. "TDS

                                            item-otd = ibseg-wskto. "Other Deductions

                                            • ITEM-NAMT = IBSEG-NEBTR * -1. " Net Amount

                                            • if tds Value is vailable

                                            if item-otd is initial.

                                            item-namt = ibseg-nebtr * -1. "Net Amount

                                            else.

                                            item-namt = item-gamt - item-otd * -1.

                                            endif. "if ITEM-OTD is initial.

                                            if item-namt is initial.

                                            select single dmbtr from bsak into lv_dmbtr

                                            where bukrs = ibseg-bukrs

                                            and lifnr = ibseg-lifnr

                                            and belnr = ibseg-belnr

                                            and gjahr = ibseg-gjahr

                                            and blart like 'C%'.

                                            lv_dmbtr = lv_dmbtr * -1.

                                            move lv_dmbtr to item-namt.

                                            endif.

                                            • Retrieve Header Details

                                            select single * from bkpf where belnr = ibseg-belnr

                                            and gjahr = ibseg-gjahr.

                                            if sy-subrc is initial.

                                            item-xblnr = bkpf-xblnr. " Refernce Number

                                            item-budat = bkpf-budat. "Posting Date

                                            endif.

                                            ELSEIF ibseg-bschl EQ '29' .

                                            item-gamt = ibseg-nebtr. "Gross Amt

                                            • tds

                                            SELECT SINGLE dmbtr FROM bseg INTO item-tds

                                            WHERE belnr EQ ibseg-belnr

                                            AND gjahr EQ ibseg-gjahr

                                            AND bukrs EQ ibseg-bukrs

                                            AND ktosl EQ 'WIT'.

                                            IF sy-subrc NE 0.

                                            item-tds = ibseg-qbshb. "TDS

                                            ENDIF.

                                            • ITEM-TDS = IBSEG-QBSHB. "TDS

                                            item-otd = ibseg-wskto. "Other Deductions

                                            • ITEM-NAMT = IBSEG-NEBTR * -1. " Net Amount

                                            • if tds Value is vailable

                                            IF item-otd IS INITIAL.

                                            item-namt = ibseg-dmbtr * -1. "Net Amount

                                            ELSE.

                                            item-namt = item-gamt - item-otd * -1.

                                            ENDIF. "if ITEM-OTD is initial.

                                            • Retrieve Header Details

                                            SELECT SINGLE * FROM bkpf WHERE belnr = ibseg-belnr

                                            AND gjahr = ibseg-gjahr.

                                            IF sy-subrc IS INITIAL.

                                            item-xblnr = bkpf-xblnr. " Refernce Number

                                            item-budat = bkpf-budat. "Posting Date

                                            ENDIF.

                                            ****gkb

                                            ELSEIF ibseg-bschl EQ '21' .

                                            item-gamt = ibseg-dmbtr. "Gross Amt

                                            • tds

                                            SELECT SINGLE dmbtr FROM bseg INTO item-tds

                                            WHERE belnr EQ ibseg-belnr

                                            AND gjahr EQ ibseg-gjahr

                                            AND bukrs EQ ibseg-bukrs

                                            AND ktosl EQ 'WIT'.

                                            IF sy-subrc NE 0.

                                            item-tds = ibseg-qbshb. "TDS

                                            ENDIF.

                                            • ITEM-TDS = IBSEG-QBSHB. "TDS

                                            item-otd = ibseg-wskto. "Other Deductions

                                            • ITEM-NAMT = IBSEG-NEBTR * -1. " Net Amount

                                            • if tds Value is vailable

                                            IF item-otd IS INITIAL.

                                            item-namt = ibseg-dmbtr * -1. "Net Amount

                                            ELSE.

                                            item-namt = item-gamt - item-otd * -1.

                                            ENDIF. "if ITEM-OTD is initial.

                                            • Retrieve Header Details

                                            SELECT SINGLE * FROM bkpf WHERE belnr = ibseg-belnr

                                            AND gjahr = ibseg-gjahr.

                                            IF sy-subrc IS INITIAL.

                                            item-xblnr = bkpf-xblnr. " Refernce Number

                                            item-budat = bkpf-budat. "Posting Date

                                            ENDIF.

                                            ****gkb

                                            ELSEIF ibseg-bschl EQ '26'.

                                            CLEAR bseg.

                                            SELECT SINGLE * FROM bseg

                                            WHERE augbl = ibseg-belnr

                                            AND bukrs = p_bukrs

                                            AND gjahr = ibseg-gjahr

                                            AND belnr NE ibseg-belnr.

                                            SELECT * FROM bseg

                                            INTO CORRESPONDING FIELDS OF TABLE ibsegz

                                            WHERE augbl = ibseg-belnr

                                            AND bukrs = p_bukrs

                                            AND auggj = ibseg-gjahr

                                            AND belnr NE ibseg-belnr.

                                            LOOP AT ibsegz.

                                            ibsegy-dmbtr = ibsegz-dmbtr .

                                            ibsegy-qbshb = ibsegz-qbshb.

                                            ibsegy-wskto = ibsegz-wskto.

                                            ibsegy-nebtr = ibsegz-nebtr.

                                            COLLECT ibsegy.

                                              • COLLECT ibsegz into ibsegy.

                                              CLEAR : ibsegz.

                                              ENDLOOP.

                                              LOOP AT ibsegy.

                                              item-gamt = ibsegy-dmbtr. "Gross Amt

                                              item-tds = ibsegy-qbshb. "TDS

                                              item-otd = ibsegy-wskto. "Other Deductions

                                              item-namt = ibsegy-nebtr * -1. "Net Amount

                                              IF ibsegy-dmbtr EQ ibsegy-nebtr.

                                              ibsegy-nebtr = ibsegy-dmbtr - ibsegy-qbshb.

                                              ENDIF.

                                              • if tds is not initial.

                                              IF item-otd IS INITIAL.

                                              item-namt = ibsegy-dmbtr * -1. "Net Amount

                                              ELSE.

                                              item-namt = item-gamt - item-otd * -1.

                                              ENDIF. "if ITEM-OTD is initial.

                                              CLEAR: ibsegy.

                                              ENDLOOP.

                                              • Retrieve Header Details

                                              SELECT SINGLE * FROM bkpf WHERE belnr = bseg-belnr

                                              AND gjahr = bseg-gjahr.

                                              IF sy-subrc IS INITIAL.

                                              item-xblnr = bkpf-xblnr. " Refernce Number

                                              item-budat = bkpf-budat. "Posting Date

                                              ENDIF.

                                              REFRESH : ibsegy,

                                              ibsegz.

                                              ****gkb

                                              ELSE.

                                              CLEAR bseg.

                                              SELECT SINGLE * FROM bseg

                                              WHERE augbl = ibseg-belnr

                                              AND bukrs = p_bukrs

                                              AND gjahr = ibseg-gjahr

                                              AND belnr NE ibseg-belnr.

                                              SELECT * FROM bseg

                                              INTO CORRESPONDING FIELDS OF TABLE ibsegz

                                              WHERE augbl = ibseg-belnr

                                              AND bukrs = p_bukrs

                                              AND auggj = ibseg-gjahr

                                              AND belnr NE ibseg-belnr.

                                              LOOP AT ibsegz.

                                              IF ibsegz-shkzg = 'H'.

                                              ibsegy-dmbtr = ibsegz-dmbtr * -1 .

                                              ELSE.

                                              ibsegy-dmbtr = ibsegz-dmbtr .

                                              ENDIF.

                                              ibsegy-qbshb = ibsegz-qbshb.

                                              ibsegy-wskto = ibsegz-wskto.

                                              ibsegy-nebtr = ibsegz-nebtr.

                                              COLLECT ibsegy.

                                              CLEAR : ibsegz.

                                              ENDLOOP.

                                              LOOP AT ibsegy.

                                              item-gamt = ibsegy-dmbtr. "Gross Amt

                                              item-tds = ibsegy-qbshb. "TDS

                                              item-otd = ibsegy-wskto. "Other Deductions

                                                    • item-namt = ibsegy-nebtr * -1. "Net Amount

                                                    IF ibsegy-dmbtr EQ ibsegy-nebtr.

                                                    ibsegy-nebtr = ibsegy-dmbtr - ibsegy-qbshb.

                                                    ENDIF.

                                                    • if tds is not initial.

                                                    IF item-otd IS INITIAL.

                                                      • item-namt = ibsegy-nebtr * -1. "Net Amount

                                                      item-namt = ibsegy-dmbtr * -1. "Net Amount

                                                      ELSE.

                                                      item-namt = item-gamt - item-otd * -1.

                                                      ENDIF. "if ITEM-OTD is initial.

                                                      CLEAR: ibsegy.

                                                      ENDLOOP.

                                                      • Retrieve Header Details

                                                      SELECT SINGLE * FROM bkpf WHERE belnr = bseg-belnr

                                                      AND gjahr = bseg-gjahr.

                                                      IF sy-subrc IS INITIAL.

                                                      item-xblnr = bkpf-xblnr. " Refernce Number

                                                      item-budat = bkpf-budat. "Posting Date

                                                      ENDIF.

                                                      REFRESH : ibsegy,

                                                      ibsegz.

                                                      ENDIF. "IF IBSEG-BSCHL EQ '25'

                                                      ENDIF.

                                                      APPEND item.

                                                      CLEAR item.

                                                      ENDLOOP.

                                                      *****

                                                      IF count = 0.

                                                      SELECT * FROM bseg

                                                      INTO TABLE ibsegx

                                                      WHERE bukrs = p_bukrs

                                                      AND belnr = p_vblnr

                                                      AND gjahr = p_gjahr

                                                      AND bschl = '50'

                                                      AND qsskz NE ' '.

                                                      ENDIF.

                                                      ****

                                                      IF NOT ibsegx[] IS INITIAL.

                                                      LOOP AT ibsegx.

                                                      item-tds = ibsegx-dmbtr. "TDS

                                                      item-namt = ibsegx-dmbtr * -1.

                                                      • Retrieve Header Details

                                                      SELECT SINGLE * FROM bkpf WHERE belnr = ibsegx-belnr

                                                      AND gjahr = ibsegx-gjahr.

                                                      IF sy-subrc IS INITIAL.

                                                      IF NOT bkpf-xblnr IS INITIAL.

                                                      item-xblnr = bkpf-xblnr. " Refernce Number

                                                      ELSE.

                                                      item-xblnr = 'TDS on Payment'.

                                                      ENDIF.

                                                      item-budat = bkpf-budat. "Posting Date

                                                      ENDIF.

                                                      APPEND item.

                                                      CLEAR item.

                                                      ENDLOOP.

                                                      ENDIF.

                                                      ****

                                                                  • ENDIF. gkb

                                                                  • IF item[] IS INITIAL.

                                                                  • RETRIEVE ITEM DETAILS.

                                                                  SELECT * FROM bseg

                                                                  WHERE belnr = p_vblnr

                                                                  AND gjahr = p_gjahr

                                                                  AND koart = 'K'

                                                                  AND bukrs = p_bukrs

                                                                  • AND bschl = '25'.

                                                                  AND bschl IN ('25','38')

                                                                  AND augbl NE p_vblnr.

                                                                  PERFORM get_refdoc.

                                                                  item-xblnr = bkpf-xblnr. " Refernce Number

                                                                  item-budat = bkpf-budat. "Posting Date

                                                                  item-gamt = bseg-dmbtr. "Gross Amt

                                                                  item-tds = bseg-qbshb. "TDS

                                                                  item-otd = bseg-wskto. "Other Deductions

                                                                  • ITEM-NAMT = BSEG-NEBTR. " Net Amount

                                                                  • if tds is not initial

                                                                  IF item-otd IS INITIAL.

                                                                  item-namt = bseg-nebtr. "Net Amount

                                                                  ELSE.

                                                                  item-namt = item-gamt - item-otd.

                                                                  ENDIF. "if ITEM-OTD is initial.

                                                                  COLLECT item.

                                                                  CLEAR item.

                                                                  ENDSELECT.

                                                                  • ENDIF.

                                                                  • IF TDS IS DEDUCTED DURING PAYMENT DOCUMENT CREATION -

                                                                  *if payment document number is posted with 29 posting key then it

                                                                  *should not be added

                                                                  • SELECT SINGLE * FROM bseg

                                                                  • WHERE belnr = p_vblnr

                                                                  • AND bukrs = p_bukrs

                                                                  • AND gjahr = p_gjahr

                                                                  • AND bschl EQ '29'.

                                                                  • IF sy-subrc ne 0.

                                                                  • SELECT SINGLE dmbtr shkzg FROM bseg

                                                                  • INTO (item-tds ,v_shkzg)

                                                                  • WHERE belnr = p_vblnr

                                                                  • AND bukrs = p_bukrs

                                                                  • AND gjahr = p_gjahr

                                                                  • AND ktosl EQ 'WIT'.

                                                                  *

                                                                  • IF sy-subrc IS INITIAL.

                                                                  *

                                                                  • SELECT SINGLE * FROM bkpf WHERE belnr = bseg-belnr

                                                                  • AND gjahr = p_gjahr

                                                                  • AND bukrs = p_bukrs.

                                                                  *

                                                                  • item-xblnr = bkpf-xblnr. " Refernce Number

                                                                  • item-budat = bkpf-budat. "Posting Date

                                                                  • IF v_shkzg EQ 'H'.

                                                                  • item-namt = item-tds * -1. "Net Amount

                                                                  • ELSE.

                                                                  • item-namt = item-tds .

                                                                  • ENDIF.

                                                                  *

                                                                  • APPEND item.

                                                                  • CLEAR item.

                                                                  *

                                                                  • ENDIF.

                                                                  *

                                                                  • ENDIF.

                                                                  ENDFORM. " Retrieve_data

                                                                  &----


                                                                  *& Form Dispaly_Smartform

                                                                  &----


                                                                  FORM dispaly_smartform .

                                                                  • Retrieve Function Module Name

                                                                  CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'

                                                                  EXPORTING

                                                                  formname = 'ZPV'

                                                                  • VARIANT = ' '

                                                                  • DIRECT_CALL = ' '

                                                                  IMPORTING

                                                                  fm_name = v_sfname.

                                                                  • EXCEPTIONS

                                                                  • NO_FORM = 1

                                                                  • NO_FUNCTION_MODULE = 2

                                                                  • OTHERS = 3

                                                                  .

                                                                  IF sy-subrc <> 0.

                                                                  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

                                                                  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

                                                                  ENDIF.

                                                                  • Call Function Module

                                                                  CALL FUNCTION v_sfname

                                                                  EXPORTING

                                                                  • ARCHIVE_INDEX =

                                                                  • ARCHIVE_INDEX_TAB =

                                                                  • ARCHIVE_PARAMETERS =

                                                                  • CONTROL_PARAMETERS =

                                                                  • MAIL_APPL_OBJ =

                                                                  • MAIL_RECIPIENT =

                                                                  • MAIL_SENDER =

                                                                  • OUTPUT_OPTIONS =

                                                                  • USER_SETTINGS = 'X'

                                                                  payr = payr

                                                                  • IMPORTING

                                                                  • DOCUMENT_OUTPUT_INFO =

                                                                  • JOB_OUTPUT_INFO =

                                                                  • JOB_OUTPUT_OPTIONS =

                                                                  TABLES

                                                                  item = item[]

                                                                  • EXCEPTIONS

                                                                  • FORMATTING_ERROR = 1

                                                                  • INTERNAL_ERROR = 2

                                                                  • SEND_ERROR = 3

                                                                  • USER_CANCELED = 4

                                                                  • OTHERS = 5

                                                                  .

                                                                  IF sy-subrc <> 0.

                                                                  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

                                                                  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

                                                                  ENDIF.

                                                                  ENDFORM. " Dispaly_Smartform

                                                                  &----


                                                                  *& Form GET_REFDOC

                                                                  &----


                                                                  FORM get_refdoc .

                                                                  • Retrieve Header Details

                                                                  IF bseg-rebzg IS INITIAL.

                                                                  SELECT SINGLE * FROM bkpf WHERE belnr = bseg-belnr

                                                                  AND gjahr = p_gjahr

                                                                  AND bukrs = p_bukrs.

                                                                  ELSE.

                                                                  SELECT SINGLE * FROM bkpf WHERE belnr = bseg-rebzg

                                                                  AND gjahr = p_gjahr

                                                                  AND bukrs = p_bukrs.

                                                                  ENDIF. "if bseg-bschl eq '29'.

                                                                  ENDFORM. " GET_REFDOC

                                                                  &----


                                                                  *& Form item_details_29_25

                                                                  &----


                                                                  FORM item_details_29_25 .

                                                                  • Retrieve Item Details.

                                                                  SELECT * FROM bseg

                                                                  WHERE belnr = p_vblnr

                                                                  AND gjahr = p_gjahr

                                                                  AND koart = 'K'

                                                                  AND bukrs = p_bukrs

                                                                  AND bschl = '29'.

                                                                  • AND BSCHL IN ('29','25').

                                                                  IF sy-subrc IS INITIAL. " kishore 20.06.2006

                                                                  count = 1.

                                                                  ENDIF.

                                                                  PERFORM get_refdoc.

                                                                  item-xblnr = bkpf-xblnr. " Refernce Number

                                                                  item-budat = bkpf-budat. "Posting Date

                                                                  item-gamt = bseg-dmbtr. "Gross Amt

                                                                  item-otd = bseg-wskto. "Other Deductions

                                                                  item-namt = bseg-nebtr. "Netamount

                                                                  *

                                                                  • IF bseg-augbl IS INITIAL .

                                                                  • IF TDS IS DEDUCTED DURING PAYMENT DOCUMENT CREATION -

                                                                  SELECT SINGLE dmbtr shkzg FROM bseg

                                                                  INTO (item-tds ,v_shkzg)

                                                                  WHERE belnr = p_vblnr

                                                                  AND bukrs = p_bukrs

                                                                  AND gjahr = p_gjahr

                                                                  AND ktosl EQ 'WIT'.

                                                                  IF sy-subrc IS INITIAL.

                                                                  SELECT SINGLE * FROM bkpf WHERE belnr = bseg-belnr

                                                                  AND gjahr = p_gjahr

                                                                  AND bukrs = p_bukrs.

                                                                  IF v_shkzg EQ 'H'.

                                                                  IF bseg-skfbt IS INITIAL.

                                                                  item-namt = item-namt + ( item-tds * -1 ). "Net Amount

                                                                  ENDIF.

                                                                  ELSE.

                                                                  IF bseg-skfbt IS INITIAL.

                                                                  item-namt = item-namt + item-tds.

                                                                  ENDIF.

                                                                  ENDIF.

                                                                  ELSE.

                                                                  item-tds = bseg-qbshb. "TDS

                                                                  ENDIF.

                                                                  • ENDIF. "IF bseg-augbl IS INITIAL AND BSEG-BSCHL EQ '29'.

                                                                  COLLECT item.

                                                                  CLEAR item.

                                                                  ENDSELECT.

                                                                  ENDFORM. " item_details_29_25

                                                                  Add comment
                                                                  10|10000 characters needed characters exceeded

                                                                  • Follow
                                                                  • Get RSS Feed

                                                                  4 Answers

                                                                  • Best Answer
                                                                    author's profile photo
                                                                    Former Member
                                                                    Posted on Sep 28, 2007 at 04:58 AM

                                                                    Hi

                                                                    There are many reasons for bad performance.Use anther work area for your internal table instead of using with header line addition.Its better to declare a types like your internal table structure and use them to create internal table and work area.Dont use select * it will take more time for execution,instaed use select field1 field2.....

                                                                    Reward if useful.

                                                                    Regards

                                                                    Shibin

                                                                    Add comment
                                                                    10|10000 characters needed characters exceeded

                                                                  • author's profile photo
                                                                    Former Member
                                                                    Posted on Sep 28, 2007 at 04:23 AM

                                                                    After having a quick glance at the code, i believe that indeed program must be taking huge execution time.

                                                                    First of all why are you doing SELECT * on BSEG. Please populate only required fields, also check your field sequence specified in ALL SELECT statements. It should be similar to the way they are in table structure.

                                                                    Also try to avoid SELECTs on BSEG / BKPF / BSAK in LOOP ENDLOOP. They will slower the performance.

                                                                    This program really needs to be optimized.

                                                                    Add comment
                                                                    10|10000 characters needed characters exceeded

                                                                  • author's profile photo
                                                                    Former Member
                                                                    Posted on Sep 28, 2007 at 04:33 AM

                                                                    Hi,

                                                                    1. <b>Avoid accessing database inside a Loop</b> (select statements). This will reduce the performance and is not recommended.

                                                                    2. Check if you are using any non-key fields in the Condition clause. If yes, its better to <b>create indexes</b> for the same. 'Coz, fetching the data based on non-key fields will take more time than on key fields or indexes.

                                                                    *Reward pts if helpful!

                                                                    Add comment
                                                                    10|10000 characters needed characters exceeded

                                                                  • Posted on Sep 28, 2007 at 04:39 AM

                                                                    hi Rajaram..

                                                                    Consider the Suggestions from other posts .

                                                                    And additionally:

                                                                    Instead of Accessing from BSEG which is a cluster table , you can access the same data from the Transparent tables

                                                                    BSID

                                                                    BSAD .

                                                                    This can improve the Performance alot.

                                                                    <b>reward if Helpful.</b>

                                                                    Add comment
                                                                    10|10000 characters needed characters exceeded