‎2008 May 13 10:10 AM
Hi All,
Please change the code based on performance wise. Because its taking so much time to execute.
LOOP AT GT_CSKS.
SELECT * FROM EKKN
WHERE KOSTL = GT_CSKS-KOSTL
AND EBELN IN S_PO
AND KOKRS = P_KOKRS
and LOEKZ <> 'X'.
GC_PRCTR = GT_CSKS-PRCTR.
ENDSELECT.
ENDLOOP.
FORM PROCESS_MAIN2.
SELECT SINGLE * FROM EKKO WHERE EBELN = EKKN-EBELN.
SELECT SINGLE * FROM EKPO WHERE EBELN = EKKN-EBELN AND
EBELP = EKKN-EBELP.
CHECK EKPO-LOEKZ <> 'L' AND
EKPO-LOEKZ <> 'S'.
SELECT SINGLE EINDT FROM EKET INTO GC_EINDT
WHERE EBELN = EKPO-EBELN
AND EBELP = EKPO-EBELP
AND EINDT IN S_EINDT.
IF NOT S_EINDT IS INITIAL.
CHECK GC_EINDT IN S_EINDT.
ENDIF.
CLEAR ITAB.
ITAB-PO_CREATE = EKKO-AEDAT.
ITAB-DEL_DAT = GC_EINDT.
ITAB-PO_NO = EKKO-EBELN.
ITAB-CURR_PO = EKKO-WAERS.
ITAB-LINE = EKPO-EBELP.
ITAB-GR_SW = EKPO-WEPOS.
ITAB-GR_NON_VAL_SW = EKPO-WEUNB.
ITAB-TEXT = EKPO-TXZ01.
ITAB-QTY_ORD = EKPO-MENGE.
ITAB-UOM = EKPO-MEINS.
ITAB-AMOUNT_DOC = EKPO-EFFWR.
APPEND ITAB.
ENDFORM.
‎2008 May 13 10:32 AM
DATA : BEGIN OG ITAB OCCURS 0,
INCLUDE STRUCTURE EKKN.
DATA : END OF ITAB.
SORT GT_CSKS BY KOSTL.
SELECT * FROM EKKN INTO TABLE ITAB
FOR ALL ENTRIES IN GT_CSKS
WHERE KOSTL = GT_CSKS-KOSTL
AND EBELN IN S_PO
AND KOKRS = P_KOKRS
and LOEKZ 'X'.
LOOP AT GT_CSKS.
READ TABLE ITAB WITH KEY KOSTL = GT_CSKS-KOSTL.
AND DO YOUR PROCESS.
ENDLOOP.
in the below code select all the data out side of the form and then you can go for read as like i have written.
hope this will help you.
Regards,
Madan.
‎2008 May 13 10:23 AM
Hi Setty,
here it goes....
1) Select query inside a loop will take much time to be executed. avoid it.
2) in the first select query, you avoid '*' and take the fields whichever you want from EKKN table.
3) avoid ENDSELECT in the first select query and use INTO TABLE ITAB option. SELECT and ENDSELECT is equal to loop and endloop.
follow the above mentioned rules and the program performance will automatically get increased.
thanks & regards
Kishore Kumar Maram
‎2008 May 13 10:27 AM
Hi,
LOOP AT GT_CSKS.
SELECT * FROM EKKN
WHERE KOSTL = GT_CSKS-KOSTL
AND EBELN IN S_PO
AND KOKRS = P_KOKRS
and LOEKZ <> 'X'.
GC_PRCTR = GT_CSKS-PRCTR.
ENDSELECT.
ENDLOOP.In the above code, remove the select-endselect inside the loop.
make it select...for all entries in gt_csks...
avoid loekz<> 'X'. remove the unwanted entries( ie loekz = 'X') after the data fetch.
hope this helps.
regards,
madhumitha
‎2008 May 13 10:29 AM
hiii...
1. dont use select end select.....
bcz it will fetch data from the DB 1 record per time.. so dont use it..
it will take a long time..
2. dont use the check where you have used it.
fetch the data in a internal table and the carry out your work.
bcz u r engaging the DB more..so the time 4 execution is also more.
suggestion.. you can use the code inspector to analyze your prg..
use the tips and tricks there.. it will give u a clear idea.
reward points if helpful.
thanks...
‎2008 May 13 10:32 AM
DATA : BEGIN OG ITAB OCCURS 0,
INCLUDE STRUCTURE EKKN.
DATA : END OF ITAB.
SORT GT_CSKS BY KOSTL.
SELECT * FROM EKKN INTO TABLE ITAB
FOR ALL ENTRIES IN GT_CSKS
WHERE KOSTL = GT_CSKS-KOSTL
AND EBELN IN S_PO
AND KOKRS = P_KOKRS
and LOEKZ 'X'.
LOOP AT GT_CSKS.
READ TABLE ITAB WITH KEY KOSTL = GT_CSKS-KOSTL.
AND DO YOUR PROCESS.
ENDLOOP.
in the below code select all the data out side of the form and then you can go for read as like i have written.
hope this will help you.
Regards,
Madan.
‎2008 May 13 10:47 AM
lots of suggestions already provided
still...
1. never ever use select inside a loop
2. avoid using select *
3. dont use select..end select
4. dont use into corresponding fields of table..
enjoy sap-reward points-
Harmeet.
‎2008 May 13 11:20 AM
Hi All,
I forget to insert PERFORM PROCESS_MAIN2. statment inside the select - endselect. I think logic will change with the statment.
Thanks,
Subbu.
Edited by: Subramanyam Sesetty on May 13, 2008 12:20 PM
‎2008 May 13 11:42 AM
> I forget to insert PERFORM PROCESS_MAIN2. statment inside the select - endselect. I think logic
> will change with the statment.
no, that is something you definitely don't want to do!
Again you should try for all entries with the result of the first recommendation. Maybe witgh a join.
And when you mix up the results from internal tables you should no forget to use binary search!!!
Siegfried
‎2008 May 13 2:39 PM
Hi All,
I tried to write code like below
SELECT * FROM EKKN INTO TABLE EKKN_1
FOR ALL ENTRIES IN GT_CSKS
WHERE KOSTL = GT_CSKS-KOSTL
AND EBELN IN S_PO
AND KOKRS = P_KOKRS
and LOEKZ <> 'X'.
LOOP AT GT_CSKS.
loop at EKKN_1 where KOSTL = GT_CSKS-KOSTL.
CLEAR: GC_EINDT,
GC_PRCTR.
GC_PRCTR = GT_CSKS-PRCTR.
PERFORM PROCESS_MAIN2 tables EKKN_1.
endloop.
ENDLOOP.
-
> Each GT_CSKS table entry contains multiple EKKN entries so i need to get all EKKN entries in sub routine PROCESS_MAIN2....Is it OK for performance....But it is taking more time than previous one.
Thanks,
‎2008 May 13 2:58 PM
> ....But it is taking more time than previous one
no wonder
you added one additional problem ...
‎2008 May 13 3:15 PM
Siegfried Boes,
Please give the solution for me.
Thanks,
Subbu.
‎2008 May 13 3:50 PM
HI,
Move the PERORM PROCESS_MAIN2 tables EKKN_1. outside the loop.
regards,
madhumitha
‎2008 May 13 4:18 PM
No Madhumitha,
I can't do like that...because i want to process the internal table (loop) values to subroutine. please check the total code what i sent at first.
Thanks,
‎2008 May 15 12:44 PM
Hi Subbu,
first of all work with field-symbols instead of header lines.
for every entry of your csks result your loop over the complete ekkn_1.
try:
read table ekkn_1 assigning <fs_ekkn_1> with table key kostl EQ <fs_csks>-kostl
binary search.
IF sy-subrc EQ 0.
ld_index = sy-tabix.
LOOP at ekkn_1 assigning <fs_ekkn_1> FROM ld_index.
IF <fs_ekkn_1>-kostl NE <fs_csks>-kostl.
EXIT.
ENDIF.
CLEAR: GC_EINDT,
GC_PRCTR.
GC_PRCTR = GT_CSKS-PRCTR.
> Why the tables-statement?
PERFORM PROCESS_MAIN2 USING <fs_ekkn_1>.
ENDLOOP.
ENDIF.
Regards,
Robert