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

plz help me modifying this code to make is run faster

Former Member
0 Kudos

REPORT ZMS_ACBAL NO STANDARD PAGE HEADING LINE-SIZE 200.

TABLES : LFA1, "Vendor Master (General Section)

BSIK, "Accounting: Secondary Index for Vendors

BKPF, "Accounting Document Header

BSIS, "Accounting: Secondary Index for G/L Accounts

SKAT, "G/L A/c (Chart of Accounts: Description)

EKBE, "History per Purchasing Document

BSEG. "Accounting Document Segment

TYPE-POOLS SLIS.

DATA: BEGIN OF JTAB OCCURS 0,

BUDAT LIKE BKPF-BUDAT, "Posting Date

BLART LIKE BKPF-BLART, "Doc. Type

MDOCU LIKE EKBE-BELNR, "Material Doc. No.

BELNR LIKE BSEG-BELNR, "Doc. No.

HKONT LIKE BSEG-HKONT, "GL A/c

LIFNR LIKE BSIK-LIFNR, "Vendor Code

PSWBT LIKE BSEG-PSWBT, "GL Amt

SHKZG LIKE BSEG-SHKZG, "Db/Cr Indicator

SGTXT LIKE BSEG-SGTXT, "Text

GJAHR LIKE BSEG-GJAHR, "Fiscal Year

EBELN LIKE BSEG-EBELN, "Purchasing Doc. No.

NAME1 LIKE LFA1-NAME1, "Vendor Name

TXT50 LIKE SKAT-TXT50, "Long Text

BAMT TYPE P DECIMALS 2, "Base Amount

TDS1 TYPE I, "TDS Amt Rounded Off

TDS2(5) TYPE P DECIMALS 2, "Calculated TDS %

END OF JTAB.

DATA : PTAB LIKE JTAB OCCURS 0 WITH HEADER LINE .

DATA : BTAB LIKE JTAB OCCURS 0 WITH HEADER LINE.

DATA : MDT(8) TYPE C.

DATA : MYR(4) TYPE C.

DATA : MTH(2) TYPE C.

DATA : MBELNR LIKE BSEG-BELNR.

DATA : MTDS1 LIKE JTAB-TDS1.

DATA : THKONT(10) TYPE C.

DATA : TDESC(50) TYPE C.

DATA : TLIST(60) TYPE C.

DATA : LT_LAYOUT TYPE SLIS_LAYOUT_ALV,

LT_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV,

LT_LISTHEADER TYPE SLIS_T_LISTHEADER,

LT_EVENT TYPE SLIS_T_EVENT,

LT_SORT TYPE SLIS_T_SORTINFO_ALV,

LT_SORT1 TYPE SLIS_SORTINFO_ALV.

SELECTION-SCREEN : BEGIN OF BLOCK B1S WITH FRAME TITLE T1.

SELECT-OPTIONS : S_HKONT FOR BSIS-HKONT NO INTERVALS OBLIGATORY.

SELECT-OPTIONS : S_BUDAT FOR BSIS-BUDAT.

SELECTION-SCREEN : END OF BLOCK B1S.

INITIALIZATION.

T1 = 'T.D.S. Register'.

START-OF-SELECTION.

MDT = S_BUDAT-LOW.

SHIFT MDT BY 4 PLACES.

MTH = MDT.

MYR = S_BUDAT-LOW.

IF MTH GE '01' AND MTH LE '03'.

MYR = MYR - 1.

ENDIF.

PERFORM GBSEG.

END-OF-SELECTION.

THKONT = JTAB-HKONT.

TDESC = JTAB-TXT50.

LT_LAYOUT-ZEBRA = 'X'.

LT_LAYOUT-COLWIDTH_OPTIMIZE = 'X'.

LT_LAYOUT-INFO_FIELDNAME = 'CLR'.

PERFORM FIEDCAT USING LT_FIELDCAT.

PERFORM DISPLAY.

&----


*& Form GBSEG

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


form GBSEG.

                        • Get Posting Date from BSIS ************

SELECT BELNR BUDAT BLART FROM BKPF INTO CORRESPONDING FIELDS OF TABLE PTAB WHERE BUDAT IN S_BUDAT.

                        • Get Records from BSEG only for GL Ac in Select-Options ************

SELECT BELNR GJAHR SHKZG PSWBT SGTXT HKONT LIFNR FROM BSEG INTO CORRESPONDING FIELDS OF TABLE JTAB

FOR ALL ENTRIES IN PTAB WHERE BELNR = PTAB-BELNR AND HKONT IN S_HKONT.

LOOP AT JTAB.

READ TABLE PTAB WITH KEY BELNR = JTAB-BELNR.

MOVE PTAB-BUDAT TO JTAB-BUDAT.

MOVE PTAB-BLART TO JTAB-BLART.

MODIFY JTAB.

ENDLOOP.

            • Delete records not in Select-Options Date Range from JTAB *******

DELETE JTAB WHERE BUDAT = '00000000'.

  • SELECT BELNR GJAHR SHKZG PSWBT SGTXT HKONT LIFNR FROM BSEG

  • INTO (JTAB-BELNR, JTAB-GJAHR, JTAB-SHKZG, JTAB-PSWBT, JTAB-SGTXT, JTAB-HKONT,

  • JTAB-LIFNR) WHERE GJAHR = MYR AND HKONT IN S_HKONT.

SORT JTAB BY BELNR.

LOOP AT JTAB.

JTAB-TDS1 = JTAB-PSWBT.

IF JTAB-BLART < '99'.

JTAB-TDS1 = 0.

MODIFY JTAB.

ELSE.

IF JTAB-TDS1 < JTAB-PSWBT.

JTAB-TDS1 = JTAB-TDS1 + 1.

ENDIF.

IF JTAB-SHKZG = 'S'.

JTAB-TDS1 = JTAB-TDS1 * -1.

ENDIF.

JTAB-PSWBT = 0.

ON CHANGE OF JTAB-BELNR.

MODIFY JTAB.

ELSE.

COLLECT JTAB.

DELETE JTAB.

ENDON.

ENDIF.

ENDLOOP.

            • Delete records not in Select-Options Date Range from JTAB *******

  • DELETE JTAB WHERE BUDAT = '00000000'.

            • Delete records for TYPE - 11,12,14,16 from JTAB *******

  • CLEAR JTAB.

  • LOOP AT JTAB.

  • ENDLOOP.

                        • Get Base Amt,LIFNR, NAME1, MDOCU ************

CLEAR JTAB.

LOOP AT JTAB.

SELECT BELNR SHKZG PSWBT EBELN FROM BSEG

INTO (BTAB-BELNR, BTAB-SHKZG, BTAB-PSWBT, BTAB-EBELN)

WHERE BELNR = JTAB-BELNR AND SHKZG = 'S' AND GJAHR = MYR.

JTAB-BAMT = BTAB-PSWBT + JTAB-BAMT.

IF BTAB-EBELN <> ''.

JTAB-EBELN = BTAB-EBELN.

ENDIF.

ENDSELECT.

IF JTAB-BAMT > 0 AND JTAB-BAMT > JTAB-TDS1.

JTAB-TDS2 = JTAB-TDS1 / JTAB-BAMT * 100.

ELSE.

JTAB-TDS2 = 0.

ENDIF.

SELECT BELNR SHKZG LIFNR FROM BSEG

INTO (BTAB-BELNR, BTAB-SHKZG, BTAB-LIFNR)

WHERE BELNR = JTAB-BELNR AND SHKZG = 'H' AND LIFNR <> '' AND GJAHR = MYR.

JTAB-LIFNR = BTAB-LIFNR.

ENDSELECT.

IF JTAB-EBELN <> ''.

SELECT * FROM EKBE WHERE EBELN = JTAB-EBELN AND BEWTP = 'Q'.

IF SY-SUBRC = 0.

JTAB-MDOCU = EKBE-BELNR.

ENDIF.

ENDSELECT.

ELSE.

CONCATENATE 'TYPE -' JTAB-BLART INTO JTAB-MDOCU.

ENDIF.

IF JTAB-LIFNR <> ''.

SELECT * FROM LFA1 WHERE LIFNR = JTAB-LIFNR.

IF SY-SUBRC = 0.

JTAB-NAME1 = LFA1-NAME1.

ENDIF.

ENDSELECT.

ELSE.

CONCATENATE 'DOCUMENT TYPE -' JTAB-BLART INTO JTAB-NAME1.

ENDIF.

SELECT * FROM SKAT WHERE SAKNR = JTAB-HKONT.

JTAB-TXT50 = SKAT-TXT50.

ENDSELECT.

MODIFY JTAB.

JTAB-BAMT = 0.

JTAB-TDS1 = 0.

JTAB-TDS2 = 0.

ENDLOOP.

endform. " GBSEG

&----


*& Form FIEDCAT

&----


  • text

----


  • -->P_LT_FIELDCAT text

----


form FIEDCAT using p_lt_fieldcat TYPE SLIS_T_FIELDCAT_ALV.

FIELD-SYMBOLS: <FC> TYPE SLIS_FIELDCAT_ALV.

CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'

EXPORTING

I_PROGRAM_NAME = SY-REPID

  • I_INTERNAL_TABNAME =

I_STRUCTURE_NAME = 'ZTDSREG'

  • I_CLIENT_NEVER_DISPLAY = 'X'

I_INCLNAME = SY-REPID

  • I_BYPASSING_BUFFER =

  • I_BUFFER_ACTIVE =

CHANGING

ct_fieldcat = P_LT_FIELDCAT

  • EXCEPTIONS

  • INCONSISTENT_INTERFACE = 1

  • PROGRAM_ERROR = 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.

LOOP AT P_LT_FIELDCAT ASSIGNING <FC>.

CASE <FC>-FIELDNAME.

WHEN 'BUDAT'.

<FC>-SELTEXT_L = 'Invoice Date'.

<FC>-ddictxt = 'L'. "Depending upon 'S,L,M' takes 'Short,Long,Medium' SELTEXT

  • <FC>-KEY = 'X'.

  • <FC>-HOTSPOT = 'X'.

  • <FC>-COL_POS = 1.

WHEN 'MDOCU'.

<FC>-SELTEXT_L = 'Invoice No.'.

<FC>-ddictxt = 'L'.

WHEN 'BELNR'.

<FC>-SELTEXT_L = 'A/c Document No.'.

<FC>-ddictxt = 'L'.

WHEN 'NAME1'.

<FC>-SELTEXT_L = 'Vendor Name'.

<FC>-ddictxt = 'L'.

WHEN 'BAMT'.

<FC>-SELTEXT_L = 'Base Amount'.

<FC>-ddictxt = 'L'.

WHEN 'TDS1'.

<FC>-SELTEXT_L = 'TDS Amount'.

<FC>-ddictxt = 'L'.

<FC>-DO_SUM = 'X'.

WHEN 'TDS2'.

<FC>-SELTEXT_L = 'TDS %'.

<FC>-ddictxt = 'L'.

WHEN 'SGTXT'.

<FC>-SELTEXT_L = 'Text'.

<FC>-ddictxt = 'L'.

ENDCASE.

ENDLOOP.

endform. " FIEDCAT

&----


*& Form DISPLAY

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


form DISPLAY .

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

EXPORTING

  • I_INTERFACE_CHECK = ' '

  • I_BYPASSING_BUFFER = ' '

  • I_BUFFER_ACTIVE = ' '

I_CALLBACK_PROGRAM = SY-REPID

  • I_CALLBACK_PF_STATUS_SET = ' '

  • I_CALLBACK_USER_COMMAND = 'USER_COMMAND'

I_CALLBACK_TOP_OF_PAGE = 'TOP_OF_PAGE'

  • I_CALLBACK_HTML_TOP_OF_PAGE = ' '

  • I_CALLBACK_HTML_END_OF_LIST = ' '

  • I_STRUCTURE_NAME =

  • I_BACKGROUND_ID = ' '

  • I_GRID_TITLE =

  • I_GRID_SETTINGS =

IS_LAYOUT = LT_LAYOUT

IT_FIELDCAT = LT_FIELDCAT

  • IT_EXCLUDING =

  • IT_SPECIAL_GROUPS =

IT_SORT = LT_SORT

  • IT_FILTER =

  • IS_SEL_HIDE =

  • I_DEFAULT = 'X'

  • I_SAVE = ' '

  • IS_VARIANT =

  • IT_EVENTS =

  • IT_EVENT_EXIT =

  • IS_PRINT =

  • IS_REPREP_ID =

  • I_SCREEN_START_COLUMN = 0

  • I_SCREEN_START_LINE = 0

  • I_SCREEN_END_COLUMN = 0

  • I_SCREEN_END_LINE = 0

  • IT_ALV_GRAPHICS =

  • IT_HYPERLINK =

  • IT_ADD_FIELDCAT =

  • IT_EXCEPT_QINFO =

  • I_HTML_HEIGHT_TOP =

  • I_HTML_HEIGHT_END =

  • IMPORTING

  • E_EXIT_CAUSED_BY_CALLER =

  • ES_EXIT_CAUSED_BY_USER =

TABLES

t_outtab = JTAB

  • EXCEPTIONS

  • PROGRAM_ERROR = 1

  • OTHERS = 2

.

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. " DISPLAY

FORM TOP_OF_PAGE.

REFRESH : LT_LISTHEADER.

DATA : LT_LIST TYPE SLIS_LISTHEADER,

HIGH(50),PLANT5(50).

CLEAR: LT_LIST.

LT_LIST-TYP = 'H'.

LT_LIST-INFO = 'JOST ENGINEERING COMPANY LTD.'.

APPEND LT_LIST TO LT_LISTHEADER.

CLEAR LT_LIST.

LT_LIST-TYP = 'S'.

LT_LIST-INFO = 'MONTHLY T.D.S. REGISTER.'.

APPEND LT_LIST TO LT_LISTHEADER.

CLEAR LT_LIST.

CONCATENATE 'G/L Account: ' THKONT ' - ' TDESC INTO TLIST SEPARATED BY SPACE.

LT_LIST-TYP = 'S'.

LT_LIST-INFO = TLIST.

APPEND LT_LIST TO LT_LISTHEADER.

CLEAR LT_LIST.

CLEAR TLIST.

CONCATENATE 'From: ' S_BUDAT-LOW6(2) '/' S_BUDAT-LOW4(2) '/'

S_BUDAT-LOW(4) 'To:' S_BUDAT-HIGH6(2) '/' S_BUDAT-HIGH4(2) '/'

S_BUDAT-HIGH(4) INTO TLIST SEPARATED BY SPACE.

LT_LIST-TYP = 'S'.

LT_LIST-INFO = TLIST.

APPEND LT_LIST TO LT_LISTHEADER.

CLEAR LT_LIST.

CLEAR TLIST.

CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'

EXPORTING

it_list_commentary = LT_LISTHEADER

.

ENDFORM.

2 REPLIES 2

Former Member
0 Kudos

Hi,

Use of tables like BSEG in a report is always a performance issue. The best solution to optimize the performance is using all the key fields in the where clause of select statement. Otherwise the perfromance will be hampered.

Try not using * in your Select queries.

Regards,

Rohit

Reward the helpful replies.

Former Member
0 Kudos

Hi Gaurav,

You are missing the first key field (the most important) in your BSEG select where-claus which is the company code (BSEG-BUKRS). For example,

select belnr shkzg pswbt ebeln from bseg

into (btab-belnr, btab-shkzg, btab-pswbt, btab-ebeln)

where belnr = jtab-belnr and shkzg = 'S' and gjahr = myr.

should be something like:

select belnr shkzg pswbt ebeln from bseg

into (btab-belnr, btab-shkzg, btab-pswbt, btab-ebeln)

where bukrs = jtab-bukrs and

belnr = jtab-belnr and shkzg = 'S' and gjahr = myr.

(You will need to add the field BUKRS to table jtab of course).

Without the first key field you are effectively doing a sequential search (searching line by line). Hope this helps.

PS As a general performance methodology, if you can't use all the primary keys, try using keys from indexes. Again, the first key fields are the most important.

Regards

Kent

Please award point if you find this post useful.