04-03-2008 11:04 AM
Hi Experts,
how can we select line item from item table and on the basis of that line item we can fetch header data
or vise versa
can i have proper answer for that
thanks
Rahul
04-03-2008 11:06 AM
in the line item there will also be a reference to the header.
Header: document 1000
item: document 100 item 10
document 100 item 20
etc.
04-03-2008 11:08 AM
See for any thing to select you should have some condition.
if there is no condition that means you are selecting all the records.
Now go to header table and get the Records from Header using the Item and header realtion fields in where condition
use for all entries to get the data from header using item,
04-03-2008 11:13 AM
Hi,
If you know the line items then you get multiple POs.
For example same line items exists in many documents like POs, SOs etc.
Select the line items from item table and for those documents (the item table also contains the document number) get the header data by passing the document number.
Reward.
04-03-2008 11:22 AM
You can either use INNER JOIN to select data from both header table and item table or u can select data from header table and using the staement FOR ALL ENTRIES u can selct data from item table.
For eg:
select VBAKVBELN VBAKERDAT VBAP~POSNR
into corresponding fields of table ITAB
from VBAK inner join VBAP
on VBAKVBELN eq VBAPVBELN.
OR
select vbeln from vbak
into corresponding fields of table ITAB.
select POSNR from vbap
into corresponding fields of table ITAB1
for all entries in ITAB
where vbeln eq ITAB-vbeln.
04-03-2008 11:27 AM
hi,
suppose <f1> is the common field between <header_table > and <item_table>..
then use this query:-
select <f1><f2> from <header_table> into <it_header_table>
where condition.
if sy-subrc = 0.
select <f1><f3> <f4>....
from <item_table> into <it_item_table> for all entries in <it_header_table>
where <f1> = <it_header_table>-<f1>.
endif.
04-03-2008 12:08 PM
Hi,
The question is not very much clear as u've not specified whether u r using any selction criteria for selecting the records.
U can select the line items from the header data and vice versa.
For example I'm taking EKKO(PO header data) and EKPO(PO Item data).
tables: ekko, ekpo.
data: it_ekko like table of ekko,
it_ekpo like table of ekpo.
data: wa_ekko type ekko,
wa_ekpo type ekpo.
select-options: po for ekko-ebeln.
if not it_ekko is initial.
select * from ekpo into table it_ekpo for all entries in it_ekko where ebeln = it_ekko-ebeln.
if not it_ekpo is initial.
loop at it_ekpo into wa_ekpo.
write:/ wa_ekpo-ebeln, wa_ekpo-ebelp.
endloop.
endif.
endif.
if u want select header data based on line items data just reverse the table names, internal tables and work areas in the select statement mentioned in the above example. While selecting the header data from the line items data, sort and delete the duplicate PO from the internal table which is storing line items records.
U can select the item data based on header data and vice versa based on the KEY field of the header data table.
Reward this solves ur problem.
Regards
ChandraK