‎2013 Jun 18 9:38 AM
HI ,
I am using fuction module within loop
which is taking lots of time please tell me any trick how to do fast processing
my code is
LOOP AT IT_HD INTO WA_HD .
var = var + 1.
CALL FUNCTION 'BBP_PD_SC_GETDETAIL'
EXPORTING
I_GUID = WA_HD-GUID
IMPORTING
E_HEADER = E_HEADER
TABLES
E_ITEM = E_ITEM
E_ACCOUNT = E_ACCOUNT
E_PARTNER = E_PARTNER
E_STATUS = E_STATUS .
delete E_STATUS WHERE INACT = 'X'.
READ TABLE E_STATUS INTO WA_STATUS INDEX 1.
select single TXT30 from TJ02T into TXT30 WHERE ISTAT = WA_STATUS-STAT and SPRAS = 'E'.
loop at E_ITEM INTO WA_ITEM .
READ TABLE E_PARTNER INTO WA_PARTNER WITH KEY PARTNER_FCT = '00000019'.
READ TABLE IT_ORG INTO WA_ORG WITH KEY BE_PUR_GROUP = WA_ITEM-BE_PUR_GROUP
BE_PUR_ORG = WA_ITEM-BE_PUR_ORG
BE_CO_CODE = WA_ITEM-BE_CO_CODE.
IF SY-SUBRC = 0.
IF E_HEADER-POSTING_DATE IN POS_DATE.
SELECT SINGLE BE_OBJECT_ID FROM BBP_PDBEI INTO WA_SC-BE_OBJECT_ID WHERE GUID = WA_ITEM-GUID.
SELECT SINGLE NAME_ORG1 FROM BUT000 INTO WA_SC-NAME_ORG1 WHERE PARTNER_GUID = WA_PARTNER-PARTNER_NO .
ENDIF.
READ TABLE E_PARTNER INTO WA_PARTNER WITH KEY PARTNER_FCT = '00000019'.
WA_SC-ZZSOCOREQ = TXT30.
READ TABLE E_ACCOUNT INTO WA_ACCOUNT INDEX 1 .
CALL FUNCTION 'OWN_LOGICAL_SYSTEM_GET'
IMPORTING
OWN_LOGICAL_SYSTEM = SYST_ID.
.
SELECT SINGLE RFC_SYS FROM ZLOGICAL_SYS INTO RFC_SYS WHERE OWN_SYS = SYST_ID.
IF SY-SUBRC = 0.
CALL FUNCTION 'Z_SRM_PO_INFO' DESTINATION RFC_SYS
EXPORTING
BE_OBJECT_ID = WA_SC-BE_OBJECT_ID
GL_CODE = WA_ACCOUNT-G_L_ACCT
COST_CTR = WA_ACCOUNT-COST_CTR
FUND = WA_ACCOUNT-FUNDs_ctr
IMPORTING
AEDAT = WA_SC-AEDAT
GL_CODE_DES = WA_SC-GL_CODE_DES
C_C_D = WA_SC-C_C_D
FUND_DES = WA_SC-FUND_DES.
.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT'
EXPORTING
INPUT = WA_ITEM-ORDERED_PROD
IMPORTING
OUTPUT = WA_ITEM-ORDERED_PROD
.
WA_SC-CREATED_BY = WA_HD-CREATED_BY .
WA_SC-POSTING_DATE = E_HEADER-POSTING_DATE .
WA_SC-BE_PUR_GROUP = WA_ITEM-BE_PUR_GROUP .
WA_SC-BE_PUR_ORG = WA_ITEM-BE_PUR_ORG .
WA_SC-BJECT_ID = E_HEADER-OBJECT_ID .
WA_SC-DESCRIPTION = E_HEADER-DESCRIPTION.
WA_SC-ORDERED_PROD = WA_ITEM-ORDERED_PROD.
WA_SC-DESCRIPTION1 = WA_ITEM-DESCRIPTION.
WA_SC-QUANTITY = WA_ITEM-QUANTITY .
WA_SC-CTR_HDR_NUMBER = WA_ITEM-CTR_HDR_NUMBER .
WA_SC-CTR_ITEM_NUMBER = WA_ITEM-CTR_ITEM_NUMBER .
WA_SC-CURRENCY = WA_ITEM-CURRENCY .
WA_SC-GROSS_PRICE = WA_ITEM-PRICE * WA_ITEM-QUANTITY.
WA_SC-ACC_CAT = WA_ACCOUNT-ACC_CAT.
WA_SC-COST_CTR = WA_ACCOUNT-COST_CTR.
WA_SC-ORDER_NO = WA_ACCOUNT-ORDER_NO.
WA_SC-NETWORK = WA_ACCOUNT-NETWORK.
WA_SC-ACTIVITY = WA_ACCOUNT-ACTIVITY.
WA_SC-FUND = WA_ACCOUNT-FUNDs_ctr.
WA_SC-ZZPRODUCT = WA_ACCOUNT-ZZPRODUCT.
WA_SC-GL_CODE = WA_ACCOUNT-G_L_ACCT .
IF G_L_ACCT IS NOT INITIAL AND COST_CTR IS NOT INITIAL .
READ TABLE E_ACCOUNT INTO WA_ACCOUNT INDEX 1.
IF WA_ACCOUNT-G_L_ACCT = G_L_ACCT AND WA_ACCOUNT-COST_CTR = COST_CTR.
APPEND WA_SC TO IT_SC .
ENDIF .
ENDIF .
IF G_L_ACCT IS NOT INITIAL AND COST_CTR IS INITIAL .
READ TABLE E_ACCOUNT INTO WA_ACCOUNT INDEX 1.
IF WA_ACCOUNT-G_L_ACCT = G_L_ACCT .
APPEND WA_SC TO IT_SC .
ENDIF .
ENDIF .
IF G_L_ACCT IS INITIAL AND COST_CTR IS NOT INITIAL .
READ TABLE E_ACCOUNT INTO WA_ACCOUNT INDEX 1.
IF WA_ACCOUNT-COST_CTR = COST_CTR.
APPEND WA_SC TO IT_SC .
ENDIF .
ENDIF .
IF G_L_ACCT IS INITIAL AND COST_CTR IS INITIAL .
APPEND WA_SC TO IT_SC .
ENDIF .
ENDIF .
ENDIF .
ENDLOOP .
ENDLOOP .
‎2013 Jun 18 1:06 PM
Hi Ravi kumar,
As per my observations of your code,
Reasons for large response time:
1) Loop inside loop
2) Read statements.
My suggestions:
1) Instead of using the first loop (LOOP AT IT_HD INTO WA_HD)
Make use of:
describe table it_hd.
itab_cnt = sy-tfill "No .of records in it_hd
cnt = 1.
while cnt <= itab_cnt.
read table it_hd index cnt
.
endwhile.
THIS WILL ELIMINATE THE SYSTEM'S LOAD TO TRACK INDEX OF TWO INTERNAL TABLES
2) Wherever READ is used, sort the internal tables and read them using binary search.
3) Following codes can be put outside the loop as they are static (no dependency on e_item)
(a)READ TABLE E_PARTNER INTO WA_PARTNER WITH KEY PARTNER_FCT = '00000019'.
(b) CALL FUNCTION 'OWN_LOGICAL_SYSTEM_GET'
IMPORTING
OWN_LOGICAL_SYSTEM = SYST_ID etc.
4) You can make use of FIELD-SYMBOLS for much faster access of the internal table (e_item)
‎2013 Jun 18 2:19 PM
Hi Ravi,
Main Issues and advices are
1) Issue - Read Statements without BINARY SEARCH clause.
Advice - Sort all the internal tables in the sequence of fields which you are using in 'WHERE' Clause and then use BINARY SEARCH in all Read Statement. After Read statement check the sy-subrc value and then proceed.
2) Issue - Select Statements inside the Loop. Some Selects are inside second level of Loop. Since every Select Statement opens a DB Cursor, fetches Data and Closes it, it is very performance intensive.
Advice - Get all the entries into an internal table and then Do the Select Once for all using For All Entries.
* As suggested by Arun you can go for Field Symbols instead of any work area, it will be faster but be sure to make a check
if <FS> is assigned.
*-- Process
endif.
BR.
‎2013 Jun 18 2:36 PM
Well, the OP himself has indicated the main cause. Using Function modules inside a loop.
In this case that IS the main problem. So how to solve this?
This problem is that standard functions usually retrieve far more data than required.
The best way to get around this, is to check what data you need, and see if it is feasible to select it from the database (not by the FM, but by your own coding).
If you can do this, it will be a huge improvement. But it all depends on what data you need...
Then, you can look at the othe suggestions (READ w. BINARY SEARCH, Selecting into internal tables and (if you have records) do a SELECT FOR ALL ENTRIES.
But first things first. Try to get rid of the FM's.
‎2013 Jun 18 2:35 PM
Hi Ravi,
1. sort the internal table
2. while using the read statement use binary search, so that it will fetch the data as faster
3. Instead of loop within loop use parallel cursor method.this is the best technique while loop in loop case.
Let me know if any issues.
Regards,
Guru
‎2013 Jun 19 8:33 AM
‎2013 Jun 19 8:54 AM
ravi kumar wrote:
please explain me
parallel cursor method.
Plenty of documentation - please search.
‎2013 Jun 19 8:57 AM
Hi Ravi,
See this code
TABLES:
likp,
lips.
Data:
t_likp type table of likp,
t_lips type TABLE OF lips.
data:
W_RUNTIME1 TYPE I,
W_RUNTIME2 TYPE I,
w_index LIKE sy-index. " Using Parallel Cursor
START-OF-SELECTION.
select *
from likp
into table t_likp.
select *
from lips
into table t_lips.
get RUN TIME FIELD w_runtime1.
SORT t_likp BY vbeln. " Using Parallel Cursor
SORT t_lips BY vbeln. " Using Parallel Cursor
loop at t_likp into likp.
* loop at t_lips into lips where vbeln eq likp-vbeln.
LOOP AT t_lips INTO lips FROM w_index. " Using Parallel Cursor
IF likp-vbeln NE lips-vbeln.
w_index = sy-tabix.
EXIT.
ENDIF.
endloop.
endloop.
get RUN TIME FIELD w_runtime2.
w_runtime2 = w_runtime2 - w_runtime1.
write w_runtime2.
‎2013 Jun 19 11:45 AM
Hi Ravi,
please follow the Ramesh T,he was explained earlier post.
‎2013 Jun 19 12:11 PM
Hi Ravi,
you need to do the following to increase the performance.
Regards, Suhas.
‎2013 Jun 19 5:04 PM
BBP_PD_SC_GETDETAIL is a RFC enabled function module that isgetting calling inside a loop which could be a cause of concern and needs to be checked.
K.Kiran.
‎2013 Jun 20 1:37 AM
Hi
1-Avoid duplication in internal table using 'Delete Adjacent Duplicate'.
SELECT SINGLE FROM NAME_ORG1 BUT000 INTO WA_SC-NAME_ORG1 WHERE PARTNER_GUID = WA_PARTNER-PARTNER_NO.
2 - The command 'select single' above must contain the condition 'where' the whole key and 'PARTNER_GUID' is key, so much influence on performance see if the functional has the field 'PARTNER' which is the key of the table.
See if others 'select singles' are key to complete as much influence on performance.