‎2017 Dec 05 8:35 AM
The following coding produces a syntax error "WHEN must be the first statement after a CASE statement.":
case reduce i( init count = 0
for s_mat in mt_materials where ( lead = abap_true )
next count = count + 1 ).
when 0.
raise exception type lcx_no_lead_mat.
when 1.
" OK.
when others.
raise exception type lcx_multiple_lead.
endcase.
Whilst this version passes without problems:
data(lv_count) = reduce i( init count = 0
for s_mat in mt_materials where ( lead = abap_true )
next count = count + 1 ).
case lv_count.
for s_mat in mt_materials where ( lead = abap_true )
next count = count + 1 ).
when 0.
raise exception type lcx_no_lead_mat.
when 1.
" OK.
when others.
raise exception type lcx_multiple_lead.
endcase.
ABAP docu says that the operand of a case statement is a general expression position, so I should be able to use reduce in this place. Where am i doing wrong?
‎2017 Dec 05 9:06 AM
What release are you working on?
The following gives a syntax warning for the last CASE down to 7.40, SP08, but not an error.
CASE VALUE i( ).
WHEN 1.
ENDCASE.
CASE REDUCE i( INIT x = 0
FOR i = 1 UNTIL i > 1
NEXT x = 1 ).
WHEN 1.
ENDCASE.
DATA itab TYPE TABLE OF i.
CASE REDUCE i( INIT x = 0
FOR wa IN itab
NEXT x = 1 ).
WHEN 1.
ENDCASE.
The warning is strange, ->development
‎2017 Dec 05 9:06 AM
What release are you working on?
The following gives a syntax warning for the last CASE down to 7.40, SP08, but not an error.
CASE VALUE i( ).
WHEN 1.
ENDCASE.
CASE REDUCE i( INIT x = 0
FOR i = 1 UNTIL i > 1
NEXT x = 1 ).
WHEN 1.
ENDCASE.
DATA itab TYPE TABLE OF i.
CASE REDUCE i( INIT x = 0
FOR wa IN itab
NEXT x = 1 ).
WHEN 1.
ENDCASE.
The warning is strange, ->development
‎2017 Dec 05 10:49 AM
I am working on 7.40 SP16. It's true that there is only a warning in your code, but as soon as you put the code inside a method, the warning becomes an error:
class lcl_a definition.
public section.
methods main.
endclass.
class lcl_a implementation.
method main.
case value i( ).
when 1.
endcase.
case reduce i( init x = 0
for i = 1 until i > 1
next x = 1 ).
when 1.
endcase.
data itab type table of i.
case reduce i( init x = 0
for wa in itab
next x = 1 ).
when 1.
endcase.
endmethod.
endclass.
‎2017 Dec 05 10:52 AM
‎2017 Dec 05 5:37 PM
Corrected in an upcoming release (but no patch).
Thanks for notifying!