on 2022 Aug 04 9:13 AM
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.
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 TylczynskiYou must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
97 | |
8 | |
6 | |
6 | |
5 | |
5 | |
5 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.