09-09-2008 5:16 AM
hi all,
I want to retrive the latest posting date from table MKPF. Here I am using the MARD,MSEG,MKPF tables to get the latest posting date.
if not it_mard[] is initial.
select amblnr amjahr amatnr awerks algort bbudat
into table it_mseg_mkpf
from mseg as a mkpf as b
on amblnr = bmblnr
and amjahr = bmjahr
for all entries in it_mard
where a~matnr = it_mard-matnr
and a~werks = it_mard-werks
and a~lgort = it_mard-lgort.
if sy-subrc eq 0.
sort it_mseg_mkpg decending by matnr werks lgort budat.
endif.
loop at it_mard.
clear it_mkpf_mseg.
read table it_mseg_mkpf with key matnr = it_mard-matnr
werks = it_mard=werks
lgort = it_mard-lgort
binary search.
if sy-subrc eq 0.
it_final-budat = it_mseg_mkpf-budat.
endif.
endloop.
from the above code i need to rereive the latest posting date , but when I am reading from internal table it is giving the sy-subrc is 4. i know when we use binary search , the standard table should be ascedning order. but here I need to use descedning order.
please hhelp i this.
regards,
Ajay
09-09-2008 5:38 AM
Hello
I have done so:
sort it_mseg_mkpg by matnr werks lgort budat.
loop at it_mard.
loop at it_mseg_mkpf where matnr = it_mard-matnr
and werks = it_mard=werks
and lgort = it_mard-lgort.
at end of budat.
it_final-budat = it_mseg_mkpf-budat.
endat.
endloop.
endloop.
09-09-2008 5:47 AM
Hi,
1. Check Storage location (LGORT) value available in the internal
table it_mseg_mkpf. Some case no value.
2. Remove the binary search after u try again. Like below.
loop at it_mard.
clear it_mkpf_mseg.
read table it_mseg_mkpf with key matnr = it_mard-matnr
werks = it_mard=werks
lgort = it_mard-lgort.
if sy-subrc eq 0.
it_final-budat = it_mseg_mkpf-budat.
endif.
endloop.
3. sort it_mseg_mkpg DESCENDING BY budat matnr werks lgort.
4. For all material (it_mard) may be or may not be there in the MSEG table.
So for some case SY-SUBRC = 4 will give.
Thanks,
Durai.V
Edited by: Durai V on Sep 9, 2008 6:50 AM