2005 Dec 02 10:03 PM
Hi All,
I have an internal table i_catsdb (having catsdb data).
It is defined like this:
counter
refcounter
pernr
creation_date (.... some other fields...and then)
status
Hours
<b>Now, i know that there will around 10,000 records in this internal table. This internal table is sorted on field counter.</b>
My task is to, make the hours negative based on refcounter and pernr...
for eg: If records in i_catsdb are like,
counter Ref Counter Pernr Hours status
1 100001 9.0 60
2 1 100001 8.0 60
3 2 100001 8.5 60
4 3 100001 8.2 30
then i should get the following records in i_catsdb.
counter Ref Counter Pernr Hours status
1 100001 9.0 60
2 1 100001 8.0 60
3 2 100001 8.5 60
4 3 100001 8.2 30
1 100001 -9.0 60
2 100001 -8.0 60
3 100001 -8.5 60
(In total 7 records)
Now the question is, which among the below options is opimimal in terms of performance?
Option 1: (<b>My Choice</b>) Have another internal(say i_temp) with same fields of i_catsdb (but, have pernr and counter as key fields,sorted on the same).
Loop on i_catsdb, read i_temp with pernr and counter = i_catsdb-ref_counter, and negate the hours, clear refcounter and take the record as new record into i_catsdb.
Option 2: loop on i_catdb, try reading the same internal table with pernr and counter = ref_counter, negate hours, clear ref_counter and insert as new row in i_catsdb.
Though, its a lengthy question.... i want to be more clear.
Regards,
Raj
2005 Dec 02 10:13 PM
2005 Dec 02 10:09 PM
Hi,
You can go with option 2,but at the same time no need to read the table as the values are already present,just clear the counter & use append.
2005 Dec 02 10:13 PM
2005 Dec 02 10:16 PM
I'm not sure exactly what you mean, but I would use option 1 with a bit of a change.
loop at i_catsdb.
do your processing.
append i_temp.
endloop.
append lines of i_temp to i_catsdb.
If this isn't what you mean, please let us know.
Rob
2005 Dec 03 6:04 AM
Hi,
I would also go with Option 1 and agree with Rob and Rich. Here is my contribution in terms of logic..
DATA: lv_tabix LIKE sy-tabix VALUE 1.
DO.
READ TABLE i_catsdb INDEX lv_tabix.
IF sy-subrc EQ 0.
IF NOT i_catsdb-refcounter IS INITIAL
AND NOT i_catsdb-pernr IS INITIAL.
READ TABLE i_catsdb WITH KEY refcounter = i_catsdb-refocounter
pernr = i_catsdb-pernr.
IF sy-subrc EQ 0.
CLEAR i_catsdb-refcounter.
i_catsdb-hours = i_catsdb-hours * -1.
APPEND i_catsdb TO i_temp. "Same structure
ENDIF.
ENDIF.
ELSE.
EXIT.
ENDIF.
ADD 1 TO lv_tabix.
ENDDO.
APPEND LINES OF i_temp TO i_catsdb.
Hope this helps..
Sri
Message was edited by: Srikanth Pinnamaneni
2005 Dec 03 8:01 AM
I will go with option 2,
since creating another table with 10000 records would be use less, on the other hand i i would recommend is to append the new lines into another internal table and in the end appending it to the main table since the size of the internal table being looped be increasing constantly thus increasing the runtime.
2005 Dec 03 8:27 AM
Hi,
Option 1: (My Choice) Have another internal(say i_temp) with same fields of i_catsdb (but, have pernr and counter as key fields,sorted on the same).
Loop on i_catsdb, read i_temp with pernr and counter = i_catsdb-ref_counter, and negate the hours, clear refcounter and take the record as new record into i_catsdb.
This will be useful rather than option 2.