‎2006 Oct 19 3:57 PM
Hi,
Need some help on read statement.
I need to read the records which starts with some character and need to specify the same in where condition as below.
read table i_itab
into w_itab
with key objnr = w_itab-objnr
stat CS 'E'
Binary search.
Getting error as should not use CS in the read statement. How to read the records which starts with letter 'E' only in this case.
Can anyone help me out in this.
Regards,
Ram
‎2006 Oct 19 3:58 PM
<b>U cannot use pattern operators in read statement. The only way is to use Loop instead of read.</b>
Loop at i_itab where objnr = w_itab-objnr
and stat(1)EQ 'E'.
do your processing
exit.
Endloop.
stat(1) would give you the start character and you can check that be E...hence it would give the records with stat starting with E.
Message was edited by: Anurag Bankley
Message was edited by: Anurag Bankley
‎2006 Oct 19 4:00 PM
Hi Ram
As there can more than one record which starts with "E", itz better you do a loop.
loop at i_itab where objnr = w_itab-objnr
and stat(1) = 'E'.
*** D0 the processing.
endloop.Kind Regards
Eswar
‎2006 Oct 19 4:02 PM
That's right you can use CS syntax in READ statement but you can with LOOP. So here is what you do, notice that this loop will only do one read because it has the EXIT statement in the loop, this is just like doing a single READ statement.
loop at i_itab into w_itab
where objnr = w_itab-objnr "<--- Not sure about this here
and stat cs 'E'.
* Do something
exit.
endloop.
Regards,
Rich Heilman
‎2006 Oct 19 4:09 PM
Hi,
The thing is i need to get the details through Read statement. Can we do this from the read statement, if so plese send me the code using read statemnt.
Regards,
Ram
‎2006 Oct 19 4:17 PM
Hi,
In that case u read the table with key key field. Then use If statement , check if it works.
eg.
data: begin of itab occurs 0,
lifnr like lfa1-lifnr,
name like lfa1-name1,
end of itab.
data: lw_itab like line of itab.
read table itab into lw_itab with
key = lw_itab-lifnr.
if lw_itab-name(1) = 'E'.
Logic
endif.
Cheers.
‎2006 Oct 19 4:10 PM
Hi,
Read statement always support '=' operator. 'CS' will not support.
Pl use loop endloop the way other Forums mate mentioned.
Cheers.
‎2006 Oct 19 4:13 PM
Hi,
Here my internal table contains OBJNR records. For each OBJNR there will many statuses. And my internal table has many records with OBJNR records. So i am using read statement. And in this i need to pick the OBJNR statues which starts with E.
Reagards,
Ram
‎2006 Oct 19 4:15 PM
Hi Ram
loop at itab where objnr = wa_itab-objnr
and estat(1) = 'E'.
exit.
endloop.The above is same a read statement, you will get only one record.
Kind Regards
Eswar
‎2006 Oct 19 4:16 PM
If you insist on using a Read statment, you can do like this:
V_KEY = 'E'.
READ TABLE I_ITAB WITH KEY STAT(1) = V_KEY.
‎2006 Oct 19 4:18 PM
‎2006 Oct 19 4:21 PM
You should be able to do a binary search to get the first record and then do indexed reads to get subsequent records.
Something like:
DATA tab_index LIKE sy-tabix.
SORT i_itab BY objnr stat.
IF sy-subrc = 0.
tab_index = sy-tabix.
ENDIF.
WHILE sy-subrc = 0.
IF w_itab-stat CS 'E'.
* process record.
ENDIF.
tab_index = tab_index + 1.
READ TABLE i_itab INDEX tab_index.
IF sy-subrc = 0.
IF i_itab-objnr <> w_itab-objnr.
sy-subrc = 9.
ENDIF.
ENDIF.
ENDWHILE.Rob
Message was edited by: Rob Burbank