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: 

Is it possible to do a SUM( CASE... END ) in ABAP 7.4 SP04?

Former Member
0 Kudos

Hi everyone,

We recently upgraded to EHP7 and we gain new features in ABAP.

Particularly the enhancements of open sql suits us very well with programs we are developing now.

However a SELECT I'm trying to do is not working. By the ABAP online help it should work, I think, but it is not.

I explain myself:

In the online help it states that you do a SELECT like this:

SELECT result

Where result is ... lines select_list ...

And select_list could be a col_spec

And col_spec could be aggregate

And aggregate could be SUM( [DISTINCT] col|sql_exp )

And sql_exp could be sql_case

And sql_case could be CASE operand

                        WHEN operand1 THEN result1

                       [WHEN operand2 THEN result2]

                        ...

                       [ELSE resultn]

                   END

So, I think, I can do something this:

SELECT some_field, SUM( CASE ... END ) ...

FROM some_table

GROUP BY some_field.

But the ABAP editor keep saying that there is a syntax error after CASE given the message ')'  was expected here. no matter what I write after the word CASE.

I'm sure ABAP is using the new syntax 'cause in fact I can use CASE in a SELECT, but notSUM( CASE... as I said.

So:

am I missing something?,

SUM( CASE... isn't supported and it's a glitch in the syntax help?

Maybe the ABAP 7.4 SP4 I have does not support it and a later one does?

Any hint would be highly appreciated.

J.

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Well it turns out that I'm on ABAP 740 SP05 (Not SP04).

And what I tried to do is possible but only from ABAP 740 SP08. Horst Keller give the correct hint.

The problem was that I was trying examples from ABAP Keyword Documentation which happen to be most recent help about ABAP.

So I wasn't careful to check in which SPxx the help was and which SPxx my system was. So in the end I tried examples only possible in SP08 using my system that is in SP05.

One need to be careful about this. And is easy to check: See release "ABAP - Release-Specific Changes > Changes in Release 7.40" in the ABAP Keyword Documentation and compare it with the the same path of transaction ABAPHELP of your system.

J.

6 REPLIES 6

naimesh_patel
Active Contributor
0 Kudos

CASE (SQL expression) and SUM (SQL aggregation) are not allowed together. The SUM can't obtained without GROUP BY and; Group by and SQL aggregation can't be used together.

Regards,

Naimesh Patel

0 Kudos

Exactly...

The ABAP editor complains... but the *ABAP help* says it should be possible.

Maybe an error in the ABAP documentation?

J.

0 Kudos

It uses the stricter syntax check when SQL expressions are used. I think that documentation needs to be updated. You can get the current version from here.  http://help.sap.com/abapdocu_740/en/abenopensql_strict_mode_740_sp08.htm

Regards,
Naimesh Patel

Former Member
0 Kudos

Well it turns out that I'm on ABAP 740 SP05 (Not SP04).

And what I tried to do is possible but only from ABAP 740 SP08. Horst Keller give the correct hint.

The problem was that I was trying examples from ABAP Keyword Documentation which happen to be most recent help about ABAP.

So I wasn't careful to check in which SPxx the help was and which SPxx my system was. So in the end I tried examples only possible in SP08 using my system that is in SP05.

One need to be careful about this. And is easy to check: See release "ABAP - Release-Specific Changes > Changes in Release 7.40" in the ABAP Keyword Documentation and compare it with the the same path of transaction ABAPHELP of your system.

J.

0 Kudos

So, are you saying that, CASE and GROUP-BY can be used together since SP08?

Regards,

Naimesh Patel

0 Kudos

Yes you can.

And this one is a very nice feature. For example you can replicate MB51 without haveing to use internal tables in ABAP just a SELECT of this kind.

J.