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: 

Syntax for Reading Internal Table

Former Member
0 Kudos

Hi All,

I need to read an internaltable itab where column col1 not equal to 'XXX'.

my statment will be

read table itab with key col1 ne 'XXXX'.

since this is not working,

how can i write this statement.

Thanks in Advance

Arun

9 REPLIES 9

Former Member
0 Kudos

IF you are pretty sure that there will be only one record then do this:

LOOP AT itab INTO wa WHERE col1 NE 'XXX'

EXIT.

ENDLOOP.

Regards,

Srikanth

Former Member
0 Kudos

HI Arun,

1. Loop At ITAB.

Use this kind of syntax(logic)

instead of READ.

2. Bcos

READ will return only 1 record.

3. eg.

report abc.

data : t001 like table of t001 with header line.

select * from t001

into table t001.

break-point.

loop at t001 where bukrs <> '1000'.

endloop.

regards,

amit m.

former_member188685
Active Contributor
0 Kudos

hi arun,

read table will give only one record, so you can use..


loop at itab where col1 <> vlaue.

"after doing what ever you want..
exit.

endloop.

regards

vijay

Former Member
0 Kudos

Dear All,

In mY program I have 2 internal tables.

loop at itab1.

read itab with key col2 = itab1-col2 col1 ne 'XXXX'.

endloop.

Thanks in Advance

Arun

0 Kudos

Hi again,

1. Here also u can use second loop (preferable to read)

2.

loop at itab1.

loop at itab2 where col2 = itab1-cols and col1 <> 'XXXX'.

endloop

endloop.

regards,

amit m.

0 Kudos
loop at itab1.
loop at itab where  col2 = itab1-col2 
                  and col1 ne 'XXXX'.
"do required stuff..
exit.
endloop.

endloop.

0 Kudos

Hi Arun,

Read statement does not take NE.You have to use loop & where condition.

0 Kudos

If both internal tables are large, then the nested looping will be slow. This should be faster:


LOOP AT itab1.
* Get the first matching record
  READ TABLE itab
    WITH KEY col1 = itab1-col1
    BINARY SEARCH.
  IF itab-col2 <> 'XXXX'.
* Process the record
  ENDIF.
  itab_index = sy-tabix.
  WHILE sy-subrc = 0.
    itab_index = itab_index + 1.
* Get subsequent matching records
    READ TABLE itab INDEX itab_index.
    IF sy-subrc   = 0 AND
       itab-col1 = itab1-col1.
      IF itab-col2 <> 'XXXX'.
* Process the record
      ENDIF.
    ELSE.
* No matching records or end of internal table
      sy-subrc = 99.
    ENDIF.
  ENDWHILE.
ENDLOOP.

If one or both tables are small, then it won't make much difference.

Rob

Former Member
0 Kudos

Hi,

Read table doen't allow ne operator.

try using loop at itab where var <> 'xxx'.

Regards

Amole