Application Development and Automation 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: 
Read only

performance tuning

Former Member
0 Likes
1,024

Hi experts

I have the code as follows, its taking so much time to run and sometime go for time exits also.

how can we increase the performance, can u do corrections or give suggestions.

Thanks in advance.

Regards

Rajaram

TABLES : bseg,LFA1,EKKO.

TYPE-POOLS : slis.

  • Data Declarations

DATA : fcat TYPE slis_t_fieldcat_alv,

it_sort TYPE SLIS_T_SORTINFO_ALV ,

wa_sort type slis_sortinfo_alv,

ls_fcat LIKE LINE OF fcat,

fheader TYPE TABLE OF slis_listheader WITH NON-UNIQUE DEFAULT KEY

WITH HEADER LINE INITIAL SIZE 0.

DATA :i_repid LIKE sy-repid,

gs_layout TYPE slis_layout_alv,

week type n.

DATA: l_index TYPE sy-tabix,

output(20) type c.

*Internal Tables

DATA : BEGIN OF IT_BSEG OCCURS 0,

BELNR LIKE BSEG-BELNR,

EBELN LIKE BSEG-EBELN,

EBELP LIKE BSEG-EBELP,

LIFNR LIKE BSEG-LIFNR,

GJAHR like BSEG-GJAHR,

ZBEL1 LIKE BSEG-BELNR,

END OF IT_BSEG.

DATA : BEGIN OF IT_BSEG1 OCCURS 0,

BELNR LIKE BSEG-BELNR,

EBELN LIKE BSEG-EBELN,

EBELP LIKE BSEG-EBELP,

LIFNR LIKE BSEG-LIFNR,

VALUT LIKE BSEG-VALUT,

MATNR LIKE BSEG-MATNR,

WERKS LIKE BSEG-WERKS,

MENGE LIKE BSEG-MENGE,

MEINS LIKE BSEG-MEINS,

GJAHR like BSEG-GJAHR,

ZBEL1 LIKE BSEG-BELNR,

NAME1 LIKE LFA1-NAME1,

DMBTR LIKE BSEG-DMBTR,

END OF IT_BSEG1.

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

SELECT-OPTIONS: zbel FOR bseg-belnr OBLIGATORY.

SELECT-OPTIONS: zfi FOR bseg-GJAHR OBLIGATORY.

SELECTION-SCREEN END OF BLOCK bk1.

zbel = zbel-low.

zfi = zfi-low.

perform edit_mask.

gs_layout-colwidth_optimize = 'X'.

select belnr ebeln GJAHR

from bseg

into corresponding fields of TABLE it_bseg

where belnr in zbel and

GJAHR in zfi.

if it_bseg[] is initial.

exit.

endif.

loop at it_bseg.

move it_bseg-belnr to it_bseg-zbel1.

modify it_bseg.

endloop.

SELECT BELNR

VALUT

EBELN

EBELP

LIFNR

MATNR

WERKS

MENGE

MEINS

GJAHR

DMBTR

FROM BSEG

INTO CORRESPONDING FIELDS OF TABLE IT_BSEG1

for all entries in it_bseg

WHERE GJAHR = IT_BSEG-GJAHR and

EBELN = IT_BSEG-EBELN and

GJAHR = IT_BSEG-GJAHR.

loop at it_bseg.

loop at it_bseg1.

if it_bseg1-ebeln = it_bseg-ebeln.

move it_bseg-zbel1 to it_bseg1-zbel1.

modify it_bseg1.

endif.

endloop.

endloop.

LOOP AT IT_BSEG1.

IF IT_BSEG1-LIFNR IS INITIAL.

SELECT SINGLE EBELN LIFNR

FROM EKKO INTO (IT_BSEG1-EBELN , IT_BSEG1-LIFNR)

WHERE EBELN = IT_BSEG1-EBELN.

ENDIF.

SELECT SINGLE LIFNR NAME1 FROM LFA1

INTO (IT_BSEG1-LIFNR , IT_BSEG1-NAME1)

WHERE LIFNR = IT_BSEG1-LIFNR.

MODIFY IT_BSEG1.

ENDLOOP.

PERFORM EDIT_MASK.

PERFORM EDIT_MASK1.

loop at it_bseg1.

if it_bseg1-belnr(1) NE '4'.

delete it_bseg1.

endif.

endloop.

i_repid = sy-repid.

PERFORM fieldcat.

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

EXPORTING

i_callback_program = i_repid

is_layout = gs_layout

it_fieldcat = fcat

i_save = 'A'

TABLES

t_outtab = it_bseg1

EXCEPTIONS

program_error = 1

OTHERS = 2.

&----


*& Form fieldcat

&----


  • text

----


FORM fieldcat.

MOVE sy-repid TO i_repid.

ls_fcat-tabname = 'IT_BSEG1'.

ls_fcat-fieldname = 'ZBEL1'.

ls_fcat-outputlen = 10.

ls_fcat-seltext_m = 'Document'.

APPEND ls_fcat TO fcat.

ls_fcat-tabname = 'IT_BSEG1'.

ls_fcat-fieldname = 'BELNR'.

ls_fcat-outputlen = 10.

ls_fcat-seltext_m = 'Document'.

APPEND ls_fcat TO fcat.

ls_fcat-tabname = 'IT_BSEG1'.

ls_fcat-fieldname = 'GJAHR'.

ls_fcat-outputlen = 4.

ls_fcat-seltext_m = 'F.Year'.

APPEND ls_fcat TO fcat.

ls_fcat-tabname = 'IT_BSEG1'.

ls_fcat-fieldname = 'EBELN'.

ls_fcat-outputlen = 10.

ls_fcat-seltext_m = 'PO Number'.

APPEND ls_fcat TO fcat.

ls_fcat-tabname = 'IT_BSEG1'.

ls_fcat-fieldname = 'EBELP'.

ls_fcat-outputlen = 2.

ls_fcat-seltext_m = 'Item'.

APPEND ls_fcat TO fcat.

ls_fcat-tabname = 'IT_BSEG1'.

ls_fcat-fieldname = 'LIFNR'.

ls_fcat-outputlen = 2.

ls_fcat-seltext_m = 'Vendor'.

APPEND ls_fcat TO fcat.

ls_fcat-tabname = 'IT_BSEG1'.

ls_fcat-fieldname = 'NAME1'.

ls_fcat-outputlen = 20.

ls_fcat-seltext_m = 'Description'.

APPEND ls_fcat TO fcat.

ls_fcat-tabname = 'IT_BSEG1'.

ls_fcat-fieldname = 'MATNR'.

ls_fcat-outputlen = 10.

ls_fcat-seltext_m = 'Material'.

APPEND ls_fcat TO fcat.

ls_fcat-tabname = 'IT_BSEG1'.

ls_fcat-fieldname = 'VALUT'.

ls_fcat-outputlen = 10.

ls_fcat-seltext_m = 'Posting Date'.

APPEND ls_fcat TO fcat.

ls_fcat-tabname = 'IT_BSEG1'.

ls_fcat-fieldname = 'WERKS'.

ls_fcat-outputlen = 4.

ls_fcat-seltext_m = 'Plant'.

APPEND ls_fcat TO fcat.

ls_fcat-tabname = 'IT_BSEG1'.

ls_fcat-fieldname = 'MENGE'.

ls_fcat-outputlen = 5.

ls_fcat-seltext_m = 'Qty'.

APPEND ls_fcat TO fcat.

ls_fcat-tabname = 'IT_BSEG1'.

ls_fcat-fieldname = 'MEINS'.

ls_fcat-outputlen = 3.

ls_fcat-seltext_m = 'Un'.

APPEND ls_fcat TO fcat.

ls_fcat-tabname = 'IT_BSEG1'.

ls_fcat-fieldname = 'DMBTR'.

ls_fcat-outputlen = 3.

ls_fcat-seltext_m = 'Amount'.

APPEND ls_fcat TO fcat.

endform.

FORM EDIT_MASK1 .

loop at it_bseg1.

CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT'

EXPORTING

INPUT = it_bseg1-belnr

IMPORTING

OUTPUT = it_bseg1-belnr.

modify it_bseg1.

endloop.

ENDFORM.

form edit_mask.

CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT'

EXPORTING

input = zbel

IMPORTING

output = zbel.

CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT'

EXPORTING

input = zfi

IMPORTING

output = zfi.

endform.

9 REPLIES 9
Read only

Former Member
0 Likes
1,002

inside statement only used read statement.

loop

select

endloop.

please do no write this way..

replace to this

select *

loop at it.

used

read tablr

endloop

loop

Read only

Former Member
0 Likes
1,002

inside loop statement do select .

wrong logic

loop

select

endloop.

please do no write this way..

replace to this

select *

loop at it.

used

read tablr

endloop

loop

Read only

Former Member
0 Likes
1,002

Hi,

1.donot use select inside the loop .. instead use for all entries for the DBtable and the internal table..

2. donot use corresponding fields, instaed define table with same number of fields you are retrieving.

3.Use field symbols so that there will be no chance of using modify statement.

feel free to post oif any issues

rewards if useful,

regards,

nazeer

Read only

Former Member
0 Likes
1,002

Hi

Lookout for these..

1. Before using for all entries, check if the internal table has any data.

2. Sort it_bseg1 by ebeln. and use READ stmnt in the loop at it_bseg.

3. Avoid select single stmnt inside loop. You can get the required data into internal tables, loop at it_bseg1 read the respective internal tables and update the fields.

Regards

Raj

Read only

0 Likes
1,002

In whcih method we can read data when avoiding Select stmt inside loop.

Regards

Rajaram

Read only

Former Member
0 Likes
1,002

Hi

if not it_bseg1[] is initial.

*- Ekko

SELECT EBELN LIFNR

FROM EKKO INTO table it_ekko

FOR ALL ENTRIES IN it_bseg1

WHERE EBELN = IT_BSEG1-EBELN.

if sy-subrc = 0.

sort it_ekko by ebeln lifnr.

*-Lfa1

SELECT LIFNR NAME1 FROM LFA1

INTO table it_lfa1

FOR ALL ENTRIES IN it_ekko

WHERE LIFNR = IT_EKKO-LIFNR.

if sy-subrc = 0.

sort it_lfa1 by lifnr.

endif.

endif.

endif.

LOOP AT IT_BSEG1.

read it_ekko with key ebeln = it_bseg1-ebeln binary search.

<assign the values to it_bseg1>

if sy-subrc = 0.

read it_lfa1 with key lifnr = it_ekko-lifnr binary search.

if sy-subrc = 0.

<assign the values to it_bseg1>

endif.

endif.

MODIFY IT_BSEG1.

ENDLOOP.

Regards

Raj

Read only

0 Likes
1,002

thank you yar

i will let u know after working on this.

Regards

Rajaram

Read only

0 Likes
1,002

hi raj

finally i want these data into it_bseg1,

how can we do this,

Regards

Rajaram

Read only

Former Member
0 Likes
1,002

Hi,

Try the below code... I dont fully understand why some part of your code is required and so removed whatever I felt is unnecessary.. But with the below code I got the same data as the code you had given.

Key Points are,

1. Aviod Loop within loops

2. If you require documents starting with '4' alone, remove the rest of the records in the beginning itself. Otherwise, entire set of records will be processed only to be deleted at the end.

3. Try not to use internal table with OCCURS statement... Declaring a separate workarea gives much better performance

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

TABLES : bseg,LFA1,EKKO.

TYPE-POOLS : slis.

  • Data Declarations

DATA : fcat TYPE slis_t_fieldcat_alv,

it_sort TYPE SLIS_T_SORTINFO_ALV ,

wa_sort type slis_sortinfo_alv,

ls_fcat LIKE LINE OF fcat,

fheader TYPE TABLE OF slis_listheader WITH NON-UNIQUE DEFAULT KEY

WITH HEADER LINE INITIAL SIZE 0.

DATA :i_repid LIKE sy-repid,

gs_layout TYPE slis_layout_alv,

week type n.

DATA: l_index TYPE sy-tabix,

output(20) type c.

types : BEGIN OF gty_BSEG1,

BELNR type BSEG-BELNR,

GJAHR like BSEG-GJAHR,

DMBTR LIKE BSEG-DMBTR,

VALUT LIKE BSEG-VALUT,

LIFNR LIKE BSEG-LIFNR,

MATNR LIKE BSEG-MATNR,

WERKS LIKE BSEG-WERKS,

MENGE LIKE BSEG-MENGE,

MEINS LIKE BSEG-MEINS,

EBELN LIKE BSEG-EBELN,

EBELP LIKE BSEG-EBELP,

ZBEL1 LIKE BSEG-BELNR,

NAME1 LIKE LFA1-NAME1,

END OF gty_BSEG1.

data : it_bseg1 type standard table of gty_bseg1,

it_bseg2 type standard table of gty_bseg1,

wa_bseg1 type gty_bseg1.

field-symbols : <fs_bseg1> type gty_bseg1.

types : begin of gty_ekko,

ebeln type ekko-ebeln,

lifnr type ekko-lifnr,

end of gty_ekko.

data : it_ekko type standard table of gty_ekko,

wa_ekko type gty_ekko.

types : begin of gty_lfa1,

lifnr type lfa1-lifnr,

name1 type lfa1-name1,

end of gty_lfa1.

data : it_lfa1 type standard table of gty_lfa1,

wa_lfa1 type gty_lfa1.

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

SELECT-OPTIONS: zbel FOR bseg-belnr.

SELECT-OPTIONS: zfi FOR bseg-GJAHR.

SELECTION-SCREEN END OF BLOCK bk1.

gs_layout-colwidth_optimize = 'X'.

SELECT

BELNR

GJAHR

DMBTR

VALUT

LIFNR

MATNR

WERKS

MENGE

MEINS

EBELN

EBELP

FROM BSEG

INTO TABLE IT_BSEG1

WHERE GJAHR in zfi and

belnr in zbel.

if not it_bseg1[] is initial.

loop at it_bseg1 assigning <fs_bseg1>.

shift <fs_bseg1>-belnr left deleting leading '0'.

endloop.

delete it_bseg1 where belnr(1) NE '4'.

it_bseg2[] = it_bseg1[].

delete it_bseg2 where lifnr NE ' '.

select ebeln lifnr from ekko

into table it_ekko

for all entries in it_bseg2

where ebeln = it_bseg2-ebeln.

sort it_ekko by ebeln.

select lifnr name1 from LFA1 into table it_lfa1

for all entries in it_bseg1

where lifnr = it_bseg1-lifnr.

sort it_lfa1 by lifnr.

LOOP AT IT_BSEG1 assigning <fs_bseg1>.

IF <fs_BSEG1>-LIFNR IS INITIAL.

read table it_ekko into wa_ekko with key ebeln = <fs_bseg1>-ebeln

binary search.

if sy-subrc EQ 0.

<fs_bseg1>-ebeln = wa_ekko-ebeln.

<fs_bseg1>-lifnr = wa_ekko-lifnr.

endif.

ENDIF.

read table it_lfa1 into wa_lfa1 with key lifnr = <fs_bseg1>-lifnr

binary search.

if sy-subrc EQ 0.

<fs_bseg1>-name1 = wa_lfa1-name1.

endif.

ENDLOOP.

endif.

sort it_bseg1 by belnr gjahr.

i_repid = sy-repid.

PERFORM fieldcat.

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

EXPORTING

i_callback_program = i_repid

is_layout = gs_layout

it_fieldcat = fcat

i_save = 'A'

TABLES

t_outtab = it_bseg1

EXCEPTIONS

program_error = 1

OTHERS = 2.

&----


*& Form fieldcat

&----


  • text

----


FORM fieldcat.

ls_fcat-tabname = 'IT_BSEG1'.

ls_fcat-fieldname = 'BELNR'.

ls_fcat-outputlen = 10.

ls_fcat-seltext_m = 'Document'.

APPEND ls_fcat TO fcat.

ls_fcat-tabname = 'IT_BSEG1'.

ls_fcat-fieldname = 'GJAHR'.

ls_fcat-outputlen = 4.

ls_fcat-seltext_m = 'F.Year'.

APPEND ls_fcat TO fcat.

ls_fcat-tabname = 'IT_BSEG1'.

ls_fcat-fieldname = 'EBELN'.

ls_fcat-outputlen = 10.

ls_fcat-seltext_m = 'PO Number'.

APPEND ls_fcat TO fcat.

ls_fcat-tabname = 'IT_BSEG1'.

ls_fcat-fieldname = 'EBELP'.

ls_fcat-outputlen = 2.

ls_fcat-seltext_m = 'Item'.

APPEND ls_fcat TO fcat.

ls_fcat-tabname = 'IT_BSEG1'.

ls_fcat-fieldname = 'LIFNR'.

ls_fcat-outputlen = 2.

ls_fcat-seltext_m = 'Vendor'.

APPEND ls_fcat TO fcat.

ls_fcat-tabname = 'IT_BSEG1'.

ls_fcat-fieldname = 'NAME1'.

ls_fcat-outputlen = 20.

ls_fcat-seltext_m = 'Description'.

APPEND ls_fcat TO fcat.

ls_fcat-tabname = 'IT_BSEG1'.

ls_fcat-fieldname = 'MATNR'.

ls_fcat-outputlen = 10.

ls_fcat-seltext_m = 'Material'.

APPEND ls_fcat TO fcat.

ls_fcat-tabname = 'IT_BSEG1'.

ls_fcat-fieldname = 'VALUT'.

ls_fcat-outputlen = 10.

ls_fcat-seltext_m = 'Posting Date'.

APPEND ls_fcat TO fcat.

ls_fcat-tabname = 'IT_BSEG1'.

ls_fcat-fieldname = 'WERKS'.

ls_fcat-outputlen = 4.

ls_fcat-seltext_m = 'Plant'.

APPEND ls_fcat TO fcat.

ls_fcat-tabname = 'IT_BSEG1'.

ls_fcat-fieldname = 'MENGE'.

ls_fcat-outputlen = 5.

ls_fcat-seltext_m = 'Qty'.

APPEND ls_fcat TO fcat.

ls_fcat-tabname = 'IT_BSEG1'.

ls_fcat-fieldname = 'MEINS'.

ls_fcat-outputlen = 3.

ls_fcat-seltext_m = 'Un'.

APPEND ls_fcat TO fcat.

ls_fcat-tabname = 'IT_BSEG1'.

ls_fcat-fieldname = 'DMBTR'.

ls_fcat-outputlen = 3.

ls_fcat-seltext_m = 'Amount'.

APPEND ls_fcat TO fcat.

endform. "fieldcat

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

Regards,

Vinoth