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

Read internal table with key not equal to

Former Member
0 Likes
58,297

Hi,

How can I read internal table with key not equal to some other field.

Basically in read statement we can read only fields equal to others fields.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
20,314
  • Read statement does not provide you with this flexibility of providing key with not equal to.

  • Instead what you can do is use

  • You need to sort the table according to your key.

SORT ......................

LOOP at it_itab into wa_itab where field ne field.

  • your code here.

  • since in read only the first entry of given keys is fetched write an exit after your code.

EXIT.

ENDLOOP

This might serve your purpose.

Thanks & Regards,

Lalit Mohan Gupta

Hi,

How can I read internal table with key not equal to some other field.

Basically in read statement we can read only fields equal to others fields.

10 REPLIES 10
Read only

Former Member
0 Likes
20,314

instead use loop ... endloop.

Read only

kiran_k8
Active Contributor
0 Likes
20,314

Shilpa,

sort itab1 by vbeln.

loop at itab1

read table itab2 with key vbeln = itab1-vbeln. binary search

if sy-subrc = 0.

your logic

endif.

endloop.

the read statement of itab2 will read the Sales order details w.r.t the sales order in itab1.

K.Kiran.

Read only

Former Member
0 Likes
20,314

Its Not possible....in read statement at atime we can pick up only row!!

we can pick up either the least value...u can use

select ..end select

regards

sas

Read only

Former Member
0 Likes
20,314

Read internal table with key field1 = another field binary search.

If sy-subrc NE 0.

UR code....

Endif.

Read only

faisalatsap
Active Contributor
0 Likes
20,314

Hi,

I think you can't use not equal in Read Table Because there might be possibility for more than one Record in this way so you must Specify Key Equal to Get one Record,

It work Just like Select Single.

Kind Regards,

Faisal

Read only

Former Member
0 Likes
20,314

HI,

You can sort the itab by the required field. and use loop and endloop

sort itab by field1.

loop at itab.

if field1 <> 'value'.

<your Logic>

endif.

endloop.

Read only

faisalatsap
Active Contributor
0 Likes
20,314

Hi,

Test the following Code you can Use Loop at for this But not Read Table

DATA: BEGIN OF it_test OCCURS 10,
  f1(4),
  f2 TYPE i,
  f3(2),
  END OF it_test.

DATA: it_test2 LIKE STANDARD TABLE OF it_test WITH HEADER LINE.
it_test-f1 = '1000'.
it_test-f2 = 10.
it_test-f3 = 'B'.
APPEND it_test TO it_test.
it_test-f1 = '2000'.
it_test-f2 = 10.
it_test-f3 = 'A'.
APPEND it_test TO it_test.
it_test-f1 = '1000'.
it_test-f2 = 10.
it_test-f3 = 'B'.
APPEND it_test TO it_test.
it_test-f1 = '1000'.
it_test-f2 = 10.
it_test-f3 = 'A'.
APPEND it_test TO it_test.
it_test-f1 = '1000'.
it_test-f2 = 40.
it_test-f3 = 'A'.
APPEND it_test TO it_test.

LOOP AT it_test INTO it_test WHERE f3 NE 'A'.
  WRITE: / it_test-f1, it_test-f2, it_test-f3.
ENDLOOP.

Kind Regards,

Faisal

Read only

I355602
Product and Topic Expert
Product and Topic Expert
0 Likes
20,314

Hi,

No READ statement will not work in that case.

Instead use:-


loop at itab.
  if <itab-field1> ne '<value>'. "your condition
    "your code
  endif.
endloop.

Hope this solves your problem.

Thanks & Regards,

Tarun Gambhir

Read only

Former Member
0 Likes
20,314

Hi,

Use

Loop at itab into wa_itab where (ur not equal condition).

Delete itab where field = wa_itab-field.

Endloop.

Read only

Former Member
0 Likes
20,315
  • Read statement does not provide you with this flexibility of providing key with not equal to.

  • Instead what you can do is use

  • You need to sort the table according to your key.

SORT ......................

LOOP at it_itab into wa_itab where field ne field.

  • your code here.

  • since in read only the first entry of given keys is fetched write an exit after your code.

EXIT.

ENDLOOP

This might serve your purpose.

Thanks & Regards,

Lalit Mohan Gupta