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

'IF' Statement with 'IN' relation operator and Ranges

maksingh8
Explorer
0 Likes
4,846

Hi Friends,

I tried to search for it in Google and answers.sap. But couldn't find any help. Thus raising this question.

My doubt is I am trying to using RANGES with IF statement. I got a ranged created from TVARVC table. Below is the code.

REPORT ztest.

DATA: ltr_bukrs TYPE RANGE OF bukrs,
lv_bukrs TYPE bukrs VALUE '1000'.

SELECT sign,
opti,
low,
high
INTO TABLE @ltr_bukrs
FROM tvarvc
WHERE name = 'SOME_NAME' AND type = 'S'.

IF lv_bukrs IN ltr_bukrs.
WRITE: 'Success'.
ENDIF.

If I execute this code, I am getting output as 'Success' even when the range table ltr_bukrs is initial.
Can someone please highlight what I am doing wrong?

3 REPLIES 3
Read only

geert-janklaps
SAP Mentor
SAP Mentor
2,912

Hi,

A range table that is initial will always return true in this context. Would be the same when you leave a select-option empty on a selection-screen, this doesn't apply a filter to the result.

Maybe change the if statement to:

IF lv_bukrs IN ltr_bukrs AND ltr_bukrs IS NOT INITIAL.
  WRITE: 'Success'.
ENDIF.
Read only

2,912

And quote from the official doc - rel_exp - Tabular Relational Operator IN :

  • If the ranges table is initial, the comparison expression is always true.
Read only

matt
Active Contributor
2,912

Read the abap help on RANGE OF and SELECT-OPTIONS.