Skip to Content

ABAP: Problems with constructor expression in case statement

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?

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

2 Answers

  • Dec 05, 2017 at 09: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

    Add comment
    10|10000 characters needed characters exceeded

  • Dec 05, 2017 at 05:37 PM

    Corrected in an upcoming release (but no patch).

    Thanks for notifying!

    Add comment
    10|10000 characters needed characters exceeded