‎2008 May 10 10:09 AM
Hi friends,
I have an internal table which having > 50000 records, but problem is its taking too much time to get executed. Pl.
chk my below code and suggests me right way. Points will be rewarded.
code.
SORT it_pos BY blart descending bschl descending.
SORT it_pos BY zuonr.
LOOP AT it_pos INTO <fs_pos> WHERE blart = 'WE' AND bschl = '96'.
IF <fs_pos>-blart = 'WE' AND <fs_pos>-bschl = '96'.
flag = 'X'.
<fs_bsis>-bukrs = <fs_pos>-bukrs.
<fs_bsis>-hkont = <fs_pos>-hkont.
<fs_bsis>-budat = <fs_pos>-budat.
<fs_bsis>-xref3 = <fs_pos>-xref3.
<fs_bsis>-zuonr = <fs_pos>-zuonr.
<fs_bsis>-blart = <fs_pos>-blart.
<fs_bsis>-bschl = <fs_pos>-bschl.
<fs_bsis>-wrbtr = <fs_pos>-dmshb.
<fs_bsis>-dcnum = <fs_pos>-xblnr.
READ TABLE it_pos INTO wa_pos1 WITH KEY bukrs = <fs_pos>-bukrs
hkont = <fs_pos>-hkont
xref3 = <fs_pos>-xref3
zuonr = <fs_pos>-zuonr
blart = <fs_pos>-blart
bschl = '86'.
IF sy-subrc = 0.
wa_pos1-bstat = 'X'.
MODIFY it_pos FROM wa_pos1 INDEX sy-tabix TRANSPORTING bstat.
<fs_bsis>-we86amt = wa_pos1-dmshb.
<fs_bsis>-wrbtr = <fs_bsis>-wrbtr + <fs_bsis>-we86amt. " added because wrbtr amt has minus sign
IF <fs_bsis>-wrbtr = 0.
CLEAR flag.
ENDIF.
ENDIF.
CLEAR wa_pos1.
READ TABLE it_pos INTO wa_pos1 WITH KEY bukrs = <fs_pos>-bukrs
hkont = <fs_pos>-hkont
xref3 = <fs_pos>-xref3
zuonr = <fs_pos>-zuonr
blart = 'RE'
bschl = '86'.
IF sy-subrc = 0.
wa_pos1-bstat = 'X'.
<fs_bsis>-invnum = wa_pos1-xblnr.
MODIFY it_pos FROM wa_pos1 INDEX sy-tabix TRANSPORTING bstat.
<fs_bsis>-re86amt = wa_pos1-dmshb.
ENDIF.
CLEAR wa_pos1.
READ TABLE it_pos INTO wa_pos1 WITH KEY bukrs = <fs_pos>-bukrs
hkont = <fs_pos>-hkont
xref3 = <fs_pos>-xref3
zuonr = <fs_pos>-zuonr
blart = 'RO'
bschl = '96'.
IF sy-subrc = 0 .
wa_pos1-bstat = 'X'.
MODIFY it_pos FROM wa_pos1 INDEX sy-tabix TRANSPORTING bstat.
<fs_bsis>-ro96amt = wa_pos1-dmshb.
<fs_bsis>-re86amt = <fs_bsis>-re86amt + <fs_bsis>-ro96amt. " added because re86amt has minus sign
IF <fs_bsis>-re86amt = 0.
<fs_bsis>-inv_amt = 0.
ELSE.
<fs_bsis>-inv_amt = <fs_bsis>-re86amt.
ENDIF.
ELSE.
<fs_bsis>-inv_amt = <fs_bsis>-re86amt.
ENDIF.
IF flag = 'X'.
MOVE <fs_bsis>-zuonr+0(10) TO <fs_bsis>-ebeln.
MOVE <fs_bsis>-zuonr+10(5) TO <fs_bsis>-ebelp.
MOVE <fs_bsis>-xref3+4(14) TO <fs_bsis>-mblnr.
APPEND <fs_bsis> TO it_bsis.
ENDIF.
CLEAR: wa_pos1, <fs_bsis>, <fs_pos>,wa_bsis1,flag,flag1.
ENDIF.
ENDLOOP.
Thanks in advance,
senthil kumar.s
‎2008 May 10 10:19 AM
just a few pointers:
declare your internal tables like TYPE SORTED TABLE OF WITH (NON-)UNIQUE KEY ...
Within loop don't check again on condition which you are already using when doing LOOP AT WHERE...
Create for beginning of this piece of code, a copy of the internal table IT_POS, which you will then read and modify.
‎2008 May 10 10:55 AM
Hi micky,
Thaks 4 ur reply.
Kindly explain me in details.
Thanks in advance.
s.senthil kumar
‎2008 May 10 12:00 PM
Hi,
While declare the internal table IT_POS, declare it as Sorted table.
DATA: IT_POS TYPE SORTED TABLE OF ........In ur code u are checking the field values double timei.e., in where condition in LOOP statement and again u are writing IF condition with the same fields.
LOOP AT it_pos INTO <fs_pos> WHERE blart = 'WE' AND bschl = '96'.
IF <fs_pos>-blart = 'WE' AND <fs_pos>-bschl = '96'.Best regards,
raam
‎2008 May 10 12:04 PM
Indeed, that's what I meant.
You are reading this IT_POS several times with field BUKRS. Then this would be a good field for declaring the key. I recon, that this field BUKRS is not unique, so declare like
TYPE SORTED TABLE OF ... WITH NON-UNIQUE KEY bukrs.
However if the total key your are reading this table with is unique better declare it like:
TYPE SORTED TABLE OF ... WITH UNIQUE KEY bukrs hkont xref3 etc.
Edited by: Micky Oestreich on May 10, 2008 1:06 PM
For reading this table IT_POS, use, like mentioned before, a copy of table IT_POS.
it_pos1_copy[] = it_pos1[]. But before doing so, sort the original table exactly like the fields you are declaring in your internal table definition WITH (NON-)UNIQUE KEY. If you violate the sort sequence, this will give a dump.
After sorting it, do another sort accorind to the fields your are using in the WHERE condition when looping.
Edited by: Micky Oestreich on May 10, 2008 1:09 PM