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: 

@ READ Statement:

Former Member
0 Kudos

I have an Internal table with MULTIPLE records for ONE Pernr and against each PERNR there is a Unique Date Stamp.

Please advice how should my Read statement look like.

READ TABLE it_tab1 WITH KEY pernr = l_t_master-pernr

eff_date = l_t_master-eff_date.

    • BINARY SEARCH.

9 REPLIES 9

former_member205763
Active Contributor
0 Kudos

what do u want to do, can explain a bit more

Former Member
0 Kudos

I have an Internal table with MULTIPLE records for ONE Pernr and against each PERNR there is a Unique Date Stamp.

Please advice how should my Read statement look like.

READ TABLE it_tab1 WITH KEY pernr = tab1-pernr

eff_date = ltab1-pernr-eff_date BINARY SEARCH.

The above READ statememnt seems to be checking only on the frist pernr record and not the subsequent ones.

Pls let me know where am I going wrong.

0 Kudos

are you SORITNG the internal table before READING?

Regards,

Pavan

0 Kudos

HI,

sort it_tab1.

loop at itab into wa.
READ TABLE it_tab1 WITH KEY pernr = tab1-pernr
eff_date = ltab1-pernr-eff_date BINARY SEARCH.
endloop.

use the read statement in the loop so it reads all the records

thanks

Sarves

0 Kudos

Hi Anand,


the statment you written is correct..

but sort the internal table with Perner timestamp first and then read the table it will work..

sort it_tab1 by pernr eff_date .   "<<write this statement

READ TABLE it_tab1 WITH KEY pernr = tab1-pernr
                                             eff_date = ltab1-pernr-eff_date  BINARY SEARCH.
if sy-subrc = o.
--<<< move the read value's to respected output
endif.


Regards,

Prabhudas

0 Kudos

@Pavan - Yes I am sorting

@Sarves- This I tried, but it doesnt work for me

0 Kudos

read table will fetch only first record tht it encounters for given set of selection criteria,

so use loop at tab1 with where condition


loop at it_tab1 into wa where pernr = tab1-pernr and eff_date = ltab1-pernr-eff_date.

Edited by: Kartik Tarla on Apr 14, 2009 7:07 PM

Former Member
0 Kudos

Hi,

You can read the data inthis way..

LOOP AT PA0001 WHERE BEGDA LE l_t_master-eff_date
                                             AND ENDDA GE l_t_master-eff_date.
" Do processing for all the records which satisfy the where clause.
ENDLOOP.
IF SY-SUBRC EQ 0.
" If you want to get the latest record do processing here
ENDIF.

What data you looking for ?

Former Member
0 Kudos
sort it_tab1 by pernr.
describe lines of it_itab1 into l_lines.
READ TABLE it_tab1 WITH KEY pernr = l_t_master-pernr.
l_tabix = sy-tabix.
do l_lines.
READ TABLE it_tab1 index l_tabix.
if it_itab1-eff_date = l_t_master-eff_date.
  " your processing statements.
  exit.
endif.
l_tabix = l_tabix + 1.
enddo.

This code works and is performance wise better.

This will satisfy your requirement.

Regards,

Lalit Mohan Gupta.