Application Development and Automation 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: 
Read only

Case-Endcase

Former Member
0 Likes
1,175

Hi Gurus,

I have written the following code using Case and End case.

loop at it_header.

case it_header-custty.

when 'ST'.

continue.

when 'BG'.

select kunn2 into it_knvp from knvp

where parvw = 'ZB'

and kunnr = it_header-custid.

when 'PG'.

select kunnr into it_knvh from knvh

where hityp = 'A'

and hkunnr = it_header-custid.

when 'HQ'.

select kunnr into it_knvh1 from knvh

where hityp = 'A'

and hkunnr = it_header-custid.

endcase.

and I am getting the error message " when is allowed only after case".

Can you please try to help me out of this.

Thanks

Rajeev Gupta

1 ACCEPTED SOLUTION
Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
840

Looks like you select statement are screwing it up. If you wish to get data into an internal table, use the word TABLE in your select statement.



case it_header-custty.
  when 'ST'.
    continue.
  when 'BG'.
    select kunn2 into TABLE it_knvp from knvp
    where parvw = 'ZB'
    and kunnr = it_header-custid.
  when 'PG'.
    select kunnr into TABLE it_knvh from knvh
    where hityp = 'A'
    and hkunnr = it_header-custid.
  when 'HQ'.
    select kunnr into TABLE it_knvh1 from knvh
    where hityp = 'A'
    and hkunnr = it_header-custid.

endcase.


Of if you need a single record us the SINGLE word in your select statements.



case it_header-custty.
  when 'ST'.
    continue.
  when 'BG'.
    select SINGLE kunn2 into  it_knvp from knvp
    where parvw = 'ZB'
    and kunnr = it_header-custid.
  when 'PG'.
    select SINGLE kunnr into  it_knvh from knvh
    where hityp = 'A'
    and hkunnr = it_header-custid.
  when 'HQ'.
    select SINGLE kunnr into  it_knvh1 from knvh
    where hityp = 'A'
    and hkunnr = it_header-custid.

endcase.




Regards,

Rich Heilman

5 REPLIES 5
Read only

Former Member
0 Likes
840

Hi Rajeev,

Expecting that you may be you forget to put ENDLOOP for LOOP.

Thanks,

Vinay

Read only

Former Member
0 Likes
840

Endloop statement is not there.

Regards,

Sen

Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
841

Looks like you select statement are screwing it up. If you wish to get data into an internal table, use the word TABLE in your select statement.



case it_header-custty.
  when 'ST'.
    continue.
  when 'BG'.
    select kunn2 into TABLE it_knvp from knvp
    where parvw = 'ZB'
    and kunnr = it_header-custid.
  when 'PG'.
    select kunnr into TABLE it_knvh from knvh
    where hityp = 'A'
    and hkunnr = it_header-custid.
  when 'HQ'.
    select kunnr into TABLE it_knvh1 from knvh
    where hityp = 'A'
    and hkunnr = it_header-custid.

endcase.


Of if you need a single record us the SINGLE word in your select statements.



case it_header-custty.
  when 'ST'.
    continue.
  when 'BG'.
    select SINGLE kunn2 into  it_knvp from knvp
    where parvw = 'ZB'
    and kunnr = it_header-custid.
  when 'PG'.
    select SINGLE kunnr into  it_knvh from knvh
    where hityp = 'A'
    and hkunnr = it_header-custid.
  when 'HQ'.
    select SINGLE kunnr into  it_knvh1 from knvh
    where hityp = 'A'
    and hkunnr = it_header-custid.

endcase.




Regards,

Rich Heilman

Read only

Former Member
0 Likes
840

HI,

Check this corrected code

loop at it_header.

case it_header-custty.

when 'ST'.

continue.

when 'BG'.

select single kunn2 into it_knvp from knvp

where parvw = 'ZB'

and kunnr = it_header-custid.

when 'PG'.

select single kunnr into it_knvh from knvh

where hityp = 'A'

and hkunnr = it_header-custid.

when 'HQ'.

select single kunnr into it_knvh1 from knvh

where hityp = 'A'

and hkunnr = it_header-custid.

endcase.

endloop.

Thanks,

mahesh

Read only

Former Member
0 Likes
840

i don't think you can write logic statements like where parvw = 'ZB' while using when statement..it should always be when 'Value' like

when '1'

when '2'

when var1.

Hope this helps.

Rajeev