Application Development 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: 

How to Optimize

Former Member
0 Kudos

Friends,

How to optimize the following Code?

FORM ORDERINVOICE.

SELECT SINGLE * FROM KNC1 WHERE BUKRS EQ COMPANY AND KUNNR EQ

XKNB1-KUNNR AND GJAHR EQ SY-DATUM+0(4).

IF SY-SUBRC = 0.

DEBITS = KNC1-UM01S + KNC1-UM02S + KNC1-UM03S + KNC1-UM04S + KNC1-UM05S

+ KNC1-UM06S + KNC1-UM07S + KNC1-UM08S + KNC1-UM09S + KNC1-UM10S +

KNC1-UM11S + KNC1-UM12S + KNC1-UM13S + KNC1-UM14S + KNC1-UM15S +

KNC1-UM16S.

CREDITS = KNC1-UM01H + KNC1-UM02H + KNC1-UM03H + KNC1-UM04H + KNC1-UM05H

+ KNC1-UM06H + KNC1-UM07H + KNC1-UM08H + KNC1-UM09H + KNC1-UM10H +

KNC1-UM11H + KNC1-UM12H + KNC1-UM13H + KNC1-UM14H + KNC1-UM15H +

KNC1-UM16H.

ZNORMAL = DEBITS - CREDITS + KNC1-UMSAV.

ELSE.

ZNORMAL = 0.

ENDIF.

SELECT SINGLE * FROM KNC3 WHERE KUNNR EQ XKNB1-KUNNR AND

BUKRS = COMPANY AND SHBKZ = 'W' AND GJAHR = SY-DATUM+0(4).

IF SY-SUBRC = 0.

ZPDC = KNC3-SALDV + KNC3-SOLLL - KNC3-HABNL.

ELSE.

ZPDC = 0.

ENDIF.

ZVARA = LIMIT - ( ZNORMAL + ZPDC ).

ENDFORM. " ORDERINVOICE

Thanks & Regds.

Vijay

1 ACCEPTED SOLUTION

Former Member
0 Kudos

It's not really a performance problem.

But you can use the DO VARYING construct after your first check of sy-subrc. This wil make the code less spaghetti-like.

Rob

4 REPLIES 4

former_member194613
Active Contributor
0 Kudos

The first question is always 'why' zo optimize?

Run the SQL Trace, go for the summary on SQL Statements, and Check the minimal and averge

number time per record. If these are around 1ms then there is room for improvement, it is already

optimal.

see for details:

/people/siegfried.boes/blog/2007/09/05/the-sql-trace-st05-150-quick-and-easy

Here you have 2 select single with fully specified primary key, what do you want to improve?

Siegfried

Former Member
0 Kudos

It's not really a performance problem.

But you can use the DO VARYING construct after your first check of sy-subrc. This wil make the code less spaghetti-like.

Rob

Former Member
0 Kudos

Vijay,

I don't see why this piece of code would need any improvement because from a database perspective you are using 2 select single statements and all correctly mentioning the primary key. The only possible aspect that could be slowing this code is if you are calling this subroutine within a loop of table XKNB1. If that is the case select data from tables KNC1 and KNC3 into separate internal tables outside this loop and replace the select statements with read statements. However I doubt that your performance issue has much to do with this subroutine.

Former Member
0 Kudos

Hi,

Use following statment

ADD KNC1-UM01S THEN KNC1-UM02S

UNTIL KNC1-UM16S

GIVING wa_sum.

L.Velu