‎2005 Dec 21 11:45 AM
Hi!
Please review the following program,
LOOP AT TG_PRICE INTO WA_PRICE.
CLEAR WA_VBELN.
READ TABLE TG_VBELN INTO WA_VBELN WITH KEY KNUMV = WA_PRICE-KNUMV
POSNR = WA_PRICE-KPOSN.
IF SY-SUBRC = 0.
WA_PRICE-VKORG = WA_VBELN-VKORG.
WA_PRICE-VBELN = WA_VBELN-VBELN.
WA_PRICE-POSNR = WA_VBELN-POSNR.
WA_PRICE-MATNR = WA_VBELN-MATNR.
WA_PRICE-MAKTX = WA_VBELN-MAKTX.
WA_PRICE-ERNAM = WA_VBELN-ERNAM.
WA_PRICE-ERDAT = WA_VBELN-ERDAT.
MODIFY TG_PRICE FROM WA_PRICE.
DELETE TABLE TG_VBELN FROM WA_VBELN.
ELSE.
DELETE TABLE TG_PRICE FROM WA_PRICE.
ENDIF.
ENDLOOP.
comments: internal table TG_PRICE has about 20,000 records and TG_VBELN has about 70,000.
this segment run spent too much time.
Comparing the following program, the speed is more faster.
LOOP AT TG_PRICE INTO WA_PRICE.
CLEAR WA_KONP.
SELECT SINGLE KNUMH
KBETR
KONWA
KPEIN
KMEIN
INTO WA_KONP
FROM KONP
WHERE KNUMH = WA_PRICE-KNUMH.
IF SY-SUBRC = 0.
WA_PRICE-KBETR_FROM = WA_KONP-KBETR_FROM.
WA_PRICE-KONWA_FROM = WA_KONP-KONWA_FROM.
WA_PRICE-KPEIN_FROM = WA_KONP-KPEIN_FROM.
WA_PRICE-KMEIN_FROM = WA_KONP-KMEIN_FROM.
VL_AMOUNT = WA_PRICE-KBETR_FROM.
CALL FUNCTION 'CURRENCY_AMOUNT_SAP_TO_DISPLAY'
EXPORTING
CURRENCY = WA_PRICE-KONWA_FROM
AMOUNT_INTERNAL = VL_AMOUNT
IMPORTING
AMOUNT_DISPLAY = VL_RATE
EXCEPTIONS
INTERNAL_ERROR = 1
OTHERS = 2 .
IF SY-SUBRC = 0.
WA_PRICE-PRICE_FROM = VL_RATE.
ENDIF.
MODIFY TG_PRICE FROM WA_PRICE.
ELSE.
DELETE TABLE TG_PRICE FROM WA_PRICE.
ENDIF.
ENDLOOP.
commmets: internal table TG_PRICE has also 20,000 records. Within the Loop, there is system table selection clause. it should be slower than the previous program. But why the previous is more slower, is there something wrong with the READ clasue or any others?
Many thanks,
Aries
‎2005 Dec 21 11:49 AM
Hi Aries,
Use READ with BINARY SEARCH option to speed up the first Program and be sure to sort the itab with the key you are using in the READ. Also, the sy-subrc check should be before PSONR = WA_PRICE-KPOSN.
Regards,
Suresh Datti
‎2005 Dec 21 11:49 AM
Hi Aries,
Use READ with BINARY SEARCH option to speed up the first Program and be sure to sort the itab with the key you are using in the READ. Also, the sy-subrc check should be before PSONR = WA_PRICE-KPOSN.
Regards,
Suresh Datti
‎2005 Dec 21 12:07 PM
Hi Suresh,
PSONR = WA_PRICE-KPOSN is also a key for READ clause.
by the way, the internal tables have been sorted.
After using BINARY SEARCH, the speed is faster acually.
But still much slower than the second program LOOP with select clause. In my opinion, the operation with internal table should much faster than operation with select system table. Do you have any other ideas?
Many thanks,
Aries
‎2005 Dec 21 12:11 PM
Hi Aries,
The second Program runs faster even if you are hitting the database for each loop pas due to the SELECT SINGLE. This statement has the complete key so retrieves faster. Can you pass the complete key with READ statement in the first program? may be that will show some improvement. Also,did you try out Andreas tip?
Regards,
Suresh Datti
‎2005 Dec 21 12:52 PM
Hi Suresh,
The complete READ statment is as follows:
READ TABLE TG_VBELN INTO WA_VBELN
WITH KEY KNUMV = WA_PRICE-KNUMV
POSNR = WA_PRICE-KPOSN.
Hi Andreas,
The two internal tables have already been sorted as follows:
SORT TG_PRICE BY KNUMV KPOSN.
SORT TG_VBELN BY KNUMV POSNR.
And these two internal table are defined as follows:
Price
TYPES:BEGIN OF YS_PRICE,
KNUMV TYPE KNUMV, "Number of the document condition
KPOSN TYPE KPOSN, "Condition item number
KNUMH TYPE KNUMH, "Condition record number
VKORG TYPE VKORG, "Sales orgnazation
VBELN TYPE VBELN_VA, "Order Number
POSNR TYPE POSNR_VA, "Item number
MATNR TYPE MATNR, "Material Number
MAKTX TYPE MAKTX, "Material Description
KBETR_FROM TYPE KBETR_KOND,"Changed From Price
KONWA_FROM TYPE KONWA, "Price Unit
KPEIN_FROM TYPE KPEIN, "Per
KMEIN_FROM TYPE KMEIN, "Per
KBETR_TO TYPE KBETR_KOND,"Changed to Price
KONWA_TO TYPE KONWA, "Price Unit
KPEIN_TO TYPE KPEIN, "Per
KMEIN_TO TYPE KVMEI, "Per
ERNAM TYPE ERNAM, "Created by
ERDAT TYPE ERDAT, "Date Created
PRICE_FROM TYPE P DECIMALS 2,
PRICE_TO TYPE P DECIMALS 2,
END OF YS_PRICE.
Sales order
TYPES: BEGIN OF YS_VBELN,
KNUMV LIKE VBAK-KNUMV,"Number of the document condition
VKORG TYPE VKORG, "Sales orgnazation
VBELN TYPE VBELN_VA, "Order Number
POSNR TYPE POSNR_VA, "Item number
MATNR TYPE MATNR, "Material Number
MAKTX TYPE MAKTX, "Material Description
ERNAM TYPE ERNAM, "Created by
ERDAT TYPE ERDAT, "Date Created
END OF YS_VBELN.
DATA: TG_PRICE TYPE YS_PRICE OCCURS 0,
TG_VBELN TYPE YS_VBELN OCCURS 0.
Do you have any ideas?
Many thanks,
Aries
‎2005 Dec 21 11:50 AM
Hi,
make table TG_VBELN a <b>sorted</b> (and when unique - a <b>hashed</b> table )
-> there will be much better performance !
Andreas
‎2005 Dec 21 12:28 PM
Hi for the second program make the changes as mentioned below.
1.dont use select inside the loop.
2. keep the select outside the loop.
then ur second program looks like this.
SELECT SINGLE KNUMH
KBETR
KONWA
KPEIN
KMEIN
INTO table WA_KONP
FROM KONP
for all entries in WA_PRICE
WHERE KNUMH = WA_PRICE-KNUMH.
sort wa_konp by knumh.
LOOP AT TG_PRICE INTO WA_PRICE.
CLEAR WA_KONP.
read table wa_konp with key tg_price-knumh = wa_konp-knumh binary search.
IF SY-SUBRC = 0.
WA_PRICE-KBETR_FROM = WA_KONP-KBETR_FROM.
WA_PRICE-KONWA_FROM = WA_KONP-KONWA_FROM.
WA_PRICE-KPEIN_FROM = WA_KONP-KPEIN_FROM.
WA_PRICE-KMEIN_FROM = WA_KONP-KMEIN_FROM.
VL_AMOUNT = WA_PRICE-KBETR_FROM.
CALL FUNCTION 'CURRENCY_AMOUNT_SAP_TO_DISPLAY'
EXPORTING
CURRENCY = WA_PRICE-KONWA_FROM
AMOUNT_INTERNAL = VL_AMOUNT
IMPORTING
AMOUNT_DISPLAY = VL_RATE
EXCEPTIONS
INTERNAL_ERROR = 1
OTHERS = 2 .
IF SY-SUBRC = 0.
WA_PRICE-PRICE_FROM = VL_RATE.
ENDIF.
MODIFY TG_PRICE FROM WA_PRICE.
ELSE.
DELETE TABLE TG_PRICE FROM WA_PRICE.
ENDIF.
ENDLOOP.
Satish
‎2005 Dec 21 2:40 PM
Try to use the following code
FIELD-SYMBOLS <F_PRICE> LIKE WA_PRICE.
DATA : W_TABIX LIKE SY-TABIX,
W_TABIX1 LIKE SY-TABIX.
LOOP AT TG_PRICE ASSIGNING <F_PRICE>.
W_TABIX1 = SY-TABIX.
CLEAR WA_VBELN.
CLEAR W_TABIX.
READ TABLE TG_VBELN INTO WA_VBELN WITH KEY KNUMV = <F_PRICE>-KNUMV BINARY SEARCH.
IF SY-SUBRC = 0.
W_TABIX = SY-TABIX.
ENDIF.
POSNR = WA_PRICE-KPOSN.
IF SY-SUBRC = 0.
<F_PRICE>-VKORG = WA_VBELN-VKORG.
<F_PRICE>-VBELN = WA_VBELN-VBELN.
<F_PRICE>-POSNR = WA_VBELN-POSNR.
<F_PRICE>-MATNR = WA_VBELN-MATNR.
<F_PRICE>-MAKTX = WA_VBELN-MAKTX.
<F_PRICE>-ERNAM = WA_VBELN-ERNAM.
<F_PRICE-ERDAT = WA_VBELN-ERDAT.
*MODIFY TG_PRICE FROM WA_PRICE. "NO NEED FOR THIS WITH
*FIELD SYMBOL
*DELETE TABLE TG_VBELN FROM WA_VBELN.
DELETE TABLE TG_VBELN INDEX W_TABIX.
ELSE.
DELETE TABLE TG_PRICE INDEX W_TABIX1.
ENDIF.
ENDLOOP.
I think it will make the code much faster because in your code three things are taking time.
(1) read without binary search
(2) Delete ( it traverse the whole table sequentially to find record to delete which has the same key values as in the header table
(3) It transports the data in header of the TG_PRICE table and then transport it back to the row to update it with modify statement. With 'assigning field symbol' you are directly working on row level
Please let me know how it works.
‎2005 Dec 22 5:20 AM
Hi Sharad,
After using filed symbols, it is faster than before actually. Thanks.
Regards,
Aries