09-10-2007 8:20 AM
09-10-2007 8:24 AM
Hi Aarif ,
You can transfer it only if the structure of all the three tables are the same else you will have to loop in the tables and use the append/modify command.
If all the tables have the same structure use the APPEND TABLE command.
Regards
Arun
09-10-2007 8:32 AM
Hi Aarif,
have a look at the code.
hope it helps.
types: begin of i_vbak,
vbeln type vbeln_va,
augru type augru,
end of i_vbak.
types: begin of i_vbap,
vbeln type vbeln_va,
augru type augru,
posnr type posnr_va,
matnr type matnr,
zmeng type dzmeng,
end of i_vbap.
types: begin of i_makt,
matnr type matnr,
maktx type maktx,
end of i_makt.
types: begin of i_lips,
posnr type posnr_vl,
matnr type matnr,
lfimg type lfimg,
end of i_lips.
types: begin of i_reason,
spras type spras,
augru type augru,
bezei type bezei40,
end of i_reason.
types: begin of i_vbpa,
vbeln type vbeln,
parvw type parvw,
kunnr type kunnr,
end of i_vbpa.
types: begin of i_kna1,
kunnr type kunnr,
name1 type name1_gp,
end of i_kna1.
types: begin of i_final,
vbeln type vbeln_va,
posnr type posnr_va,
matnr type matnr,
zmeng type dzmeng,
maktx type maktx,
lfimg type lfimg,
spras type spras,
augru type augru,
bezei type bezei40,
parvw type parvw,
kunnr type kunnr,
name1 type name1_gp,
end of i_final.
*INTERNAL TABLES
data: it_vbak type standard table of i_vbak.
data: it_vbap type standard table of i_vbap.
data: it_makt type standard table of i_makt.
data: it_lips type standard table of i_lips.
data: it_vbpa type standard table of i_vbpa.
data: it_kna1 type standard table of i_kna1.
data: it_final type standard table of i_final.
data: it_reason type standard table of i_reason.
select vbeln
augru into corresponding fields of table it_vbak
from vbak
where vbeln in s_vbeln.
if sy-subrc = 0.
select vbeln
posnr
matnr
zmeng into corresponding fields of table it_vbap
from vbap
for all entries in it_vbak
where vbeln = it_vbak-vbeln.
if sy-subrc = 0.
select spras
augru
bezei into corresponding fields of table it_reason
from tvaut
for all entries in it_vbak
where augru = it_vbak-augru.
if sy-subrc = 0.
select vbeln
parvw
kunnr into corresponding fields of table it_vbpa
from vbpa
for all entries in it_vbak
where vbeln = it_vbak-vbeln.
if sy-subrc = 0.
select kunnr
name1 into corresponding fields of table it_kna1
from kna1
for all entries in it_vbpa
where kunnr = it_vbpa-kunnr.
if sy-subrc = 0.
select posnr
matnr
lfimg into corresponding fields of table it_lips
from lips
for all entries in it_vbap
where posnr = it_vbap-posnr.
if sy-subrc = 0.
select matnr
maktx into corresponding fields of table it_makt
from makt
for all entries in it_vbap
where matnr = it_vbap-matnr.
endif.
endif.
endif.
endif.
endif.
else.
message i002(sy) with 'No Data found'.
leave list-processing.
endif.
if sy-subrc = 0.
loop at it_vbap into wa_vbap.
read table it_vbak into wa_vbak with key vbeln = wa_vbap-vbeln binary search.
if sy-subrc = 0.
*<b>MOVE DATA INTO IT_FINAL.</b>
move: wa_vbak-vbeln to wa_final-vbeln,
wa_vbak-augru to wa_final-augru,
wa_vbap-posnr to wa_final-posnr,
wa_vbap-matnr to wa_final-matnr,
wa_vbap-zmeng to wa_final-zmeng.
endif.
read table it_lips into wa_lips with key posnr = wa_final-posnr binary search.
if sy-subrc = 0.
move: wa_lips-lfimg to wa_final-lfimg.
endif.
read table it_reason into wa_reason with key augru = wa_final-augru binary search.
if sy-subrc = 0.
move: wa_reason-spras to wa_final-spras,
wa_reason-bezei to wa_final-bezei.
endif.
read table it_makt into wa_makt with key matnr = wa_final-matnr binary search.
if sy-subrc = 0.
move: wa_makt-maktx to wa_final-maktx.
endif.
read table it_vbpa into wa_vbpa with key vbeln = wa_final-vbeln binary search.
if sy-subrc = 0.
move: wa_vbpa-parvw to wa_final-parvw,
wa_vbpa-kunnr to wa_final-kunnr.
endif.
read table it_kna1 into wa_kna1 with key kunnr = wa_final-kunnr binary search.
if sy-subrc = 0.
move: wa_kna1-name1 to wa_final-name1.
endif.
append wa_final to it_final.
clear wa_final.
endloop.
endif.
<b>reward if useful.</b>
Pritha.
09-20-2007 8:03 AM
Hi,
DATA: itab1 TYPE TABLE OF kna1,
itab2 TYPE TABLE OF kna1,
itab2 TYPE TABLE OF kna1,
itab TYPE TABLE OF kna1,
wa TYPE kna1.
LOOP AT itab1 INTO wa.
APPEND wa TO itab.
ENDLOOP.
LOOP AT itab2 INTO wa.
APPEND wa TO itab.
ENDLOOP.
LOOP AT itab3 INTO wa.
APPEND wa TO itab.
ENDLOOP.
SORT iatb BY <fieldnm>
DELETE ADJACENT DUPLICATES FROM iatb COMPARING <fieldnm>
09-20-2007 8:39 AM
Dear Aarif,
create 3 tables with the same fields, and use for all entries.
Give point if helpfull.
Thanks
09-20-2007 9:16 AM
Table declarations
TABLES: ekko, "Purchasing Document Header
ekpo, "Purchasing Document Item
lfa1. "Vendor Master (General Section)
Declaration of types:
data: BEGIN OF tbl_ekko occurs 0,
ebeln TYPE ebeln,
bukrs type bukrs,
bsart type bsart,
lifnr TYPE lifnr,
END OF tbl_ekko.
data: BEGIN OF tbl_ekpo occurs 0,,
ebeln TYPE ebeln,
ebelp TYPE ebelp,
matnr thpe matnr,
END OF tbl_ekpo.
data: BEGIN OF tbl_lfa1 occurs 0,,
lifnr TYPE lifnr
name1TYPE name1,
END OF tbl_lfa1.
data: BEGIN OF tbl_final occurs 0,,
ebeln TYPE ebeln,
ebelp TYPE ebelp,
bsart type bsart,
bsart type bsart,
matnr type matnr,
bukrs type bukrs,
lifnr TYPE lifnr,
name1 type name1,
END OF tbl_final.
*Selection screen:
PARAMETERS: p_lifnr TYPE lifnr,
p_ebeln type ebeln.
Selection (JOIN):
START-OF-SELECTION.
SELECT lifnr name1
FROM lfa1
INTO table tbl_lfa1
WHERE lifnr EQ p_lifnr.
if sy-subrc = 0.
sort tbl_lfa1 by lifnr.
endif.
if not tbl_lifnr is initial.
SELECT ebeln bukrs bsart lifnr
FROM ekko
INTO table tbl_ekko
FOR ALL INTRIES IN tbl_lfa1
WHERE ebeln EQ p_ebeln
AND lifnr EQ tbl_lfa1-lifnr.
if sy-subrc = 0.
sort tbl_ ekko by ebeln.
endif.
endif.
if not tbl_ekko is initial.
SELECT ebeln ebelp matnr
FROM ekpo
INTO table tbl_ekpo
FOR ALL INTRIES IN tbl_ekko
WHERE ebeln EQ tbl_ekko-eblen.
if sy-subrc = 0.
sort tbl_ ekpo by ebeln.
endif.
endif.
END-OF-SELECTION.
Main program logic:
LOOP AT tbl_ekpo.
read table tbl_ekko with key ebeln = tbl_ekpo-ebeln BINARY SEARCH.
if sy-subrc = 0.
read table tbl_lfa1 with key lifnr = tbl_ekko-lifnr BINARY SEARCH.
if sy-subrc = 0
tbl_final-ebeln = tbl_ekpo-ebeln.
tbl_final-ebelp =tbl_ekpo-ebelp.
tbl_final-bsart =tbl_ekko-bsart.
tbl_final-matnr =tbl_ekpo-matnr.
tbl_final-bukrs =tbl_ekko-bukrs.
tbl_final-lifnr =tbl_lf1-lifnr.
tbl_final-name1 =tbl_lfa1-name.
APPEND tbl_final.
CLEAR : tbl_final,
tbl_ekko,
tbl_ekpo,
tbl_lfa1.
endif.
endif.
ENDLOOP.
NOTE : use only KEY-FIELDS in WHERE condition for better perfomance SORT the internal table for BINARY SEARCH for READ statement
In that above code you can change a/c to ur inputs availabe.
<b>Reward with points if helpful.</b>
Regards,
Vijay
09-21-2007 8:39 AM
Loop on any one Internal Table from 3, write READ statements for the other two, and move data to the final internal table.
-
Loop at itab into wa.
move data from itab to final.
read table itab2 into wa2 based on some condition with itab (eg. WITH KEY matnr = wa-matnr).
if sy-subrc eq 0.
move data from itab2 to final.
endif.
read table itab3 into wa3 based on some condition with itab (eg. WITH KEY matnr = wa-matnr, or some other condition).
if sy-subrc eq 0.
move data from itab3 to final.
endif.
append final.
endloop.
-
<b>Reward Points if useful.</b>