09-20-2008 8:47 AM
Dear Experts,
I am making monthly consumption report, In which i am getting monthly data column wise for different month , here firstly i am fetching header mblnr date according to date from mkpf then i am fetching data from mseg.....
I have same mblnr in both tables..... Now i am using read statement like this.......
sort lt_mkpf by mblnr.
SORT lt_mseg BY mblnr.
LOOP AT lt_mkpf INTO lw_mkpf.
READ TABLE lt_mseg INTO lw_mseg WITH KEY mblnr = lw_mkpf-mblnr
mjahr = lw_mkpf-mjahr
BINARY SEARCH.
When I am debugging i am getting data in lw_mkpf but sy-subrc = 4 is coming and getting wrong data in final table by using these above statements..........
where as if i am using loop like this:
SORT lt_mkpf BY mblnr.
SORT lt_mseg BY mblnr.
LOOP AT lt_mkpf INTO lw_mkpf.
v_mkpf = lw_mkpf-mblnr.
LOOP AT lt_mseg INTO lw_mseg WHERE mblnr EQ v_mkpf.
with this i am getting right data........ But it takes lot of time to execute..........
Can you please guide me am i using read statement by wrong method. which one is the correct method which one shoul be used.........
09-20-2008 8:57 AM
Hi,
Try like this.... dont sort lt_mkpf table and then try
SORT lt_mseg BY mblnr.
LOOP AT lt_mkpf INTO lw_mkpf.
READ TABLE lt_mseg INTO lw_mseg WITH KEY mblnr = lw_mkpf-mblnr binary search.
Hope it will helps
09-20-2008 8:57 AM
Hi,
Try like this.... dont sort lt_mkpf table and then try
SORT lt_mseg BY mblnr.
LOOP AT lt_mkpf INTO lw_mkpf.
READ TABLE lt_mseg INTO lw_mseg WITH KEY mblnr = lw_mkpf-mblnr binary search.
Hope it will helps
09-20-2008 8:59 AM
READ TABLE lt_mseg INTO lw_mseg WITH KEY mblnr = lw_mkpf-mblnr binary search
here ur fetching only one record.
LOOP AT lt_mseg INTO lw_mseg WHERE mblnr EQ v_mkpf.
In this u may get no.of records.
SO continue with below statement only.
Regards,
09-20-2008 9:42 AM
Hi shelly,
As to say both are same but ,
In first you used ... year condition (mjahr.)
As to say year is not requried for mkpf to mseg.
mkpf is header and mseg is Item wise ....When ever user creats GR in MIGO .. automatically both tables will trigger ...
waiting for rewards...
From
Maddy .
09-20-2008 9:46 AM
Hi,
while Sorting your Table, Sort it with both MBLNR and MJAHR.
Sure this will solve your issue.
Refer the following SAP Help Content.
standard tables are subject to a linear search. If the addition BINARY SEARCH is specified, the search is binary instead of linear. This considerably reduces the runtime of the search for larger tables (from approximately 100 entries upwards). For the binary search, the table must be sorted by the specified search key in ascending order. Otherwise the search will not find the correct row.
09-20-2008 9:50 AM
Hey Dude, sorry my previous post was not presentable,
Refer the SAP help content now, from below.
standard tables are subject to a linear search. If the addition
BINARY SEARCH is specified, the search is binary instead of
linear. This considerably reduces the runtime of the search for
larger tables (from approximately 100 entries upwards). For the
binary search, the table must be sorted by the specified
search key in ascending order. Otherwise the search will not
find the correct row.
09-21-2008 5:25 AM
Hello Shelly,
To solve the issue of read table being failed, Sort the internal table by mblnr and mjahr. say sort lt_mseg by mblnr mjahr but read the internal table mseg will give you only one data. What about the other line items. MSEG is material document line item table. So for one record in MKPF there can be more than one record in MSEG. So to consider all the line items, you need to loop on the MSEG internal table instead of read table.
LOOP AT lt_mkpf INTO lw_mkpf.
v_mkpf = lw_mkpf-mblnr.
LOOP AT lt_mseg INTO lw_mseg WHERE mblnr EQ v_mkpf.
This statement will take time and create performance issue. So rewrite the statement as
LOOP AT lt_mseg INTO lw_mseg.
read table lt_mkpf with key lw_mkpf binary search.
Regards
Farzan
09-22-2008 11:07 AM
If the second one is working, try using the following.
LOOP AT lt_mkpf INTO lw_mkpf.
v_mkpf = lw_mkpf-mblnr.
READ TABLE lt_mseg INTO lw_mseg WITH KEY mblnr = v_mkpf.