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: 
Read only

optimize code

Former Member
0 Likes
434

please give the optimise code for following and please give reason.

2.C4A = '000'.

SELECT * FROM T100

WHERE SPRSL = 'D' AND

ARBGB = '00'.

CHECK: T100-MSGNR > C4A.

C4A = T100-MSGNR.

ENDSELECT.

3. LOOP AT TAB.

IF TAB-FLAG IS INITIAL.

TAB-FLAG = 'X'.

ENDIF.

MODIFY TAB.

ENDLOOP.

4.

DESCRIBE TABLE: TAB1 LINES L1,

TAB2 LINES L2.

IF L1 <> L2.

TAB_DIFFERENT = 'X'.

ELSE.

TAB_DIFFERENT = SPACE.

LOOP AT TAB1.

READ TABLE TAB2 INDEX SY-TABIX.

IF TAB1 <> TAB2.

TAB_DIFFERENT = 'X'. EXIT.

ENDIF .

ENDLOOP.

ENDIF.

IF TAB_DIFFERENT = SPACE.

" ...

ENDIF.

5. LOOP AT TAB_SRC.

APPEND TAB_SRC TO TAB_DEST.

ENDLOOP

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
415

Hi Javed,

For the code no 2. do the following:

1. Keep the no of database access small.

2. Keep the data transfer between the database and the application server small.

so, you can do the same using internal tables for the entire operation.

C4A = '000'.

select *

from T100

into table lt_itab

where SPRSL = 'D'

and ARBGB = '00'.

if sy-subrc <> 0.

// error code

endif.

loop at lt_itab.

if lt_itab-msgnr > C4A.

C4A = T100-MSGNR.

Modify lt_itab from wa_itab where msgnr GE C4A.

if sy-subrc <> 0.

// error code

endif.

endif.

endloop.

Else you can modify the existing code as follows:

C4A = '000'.

SELECT * FROM T100

WHERE SPRSL = 'D' AND

ARBGB = '00'.

if T100-MSGNR > C4A.

C4A = T100-MSGNR.

endif.

ENDSELECT.

For the no 3 code - Use an Array operation on the same rather than row by row.

For the no 4 code - It looks fine to me...

For the no 5 code - use append lines of Itab instead of single append.

Thanks,

Samantak,

<b>Rewards for useful answers.</b>

3 REPLIES 3
Read only

Former Member
0 Likes
416

Hi Javed,

For the code no 2. do the following:

1. Keep the no of database access small.

2. Keep the data transfer between the database and the application server small.

so, you can do the same using internal tables for the entire operation.

C4A = '000'.

select *

from T100

into table lt_itab

where SPRSL = 'D'

and ARBGB = '00'.

if sy-subrc <> 0.

// error code

endif.

loop at lt_itab.

if lt_itab-msgnr > C4A.

C4A = T100-MSGNR.

Modify lt_itab from wa_itab where msgnr GE C4A.

if sy-subrc <> 0.

// error code

endif.

endif.

endloop.

Else you can modify the existing code as follows:

C4A = '000'.

SELECT * FROM T100

WHERE SPRSL = 'D' AND

ARBGB = '00'.

if T100-MSGNR > C4A.

C4A = T100-MSGNR.

endif.

ENDSELECT.

For the no 3 code - Use an Array operation on the same rather than row by row.

For the no 4 code - It looks fine to me...

For the no 5 code - use append lines of Itab instead of single append.

Thanks,

Samantak,

<b>Rewards for useful answers.</b>

Read only

Former Member
0 Likes
415

Q2 looks to be trying to get the highest value of MSGNR for message library '00'... so rather than read every matching record from the table I'd pick something like:

select max( msgnr ) into c4a
   from t100 
   where sprsl = 'D'                 
   and   arbgb = '00'.

Q3 could probably be achieved without the loop via something like

tab-flag = 'X'.
modify tab transporting flag
  where flag is initial.

Q4 can be done simply without loops by comparing the body of the tables via

if tab1[] = tab2[]. 
...
endif.

Q5 save the loops again..

append lines of tab_src to tab_dest.

Read only

Former Member
0 Likes
415

I have seen this example several times, and I do not understand what is good

for? To compare 2 tables is more complicated, the knowledge that the number

of lines is equal helps nothing, the sort order is completely neglected, and

both tables can have the same number of lines, but different different keys.

The coding here works only for identically sorted tables, where a non-key field

is different. If the number of lines is different, then it provides no solution.

DESCRIBE TABLE: TAB1 LINES L1,

TAB2 LINES L2.

IF L1 <> L2.

TAB_DIFFERENT = 'X'.

ELSE.

TAB_DIFFERENT = SPACE.

LOOP AT TAB1.

READ TABLE TAB2 INDEX SY-TABIX.

IF TAB1 <> TAB2.

TAB_DIFFERENT = 'X'. EXIT.

ENDIF .

ENDLOOP.

ENDIF.

IF TAB_DIFFERENT = SPACE.

" ...

ENDIF.

2. Don't use check inside select ... endselect, add the condition the where clause

3. Use assigning and modify directly

4. What is the task? See above.

5 is o.k.

Siegfried