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

CHECK in CASE statements

Former Member
0 Likes
2,838

Hi all,

    Can we use IN statement in a CHECK statement? I am very new to abap. I am designing a report where I need to check wheather the value of a field lies in any of the given values. My code looks lik this..

LOOP AT it_mseg INTO wa_mseg.

   READ TABLE it_mara INTO wa_mara WITH KEY matnr = wa_mseg-matnr.

  

    CASE wa_mseg-bwart.

         WHEN '101' OR '123'.

         CHECK : wa_mara-matkl EQ '20001'.

         lv_B1 = lv_B1 + wa_mseg-bualt.

         lv_B2 = lv_B2 + wa_mseg-menge.

        

         WHEN '102' OR '122'.

        CHECK :  wa_mara-matkl IN ( ' 10001 ' , ' 20002 ' , ' 20003 ' ).

         lv_J1 = lv_J1 + wa_mseg-bualt.

         lv_J2 = lv_J2 + wa_mseg-menge.

    ENDCASE.

ENDLOOP.

I want to check wheather wa_mara-matkl has any of these values - 10001,20002,20003.

But this code is giving error saying "Incorrect logical expression".

Can anyone suggest what is wrong in the code and how to go on..

Regards,

Divya

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,890

Hi,

Create a range table using RANGES r_values FOR wa-mara-matkl.

Append values to it :

r_values-sign = 'I'.

r_values-option = 'EQ'.

r_values-low = '10001'.

append r_values.

Use this range table in your with IN.

CHECK wa_mara-matkl in r_values.

Regards,

Ashish

Hi all,

    Can we use IN statement in a CHECK statement? I am very new to abap. I am designing a report where I need to check wheather the value of a field lies in any of the given values. My code looks lik this..

LOOP AT it_mseg INTO wa_mseg.

   READ TABLE it_mara INTO wa_mara WITH KEY matnr = wa_mseg-matnr.

  

    CASE wa_mseg-bwart.

         WHEN '101' OR '123'.

         CHECK : wa_mara-matkl EQ '20001'.

         lv_B1 = lv_B1 + wa_mseg-bualt.

         lv_B2 = lv_B2 + wa_mseg-menge.

        

         WHEN '102' OR '122'.

        CHECK :  wa_mara-matkl IN ( ' 10001 ' , ' 20002 ' , ' 20003 ' ).

         lv_J1 = lv_J1 + wa_mseg-bualt.

         lv_J2 = lv_J2 + wa_mseg-menge.

    ENDCASE.

ENDLOOP.

I want to check wheather wa_mara-matkl has any of these values - 10001,20002,20003.

But this code is giving error saying "Incorrect logical expression".

Can anyone suggest what is wrong in the code and how to go on..

Regards,

Divya

2 REPLIES 2
Read only

Former Member
0 Likes
1,890

Hi Divya,

Whlie using IN in the logical expression you have to pass table. Please look in below comment from SAPhelp.com for Syntax.

---------------------------------------------------------------------------------------

log_exp - IN

 

Syntax

... operand [NOT] IN seltab ...

Effect

In a logical expression with language element IN, the conditions of a selection table are checked, that is whether an operand operand meets the conditions of the selection table or, with addition NOT, does not meet them.

--------------------------------------------------------------------------------------

So in your case, declare one internal table type SELOPT and append values as

Sign = 'I'

OPTION = 'EQ'

LOW = '10001'.

Append.

similarly for other entries and write expression as above.

Regards,

Ganesh Lathi.

Read only

Former Member
0 Likes
1,891

Hi,

Create a range table using RANGES r_values FOR wa-mara-matkl.

Append values to it :

r_values-sign = 'I'.

r_values-option = 'EQ'.

r_values-low = '10001'.

append r_values.

Use this range table in your with IN.

CHECK wa_mara-matkl in r_values.

Regards,

Ashish