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 statement drawback

Former Member
0 Likes
1,082

Dear friends,

I am using read statement :

loop at it_bkpf.

read table it_bsid with key belnr = it_bkpf-belnr BUKRS = it_bkpf-BUKRS binary search.

if sy-subrc = 0.

endif.

endloop.

there are 2 records of same belnr in BSID. eg :

BELNR WRBTR

10003 55.50

10003 100.50

but read statement is reading only 1 record.

its possible using loop at it_bsid. but using read statement is it possible?

8 REPLIES 8
Read only

Former Member
0 Likes
1,002

Hi,

READ Statement will fetch you only one record always.

Regards,

Ankur Parab

Read only

Former Member
0 Likes
1,002

HI,

The Read statement will read the first record with the BELNR & BUKRS combination even if yo have more that one reocrds in the internal table with the these combination.

If you want to have all the record..you need use the LOOP AT ITAB WHERE <condition>.

Read only

Former Member
0 Likes
1,002

hi

read statement reads only one record at a time

if u wanna read more than one than go for loop.

Read only

Former Member
0 Likes
1,002

hi ,

if you are using Binary search with key fields if they are duplicates then read fails..

so try to avoid binary search if they are duplicate entries you are reading with key fields..

read will return only one line of record..

and sort the table before doing binary search..


loop at it_bkpf.
 read table it_bsid with key belnr = it_bkpf-belnr BUKRS = it_bkpf-BUKRS binary search.
 if sy-subrc = 0.
   loop at it_bsid where belnr = it_bkpf-belnr and BUKRS = it_bkpf-BUKRS .    "add this to get multiple
     "move to another table or modify..
   endloop.
 endif.
 endloop.

Regards,

Prabhudas

Read only

SuhaSaha
Product and Topic Expert
Product and Topic Expert
0 Likes
1,002

Hello,

But IT_BKPF will have only one record for BELNR, BUKRS & GJAHR combination.

So you can loop at IT_BSID & read IT_BKPF, simple )

LOOP AT it_bsid.
  READ TABLE it_bkpf WITH KEY belnr = it_bsid-belnr bukrs = it_bsid-bukrs BINARY SEARCH.
  IF sy-subrc = 0.
  ENDIF.
ENDLOOP.

I will not suggest nested LOOP stmt like this:

LOOP AT it_bkpf.
  LOOP AT it_bsid WHERE belnr = it_bkpf-belnr AND bukrs = it_bkpf-bukrs.

  ENDLOOP.
ENDLOOP.

Hope this helps.

BR,

Suhas

Read only

Former Member
0 Likes
1,002

Dear Friend ,

Use loop into loop and pass parameters as customer, document number fileds in the loop.

Hope this will solve your problem.

Regards,

Vijay

Read only

Former Member
0 Likes
1,002

READ statement reads single record at a time.

if u want to process all records, dont use REAd

use SELECT END SELECT.

if u want to use only READ statement, there should be item number or some other field to fetch correct record.

Regards,

ajay

Read only

Former Member
0 Likes
1,002

Hi,

If you want to use read statemeny please use the following eg code:

loop at it_vbep into xx_vbep.

          clear avbep.
          read table it_eintn into avbep with key
                            edatu = xx_vbep-edatu.

          IF sy-subrc = 0.
                         XX_WMENG_OLD_sum  =  XX_WMENG_OLD_sum + avbep-wmeng.
              XX_WMENG_AKT_sum  =  XX_WMENG_AKT_sum + xx_vbep-wmeng.
            endif.

          else.
            XX_WMENG_AKT_sum  =  XX_WMENG_AKT_sum + xx_vbep-wmeng.
          endif.

        endloop.

Regards,

Nikhil.