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

Like Condition in Loop at itab

muhammad_sohail
Participant
10,349

Dear Experts,

I want to use the like condition in loop at itab, It is not possible to use like condition in loop at itab, then how I can accomplish my task?

Example:

*LOOP AT itab where field1 like '5%'.*               " It is not possible
  SELECT 
       --- 
   FROM 
       ---
   INTO CORRESPONDING FIELDS OF itab2
   WHERE 
       ---
    APPEND: itab2.
    CLEAR: itab2.
  ENDSELECT.
ENDLOOP.

Thanks and Regards,

Sohail

1 ACCEPTED SOLUTION
Read only

Former Member
4,116

TRY WITH THE FOLLOWING


LOOP AT ITAB WHERE FIELD1 CP '5%'. " U CAN ALSO USE CS ( CONTAINS STRING ) , CP IS CONTAINS PATTERN

SELECT 
       --- 
   FROM 
       ---
   INTO CORRESPONDING FIELDS OF itab2
   WHERE 
       ---
    APPEND: itab2.
    CLEAR: itab2.
  ENDSELECT.


ENDLOOP.

Dear Experts,

I want to use the like condition in loop at itab, It is not possible to use like condition in loop at itab, then how I can accomplish my task?

Example:

*LOOP AT itab where field1 like '5%'.*               " It is not possible
  SELECT 
       --- 
   FROM 
       ---
   INTO CORRESPONDING FIELDS OF itab2
   WHERE 
       ---
    APPEND: itab2.
    CLEAR: itab2.
  ENDSELECT.
ENDLOOP.

Thanks and Regards,

Sohail

4 REPLIES 4
Read only

Former Member
4,117

TRY WITH THE FOLLOWING


LOOP AT ITAB WHERE FIELD1 CP '5%'. " U CAN ALSO USE CS ( CONTAINS STRING ) , CP IS CONTAINS PATTERN

SELECT 
       --- 
   FROM 
       ---
   INTO CORRESPONDING FIELDS OF itab2
   WHERE 
       ---
    APPEND: itab2.
    CLEAR: itab2.
  ENDSELECT.


ENDLOOP.

Read only

Former Member
0 Likes
4,116

Hello

Try this:


LOOP AT itab where field1(1) EQ '5'. " It is  possible
  SELECT 
       --- 
   FROM 
       ---
   INTO CORRESPONDING FIELDS OF itab2
   WHERE 
       ---
    APPEND: itab2.
    CLEAR: itab2.
  ENDSELECT.
ENDLOOP.

Read only

former_member156446
Active Contributor
0 Likes
4,116

try like this :

data: it_itab1 type standard table of selopt,
          s_itab1 type selopt.

s_itab1-sign = 'I'.
s_itab1-options = 'BT'.
s_itab1-low = '5*'. " later if your requirement changes its, just another append away to do that...
append w_itab1 to it_itab1.
clear w_itab1.

LOOP AT itab where field1 in it_itab1.

Read only

muhammad_sohail
Participant
0 Likes
4,116

Very Helpful Answers from You guys, But I solve the problem with another field Condition.

Thanks you Very Much.