04-14-2009 2:05 PM
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.
04-14-2009 2:07 PM
04-14-2009 2:09 PM
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.
04-14-2009 2:11 PM
04-14-2009 2:11 PM
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
04-14-2009 2:13 PM
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
04-14-2009 2:14 PM
@Pavan - Yes I am sorting
@Sarves- This I tried, but it doesnt work for me
04-14-2009 2:36 PM
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
04-14-2009 2:12 PM
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 ?
04-14-2009 6:08 PM
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.