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

Help on Read

Former Member
0 Likes
1,134

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

11 REPLIES 11
Read only

Former Member
0 Likes
1,088

<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

Read only

Former Member
0 Likes
1,088

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

Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
1,088

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

Read only

0 Likes
1,088

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

Read only

0 Likes
1,088

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.

Read only

Former Member
0 Likes
1,088

Hi,

Read statement always support '=' operator. 'CS' will not support.

Pl use loop endloop the way other Forums mate mentioned.

Cheers.

Read only

0 Likes
1,088

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

Read only

0 Likes
1,088

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

Read only

0 Likes
1,088

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.

Read only

0 Likes
1,088

Ok, if you absolutely need to use the READ statement and you want to look for record that STAT starts with "E". You can do this.




read table i_itab into w_itab
             with key objnr = w_itab-objnr
                      <b>stat+0(1) = 'E' Binary search.</b>

Regards,

Rich Heilman

Read only

Former Member
0 Likes
1,088

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