2007 Jul 11 8:00 AM
plzz help me giving all the possible ways with explanation to do the following :------
i dont want the database table to use regularly, so i created 3 internal tables from which i want to extract data & put those data in the main output table which is used in ALV.
the 3 internal tables are linked thru primary keys.....but want other fields to be extracted thru primary-foreign key relationship.
how should i bring the data from the the 3 internal tables into the output internal table ?
<u><b>W/O using OOABAP.</b></u>
2007 Jul 11 8:09 AM
Hi
See the sample code how data is fetched into internal tables and how it is read in the loop of one internal table
form read_data.
Get the Accounting Documents for the GR/IR Account Entered on
Selection Screen
clear i_bsis.
refresh i_bsis.
select bukrs " Company Code
hkont " GR IR Account
gjahr " Fiscal Year
belnr " Acc Document
buzei " Item No
budat " Receipt Date(Posting)
monat " Period
into table i_bsis
from bsis
where bukrs = p_bukrs
and hkont = p_grira
and budat in s_budat
and monat in s_monat .
if sy-subrc <> 0.
message i899 with 'No data found'(043).
g_exit = c_x.
stop.
endif.
sort i_bsis by bukrs hkont gjahr belnr buzei.
Get the Vendor,PO,Material,Qty details from BSEG Table
if not i_bsis[] is initial.
clear i_bseg.
refresh i_bseg.
select bukrs " Company Code
belnr " Acc Document
buzei " Item No
gjahr " Fiscal Year
shkzg " Dr/Cr Indicator
lifnr " Vendor Code
matnr " Material No
ebeln " Purchase Order
ebelp " PO Item
werks " Plant
menge " PO Quantity
meins " UOM
dmbtr " Amount in Local Currency
wrbtr " Amount in Trans.Currency
into table i_bseg
from bseg
for all entries in i_bsis
where bukrs = p_bukrs
and belnr = i_bsis-belnr
and gjahr = i_bsis-gjahr
and buzei = i_bsis-buzei
and lifnr in s_lifnr
and werks in s_werks
and matnr in s_matnr
and ebeln in s_ebeln.
sort i_bseg by bukrs belnr buzei gjahr.
Select the Trans.Currency from BKPF Table
clear i_bkpf.
refresh i_bkpf.
select bukrs " Company Code
belnr " Acc Document
gjahr " Fiscal Year
waers " Trans. Currency
awkey " Object Key
awtyp " Reference Procedure
into table i_bkpf
from bkpf
for all entries in i_bsis
where bukrs = p_bukrs
and belnr = i_bsis-belnr
and gjahr = i_bsis-gjahr.
endif.
sort i_bkpf by bukrs belnr gjahr.
Get the Quantity and UOM of Material from MSEG Table
if not i_bkpf[] is initial.
clear i_mseg.
refresh i_mseg.
select mblnr " Material Document
mjahr " Fiscal Year
bwart " Movement Type
matnr " Material No
menge " PO Quantity
meins " UOM
into table i_mseg
from mseg
for all entries in i_bkpf
where mblnr = i_bkpf-awkey(10).
endif.
sort i_mseg by mblnr mjahr.
Get the Material And Description from EKPO Table
if not i_bseg[] is initial.
clear i_ekpo.
refresh i_ekpo.
select ebeln " Purchase Order
ebelp " PO Item
matnr " Material No
txz01 " Material Text
into table i_ekpo
from ekpo
for all entries in i_bseg
where ebeln = i_bseg-ebeln
and ebelp = i_bseg-ebelp.
sort i_ekpo by ebeln ebelp.
Get the Valuation Class from MBEW Table
clear i_mbew.
refresh i_mbew.
select matnr " Material No
bwkey " Plant
bklas " Valuation Class
into table i_mbew
from mbew
for all entries in i_bseg
where matnr = i_bseg-matnr
and bwkey = i_bseg-werks.
sort i_mbew by matnr werks.
Get the Cost Center and Cost Element of the PO from EKKN Table
clear i_ekkn.
refresh i_ekkn.
select ebeln " Purchase Order
ebelp " PO Item
kostl " Cost Center
sakto " Cost Element
into table i_ekkn
from ekkn
for all entries in i_bseg
where ebeln = i_bseg-ebeln
and ebelp = i_bseg-ebelp
and kostl in s_kostl
and sakto in s_kstar.
sort i_ekkn by ebeln ebelp.
Get the Vendor Name
clear i_lfa1.
refresh i_lfa1.
select lifnr " Vendor
name1 " Name
into table i_lfa1
from lfa1
for all entries in i_bseg
where lifnr = i_bseg-lifnr.
endif.
sort i_lfa1 by lifnr.
Move the data to Final Output Internal Table
loop at i_bsis.
i_final-belnr = i_bsis-belnr. " FI Document
i_final-monat = i_bsis-monat. " Period
i_final-budat = i_bsis-budat. " Rec. Date
Read the Transaction Currency from BKPF Internal Table
read table i_bkpf with key bukrs = i_bsis-bukrs
belnr = i_bsis-belnr
gjahr = i_bsis-gjahr
binary search.
if sy-subrc = 0.
i_final-waers = i_bkpf-waers. " Tran.Currency
Read the Movement Type for all Material Related
Documents from MSEG Internal Table
if i_bkpf-awtyp = c_mkpf.
read table i_mseg with key mblnr = i_bkpf-awkey(10)
mjahr = i_bkpf-awkey+10(4).
if sy-subrc = 0.
i_final-bwart = i_mseg-bwart. " Movement Type
endif.
endif.
endif.
Read Vendor, Plant, PO Document, Local And Trans.Amounts
from BSEG Internal Table
read table i_bseg with key bukrs = i_bsis-bukrs
belnr = i_bsis-belnr
gjahr = i_bsis-gjahr
buzei = i_bsis-buzei
binary search.
if sy-subrc = 0.
i_final-lifnr = i_bseg-lifnr. " Vendor
i_final-werks = i_bseg-werks. " Plant
i_final-ebeln = i_bseg-ebeln. " PO
i_final-dmbtr = i_bseg-dmbtr. " Local Amount
i_final-wrbtr = i_bseg-wrbtr. " Tran.Amount
i_final-menge = i_bseg-menge. " Quantity
i_final-meins = i_bseg-meins. " UOM
For Credit Indicator(SHKZG = H) amounts should be (-)ve
if i_bseg-shkzg = c_h.
i_final-dmbtr = i_final-dmbtr * -1.
i_final-wrbtr = i_final-wrbtr * -1.
i_final-menge = i_final-menge * -1.
endif.
Read the Material and its Description from EKPO Internal Table
read table i_ekpo with key ebeln = i_bseg-ebeln
ebelp = i_bseg-ebelp
matnr = i_bseg-matnr
binary search.
if sy-subrc = 0.
i_final-matnr = i_ekpo-matnr. " Material Number
i_final-txz01 = i_ekpo-txz01. " Material Text
Populate the Material Status depending on the Input Checkbox
On Selection Screen
if not i_ekpo-matnr is initial.
i_final-status = c_x.
endif.
endif.
Read the PO related Cost Element and Cost Centers
from EKKN Internal Table
read table i_ekkn with key ebeln = i_bseg-ebeln
ebelp = i_bseg-ebelp
binary search.
if sy-subrc = 0.
i_final-kostl = i_ekkn-kostl. " Cost Center
i_final-sakto = i_ekkn-sakto. " Cost Element
endif.
Read the Valuation Class from MBEW Internal Table
read table i_mbew with key matnr = i_bseg-matnr
werks = i_bseg-werks
binary search.
if sy-subrc = 0.
i_final-bklas = i_mbew-bklas. " Val Class
endif.
Read the Vendor Name from LFA1 Internal Table
read table i_lfa1 with key lifnr = i_bseg-lifnr
binary search.
if sy-subrc = 0.
i_final-name1 = i_lfa1-name1. " Vendor Name
endif.
endif.
append i_final.
clear i_final.
endloop.
sort i_final by lifnr werks monat matnr.
Depending on the check Box Selected display the data
if p_incmt = c_x and p_incnm ne c_x.
delete i_final where matnr eq space.
elseif p_incnm = c_x and p_incmt ne c_x.
delete i_final where matnr ne space.
endif.
endform. "Read Data
<b>Reward points for useful Answers</b>
Regards
Anji
2007 Jul 11 8:02 AM
Hi Divya,
You need to use the LOOP ..ENDLOOP and READ. No need to use ABAP OO here.
Regards,
Atish
2007 Jul 11 8:04 AM
use READ TABLE statement to read one of the internal table based on the primaty key's.
you can read the table..fetch data..and then APPEND the data into your main table.
Hope this answers your question.
Reward points if helpful
2007 Jul 11 8:09 AM
Hi
See the sample code how data is fetched into internal tables and how it is read in the loop of one internal table
form read_data.
Get the Accounting Documents for the GR/IR Account Entered on
Selection Screen
clear i_bsis.
refresh i_bsis.
select bukrs " Company Code
hkont " GR IR Account
gjahr " Fiscal Year
belnr " Acc Document
buzei " Item No
budat " Receipt Date(Posting)
monat " Period
into table i_bsis
from bsis
where bukrs = p_bukrs
and hkont = p_grira
and budat in s_budat
and monat in s_monat .
if sy-subrc <> 0.
message i899 with 'No data found'(043).
g_exit = c_x.
stop.
endif.
sort i_bsis by bukrs hkont gjahr belnr buzei.
Get the Vendor,PO,Material,Qty details from BSEG Table
if not i_bsis[] is initial.
clear i_bseg.
refresh i_bseg.
select bukrs " Company Code
belnr " Acc Document
buzei " Item No
gjahr " Fiscal Year
shkzg " Dr/Cr Indicator
lifnr " Vendor Code
matnr " Material No
ebeln " Purchase Order
ebelp " PO Item
werks " Plant
menge " PO Quantity
meins " UOM
dmbtr " Amount in Local Currency
wrbtr " Amount in Trans.Currency
into table i_bseg
from bseg
for all entries in i_bsis
where bukrs = p_bukrs
and belnr = i_bsis-belnr
and gjahr = i_bsis-gjahr
and buzei = i_bsis-buzei
and lifnr in s_lifnr
and werks in s_werks
and matnr in s_matnr
and ebeln in s_ebeln.
sort i_bseg by bukrs belnr buzei gjahr.
Select the Trans.Currency from BKPF Table
clear i_bkpf.
refresh i_bkpf.
select bukrs " Company Code
belnr " Acc Document
gjahr " Fiscal Year
waers " Trans. Currency
awkey " Object Key
awtyp " Reference Procedure
into table i_bkpf
from bkpf
for all entries in i_bsis
where bukrs = p_bukrs
and belnr = i_bsis-belnr
and gjahr = i_bsis-gjahr.
endif.
sort i_bkpf by bukrs belnr gjahr.
Get the Quantity and UOM of Material from MSEG Table
if not i_bkpf[] is initial.
clear i_mseg.
refresh i_mseg.
select mblnr " Material Document
mjahr " Fiscal Year
bwart " Movement Type
matnr " Material No
menge " PO Quantity
meins " UOM
into table i_mseg
from mseg
for all entries in i_bkpf
where mblnr = i_bkpf-awkey(10).
endif.
sort i_mseg by mblnr mjahr.
Get the Material And Description from EKPO Table
if not i_bseg[] is initial.
clear i_ekpo.
refresh i_ekpo.
select ebeln " Purchase Order
ebelp " PO Item
matnr " Material No
txz01 " Material Text
into table i_ekpo
from ekpo
for all entries in i_bseg
where ebeln = i_bseg-ebeln
and ebelp = i_bseg-ebelp.
sort i_ekpo by ebeln ebelp.
Get the Valuation Class from MBEW Table
clear i_mbew.
refresh i_mbew.
select matnr " Material No
bwkey " Plant
bklas " Valuation Class
into table i_mbew
from mbew
for all entries in i_bseg
where matnr = i_bseg-matnr
and bwkey = i_bseg-werks.
sort i_mbew by matnr werks.
Get the Cost Center and Cost Element of the PO from EKKN Table
clear i_ekkn.
refresh i_ekkn.
select ebeln " Purchase Order
ebelp " PO Item
kostl " Cost Center
sakto " Cost Element
into table i_ekkn
from ekkn
for all entries in i_bseg
where ebeln = i_bseg-ebeln
and ebelp = i_bseg-ebelp
and kostl in s_kostl
and sakto in s_kstar.
sort i_ekkn by ebeln ebelp.
Get the Vendor Name
clear i_lfa1.
refresh i_lfa1.
select lifnr " Vendor
name1 " Name
into table i_lfa1
from lfa1
for all entries in i_bseg
where lifnr = i_bseg-lifnr.
endif.
sort i_lfa1 by lifnr.
Move the data to Final Output Internal Table
loop at i_bsis.
i_final-belnr = i_bsis-belnr. " FI Document
i_final-monat = i_bsis-monat. " Period
i_final-budat = i_bsis-budat. " Rec. Date
Read the Transaction Currency from BKPF Internal Table
read table i_bkpf with key bukrs = i_bsis-bukrs
belnr = i_bsis-belnr
gjahr = i_bsis-gjahr
binary search.
if sy-subrc = 0.
i_final-waers = i_bkpf-waers. " Tran.Currency
Read the Movement Type for all Material Related
Documents from MSEG Internal Table
if i_bkpf-awtyp = c_mkpf.
read table i_mseg with key mblnr = i_bkpf-awkey(10)
mjahr = i_bkpf-awkey+10(4).
if sy-subrc = 0.
i_final-bwart = i_mseg-bwart. " Movement Type
endif.
endif.
endif.
Read Vendor, Plant, PO Document, Local And Trans.Amounts
from BSEG Internal Table
read table i_bseg with key bukrs = i_bsis-bukrs
belnr = i_bsis-belnr
gjahr = i_bsis-gjahr
buzei = i_bsis-buzei
binary search.
if sy-subrc = 0.
i_final-lifnr = i_bseg-lifnr. " Vendor
i_final-werks = i_bseg-werks. " Plant
i_final-ebeln = i_bseg-ebeln. " PO
i_final-dmbtr = i_bseg-dmbtr. " Local Amount
i_final-wrbtr = i_bseg-wrbtr. " Tran.Amount
i_final-menge = i_bseg-menge. " Quantity
i_final-meins = i_bseg-meins. " UOM
For Credit Indicator(SHKZG = H) amounts should be (-)ve
if i_bseg-shkzg = c_h.
i_final-dmbtr = i_final-dmbtr * -1.
i_final-wrbtr = i_final-wrbtr * -1.
i_final-menge = i_final-menge * -1.
endif.
Read the Material and its Description from EKPO Internal Table
read table i_ekpo with key ebeln = i_bseg-ebeln
ebelp = i_bseg-ebelp
matnr = i_bseg-matnr
binary search.
if sy-subrc = 0.
i_final-matnr = i_ekpo-matnr. " Material Number
i_final-txz01 = i_ekpo-txz01. " Material Text
Populate the Material Status depending on the Input Checkbox
On Selection Screen
if not i_ekpo-matnr is initial.
i_final-status = c_x.
endif.
endif.
Read the PO related Cost Element and Cost Centers
from EKKN Internal Table
read table i_ekkn with key ebeln = i_bseg-ebeln
ebelp = i_bseg-ebelp
binary search.
if sy-subrc = 0.
i_final-kostl = i_ekkn-kostl. " Cost Center
i_final-sakto = i_ekkn-sakto. " Cost Element
endif.
Read the Valuation Class from MBEW Internal Table
read table i_mbew with key matnr = i_bseg-matnr
werks = i_bseg-werks
binary search.
if sy-subrc = 0.
i_final-bklas = i_mbew-bklas. " Val Class
endif.
Read the Vendor Name from LFA1 Internal Table
read table i_lfa1 with key lifnr = i_bseg-lifnr
binary search.
if sy-subrc = 0.
i_final-name1 = i_lfa1-name1. " Vendor Name
endif.
endif.
append i_final.
clear i_final.
endloop.
sort i_final by lifnr werks monat matnr.
Depending on the check Box Selected display the data
if p_incmt = c_x and p_incnm ne c_x.
delete i_final where matnr eq space.
elseif p_incnm = c_x and p_incmt ne c_x.
delete i_final where matnr ne space.
endif.
endform. "Read Data
<b>Reward points for useful Answers</b>
Regards
Anji