Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Need your expertise judgement....

Former Member
0 Kudos
197

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

1 ACCEPTED SOLUTION

RichHeilman
Developer Advocate
Developer Advocate
0 Kudos
165

I like option 1. I don't like to read the same table inside a LOOP of the table. Just my opinion.

Regards,

Rich Heilman

6 REPLIES 6

Former Member
0 Kudos
165

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.

RichHeilman
Developer Advocate
Developer Advocate
0 Kudos
166

I like option 1. I don't like to read the same table inside a LOOP of the table. Just my opinion.

Regards,

Rich Heilman

Former Member
0 Kudos
165

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

Former Member
0 Kudos
165

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

Former Member
0 Kudos
165

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.

Former Member
0 Kudos
165

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.