Application Development 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: 

Can I use LIKE in an IF statement?

Former Member
0 Kudos

I am trying to use LIKE in my IF below and it says it sin't supported

if itab-reason_var LIKE '1%'.

APPEND DATA_PACKAGE to fitab.

else.

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi Mick,

I think you cant use LIKE in IF statement. Instead you may use the string operators like CO( Contains only ), CP ( contains Pattern) etc.

Cheers

VJ

8 REPLIES 8

Former Member
0 Kudos

No.

Rob

Former Member
0 Kudos

Hi Mick,

I think you cant use LIKE in IF statement. Instead you may use the string operators like CO( Contains only ), CP ( contains Pattern) etc.

Cheers

VJ

former_member181962
Active Contributor
0 Kudos

Do like this instead:

if itab-reason_var <b>CP</b> '1*'.

APPEND DATA_PACKAGE to fitab.

else.

cp stands for Contains pattern

0 Kudos

okay i did this except used NP but it doens't seem to be wokring because it stops at the 1st 'IF' and acts like all records don't meet the conditions

if DATA_PACKAGE-reason_var NP '1*' or

DATA_PACKAGE-reason_var NP '2*' or

DATA_PACKAGE-reason_var nP '3*' or

DATA_PACKAGE-reason_var n '4*' or

DATA_PACKAGE-reason_var n '5*'.

APPEND DATA_PACKAGE to fitab.

0 Kudos

Try this:


REPORT ztest MESSAGE-ID 00.

DATA: BEGIN OF itab OCCURS 0,
        reason_var(10),
      END OF itab.
RANGES: r_var FOR itab-reason_var.

itab-reason_var = '123'.
APPEND itab.

itab-reason_var = '456'.
APPEND itab.

r_var-sign   = 'I'.
r_var-option = 'CP'.
r_var-low    = '1*'.
APPEND r_var.

LOOP AT itab.
  IF itab-reason_var IN r_var.
    WRITE: /001 itab-reason_var, 'is included'.
  ELSE.
    WRITE: /001 itab-reason_var, 'is not included'.
  ENDIF.
ENDLOOP.

Rob

0 Kudos

Change all your 'OR's to 'AND's.

Former Member
0 Kudos

HI,

IF will not support the LIKE.

Regards

SAB

Former Member
0 Kudos

Thanks for all the help