cancel
Showing results for 
Search instead for 
Did you mean: 

improve Query Performance

mulhimalqahtani
Discoverer
0 Kudos
157

Hello,

I want to improve this statement by adding the If condition ( that in the end ) to the statement it self.

I looked for answers and i found that there is a why to use Case statement with Sum

( I said sum because the if statement is adding )

i appreciate your support ..

SELECT nafaz safaz mafaz aafaz kostl peraf FROM faav_anlp INTO
(anlp-nafaz,anlp-safaz,anlp-mafaz,anlp-aafaz,anlp-kostl,
anlp-peraf)
WHERE bukrs = anlav-bukrs
AND gjahr = sav_gjahr
AND peraf LE sav_poper
AND anln1 = anlav-anln1
AND anln2 = anlav-anln2
AND afaber = bereich1.

CHECK anlp-kostl IN s_kostl[].


IF anlp-peraf = sav_poper.
itab_data-nafaz = itab_data-nafaz + anlp-nafaz + anlp-safaz
+ anlp-mafaz + anlp-aafaz.
ENDIF.
ENDSELECT.

View Entire Topic
DominikTylczyn
Active Contributor
0 Kudos

Hello mulhimalqahtani

Try to push the processing down to the database.First, you are doing two checks inside SELECT ... ENDSELECT:
CHECK anlp-kostl IN s_kostl[].
IF anlp-peraf = sav_poper.

They can be implemented more efficiently by putting then directly in WHERE statement.

Second, you are summarizing inside SELECT ... ENDSELECT:

itab_data-nafaz = itab_data-nafaz + anlp-nafaz + anlp-safaz + anlp-mafaz + anlp-aafaz.
You'd be better of using SELECT SUM:
SELECT SUM( nafaz + safaz + mafaz + aafaz ) FROM faav_anlp

Best regards

Dominik Tylczynski