Skip to Content
author's profile photo
Former Member

case endcase

check this syntax

case <itab-var1>.

when 'v1' or v2 or 'v3'.

if 'v1'.

read table <t1> with key v1 = t1-v1.

if 'v2'.

read table <t1> with key v2 = t1-v2.

if 'v3'.

read table <t1> with key v3 = t1-v3.

when 'f01' or f02'.

if 'f01'.

read

if 'f02'

read.

endcase.

plz tell me can i write syntax like this.

Add comment
10|10000 characters needed characters exceeded

6 Answers

  • author's profile photo
    Former Member
    Posted on Aug 21, 2007 at 06:24 AM

    Instead of using if statement use 'when' only for each condition.

    S@meer

    Add comment
    10|10000 characters needed characters exceeded

  • author's profile photo
    Former Member
    Posted on Aug 21, 2007 at 06:30 AM

    Hi Pavan,

    U can write like this.

    case <itab-var1>.

    when 'v1'.

    read table <t1> with key v1 = t1-v1.

    when 'v2'.

    read table <t1> with key v2 = t1-v2.

    when 'v3'.

    read table <t1> with key v3 = t1-v3.

    when 'f01'.

    read

    when 'f02'

    read.

    endcase.

    Add comment
    10|10000 characters needed characters exceeded

  • author's profile photo
    Former Member
    Posted on Aug 21, 2007 at 06:31 AM

    Hi pavan!

    I think you can not use this syntax..

    According to me there are the following mistakes:

    case <itab-var1>.

    when 'v1' or v2 or 'v3'. (<b> Here you can not use Conditional operators ,

    Secondaly you can not use variables ...untill they are alredy having some values. )</b>

    if 'v1'.

    read table <t1> with key v1 = t1-v1. <b>( In this read statement you have to use a field instead of a variable. i.e you have to use var1 instead of v1. Moreover you can not do manuplations in read statement. )</b>if 'v2'.

    read table <t1> with key v2 = t1-v2.

    if 'v3'.

    read table <t1> with key v3 = t1-v3.

    when 'f01' or f02'.

    if 'f01'.

    read

    if 'f02'

    read.

    endcase.

    Hope it is clear.

    Rewards Points if helpful

    Regards

    Sourabh verma

    Add comment
    10|10000 characters needed characters exceeded

  • author's profile photo
    Former Member
    Posted on Aug 21, 2007 at 06:41 AM

    LOOP AT itab.

    CASE itab-var1.

    WHEN 'V1' OR 'V2'.

    read table t1 with key var1 = itab-var1.

    itab-slno = X.

    MODIFY itab.

    WHEN 'V3' .

    read table t1 with key var1 = itab-var1.

    itab-slno = Y.

    MODIFY itab.

    WHEN others.

    itab-slno = Z.

    MODIFY itab.

    ENDCASE.

    ENDLOOP.

    reward if useful

    Add comment
    10|10000 characters needed characters exceeded

  • author's profile photo
    Former Member
    Posted on Aug 21, 2007 at 06:45 AM

    You will have to understand that if statements and case statments replace each other.

    if itab-var1 = 'v1'.

    read table <t1> with key v1 = t1-v1.

    elseif itab-var1 = 'v2'.

    read table <t1> with key v2 = t1-v2.

    elseif itab-var1 = 'v3'.

    read table <t1> with key v3 = t1-v3.

    elseif itab-var1 = 'f01'.

    read

    elseif itab-var1 = 'f02'

    read.

    endif.

    now u can replace the above if statment with case

    case <itab-var1>.

    when 'v1'

    read table <t1> with key v1 = t1-v1.

    when 'v2'.

    read table <t1> with key v2 = t1-v2.

    when'v3'.

    read table <t1> with key v3 = t1-v3.

    when 'f01' .

    read

    when 'f02'

    read.

    endcase.

    Regards,

    Aparna

    Add comment
    10|10000 characters needed characters exceeded

  • Posted on Aug 21, 2007 at 07:07 AM

    Hi Pavan,

    • You can not have Logical condition in 'When'.

    sample code:

    DATA: v TYPE i.

    v = 1.

    CASE v.

    WHEN 1.

    WRITE: '1'.

    WHEN 2.

    WRITE: '2'.

    WHEN 3.

    WRITE: '3'.

    ENDCASE.

    Add comment
    10|10000 characters needed characters exceeded