2008 Jan 03 7:13 AM
Hi,
i need to pick the data form 2 tables ( BSEG and BKPF) from BSEG - KUNNR,GSBER, BUKRS and from BKPF- BUDAT , BLDAT.
How to pick the data and on which field basis i need to pick the data
2008 Jan 03 7:20 AM
BSEG is a pooled table so inner join is not possible so try this.
i m giving one example,
change as per your requirement,
select belnr gjahr budat
into corresponding fields of table t_head_expense
from bkpf
where budat in posdate
.
select belnr buzei gjahr hkont dmbtr shkzg sgtxt
into corresponding fields of table t_expense
from bseg
for all entries in t_head_expense
where belnr = t_head_expense-belnr and gjahr = t_head_expense-gjahr.
Regards,
Arpit
2008 Jan 03 7:16 AM
what r u r inputs...
the link beteween these 2 tables are belnr,mjahr,bukrs
first go to header-bkpf and then bseg
2008 Jan 03 7:21 AM
2008 Jan 03 7:29 AM
select bukrs,belnr,gjahr from bkpf
into it_bkpf where
budat = pa_budat "input
and bukrs = pa_bukrs.
select < your needed fields> into table itab from bseg for all entries in it_bkpf
where belnr = it_bkpf-belnr
and gjahr = it_bkpf-gjahr
and bukrs = it_bkpf-bukrs.
and kunnr = pa_kunnr "<--inputs
2008 Jan 03 7:20 AM
BSEG is a pooled table so inner join is not possible so try this.
i m giving one example,
change as per your requirement,
select belnr gjahr budat
into corresponding fields of table t_head_expense
from bkpf
where budat in posdate
.
select belnr buzei gjahr hkont dmbtr shkzg sgtxt
into corresponding fields of table t_expense
from bseg
for all entries in t_head_expense
where belnr = t_head_expense-belnr and gjahr = t_head_expense-gjahr.
Regards,
Arpit
2008 Jan 03 8:26 AM
i write like this:
select belnr budat bldat
into corresponding fields of table It_BKPF
from bkpf
where budat in SO_BUDAT.
IF IT_BKPF IS NOT INITIAL.
select bukrs belnr shkzg gsber dmbtr sgtxt kunnr
into corresponding fields of table IT_BSEG
from bseg
for all entries in IT_BKPF
where belnr = IT_BKPF-belnr.
ENDIF.
i am not getiing output for posting date , document date , currency, document no
2008 Jan 03 7:22 AM
you can select from BKPF-BELNR,BUKRS and from
BSEG-BELNR,BUKRS.
and you can relate both tables based on these fields.
2008 Jan 03 7:25 AM
first select the data from bkpf
use for all entries and retrieve the information form bseg based on bukrs, belnr and gjahr
reward point if it is useful
Madhavi
2008 Jan 03 7:28 AM
You could link BKPF and BSEG via the primary keys of BKPF
BUKRS
BELNR
GJAHR
But BSEG is a cluster, so some "join" options are unavailable, and if you use some ways to bypass this, performances will be very poor as the database is unable to optimize selection on BSEG (in fact cluster RFBLG), Legacy of old good time, where disk space was costly) (selecting too much records from one table and using the result in a FOR ALL ENTRIES from the second table with the last criteria.)
For this purpose use the "secondary indexes" for customer account, BSID and BSAD (cleared or not-cleared post, so you have to use 2 select)
Then if some fields are missing you can select from BSEG and BKPF the missing fields (via SELECT FOR ALL ENTRIES, using the primary keys of these tables)
Regards
2008 Jan 03 7:34 AM
SELECT
BSEG~KUNNR
BSEG~GSBER
BSEG~BUKRS
BKPF~BUDAT
BKPF~BLDAT
INTO CORRESPONDING FIELDS OF TABLE IT_BSEG FROM
BSEG INNER JOIN BSEG
ON BSEGKUNNR = BKPFKUNNR
WHERE BSEG~KUNNR IN S_KUNNR.
IF NOT IT_BSEG[] IS INITIAL.
SORT BY IT_BSEG-KUNNR.
DELETE ADJACENT DUPLICATES FROM IT_BSEG[].
ENDIF.