08-30-2006 9:02 AM
Hi Friends,
I have a case where I need an optimized select statement.
For Last posting FY/period: for each G/L account, Company code combination, determine the MAX (Doc. No) in BSEG, and look up the corresponding document in BKPF table to get the last posting FY/Period.
Please get back to ASAP.
Thanks,
Prakash.
08-30-2006 9:10 AM
Hello,
Use the tables BSAS and BSIS instead of BSEG and BKPF.
Regards,
naimesh
08-30-2006 9:12 AM
HI,
Try this :
data : v_belnr like belnr-bseg.
Parameters : p_GJAHR like GJAHR-BSEG,
p_BUKRS LIKE BUKRS-BSEG.
Select max(belnr) from bseg into v_belnr groupby saknr
where gjahr = p_gjahr and bukrs = p_bukrs.
check sy-subrc = 0 .
select single gjahr monat from bkpf where belnr = v_belnr.
Reward if helpful.
Regards
08-30-2006 9:13 AM
Hi,
Also refer TABLE BSIS. You cannot join tables BSEG and BKPF as BSEG is a cluster table.
Regards
08-30-2006 9:16 AM
Hi,
the last posting period you get with table <b>GLT0</b>
or fm READ_SKC1A
Message was edited by: Andreas Mann
08-30-2006 9:18 AM
Attach is the logic please replace it with corresponding field names from the table.
select glacc company fy per docno into table itab
from bseg.
sort glacc company fy descending per descending docno descending.
loop at itab.
ldocno = itab-docno.
at new company.
select fields into table ibkpf
from bkpf
where docno = ldocno.
endat.
endloop.
Regards
anurag