on 03-18-2008 5:52 AM
Hi all,
I have 4 itab, i want to populate these data of 4 different tables into 1 single table...
how do i proceed ahead..
following is my code
please help..
REPORT ZAVS_KEMWEL.
tables : Mseg, resb, makt, afko.
types : begin of ty_mseg,
mblnr type mseg-mblnr,
mjahr type MSEG-MJAHR,
bwart TYPE mseg-bwart,
matnr TYPE mseg-matnr,
charg TYPE charg_d,
menge TYPE menge_d,
aufnr TYPE mseg-aufnr,
rsnum TYPE mseg-rsnum,
rspos TYPE mseg-rspos,
end of ty_mseg,
begin of ty_resb,
rsnum TYPE mseg-rsnum,
rspos TYPE mseg-rspos,
nomng type resb-NOMNG,
end of ty_resb,
begin of ty_afko,
aufnr type mseg-aufnr,
plnbez type matnr,
end of ty_afko,
begin of ty_makt,
matnr type makt-matnr,
maktx type makt-maktx,
end of ty_makt.
data : lform type rs381_fnam.
data : it_mseg type standard table of ty_mseg,
it_resb type standard table of ty_resb,
it_afko type standard table of ty_afko,
it_makt type standard table of ty_makt.
data : wa_mseg like line of it_mseg.
SELECT-OPTIONS: so_mblnr FOR mseg-mblnr OBLIGATORY,
so_mjahr FOR mseg-mjahr OBLIGATORY .
select mblnr mjahr bwart matnr charg menge aufnr rsnum rspos
into corresponding fields of table it_mseg
from mseg
where bwart = '261'
and mblnr in so_mblnr
and mjahr in so_mjahr.
move it_mseg to it_final.
if it_mseg is not initial.
select nomng rsnum rspos
from resb
into corresponding fields of table it_resb
for all entries in it_mseg
where rsnum = it_mseg-rsnum
and rspos = it_mseg-rspos.
select aufnr plnbez
from afko
into corresponding fields of table it_afko
for all entries in it_mseg
where aufnr = it_mseg-aufnr.
if it_afko is not initial.
select maktx
from makt
into table it_makt
for all entries in it_afko
where matnr = it_afko-plnbez
and spras = 'EN'.
endif.
i want these 4 tables in it_final.
hi amrutha modify thw where condition above(given by me)
as
WHERE
A~BWART = '261' AND
A~MBLNR IN SO_MBLNR AND
A~MJAHR IN SO_MJAHR AND
D~SPRAS = 'EN'.
KINDLY REWARD IF IT IS HELPFUL
REGARDS
RANJITH
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
hai amrutha
declare one more internal table and use join like this
..use this code
i think it will be helpful..
here i declared a structure..
and joined all those four tables
TYPES : BEGIN OF TY_FINAL,
MBLNR TYPE MSEG-MBLNR,
MJAHR TYPE MSEG-MJAHR,
BWART TYPE MSEG-BWART,
MATNR TYPE MSEG-MATNR,
CHARG TYPE CHARG_D,
MENGE TYPE MENGE_D,
AUFNR TYPE MSEG-AUFNR,
RSNUM TYPE MSEG-RSNUM,
RSPOS TYPE MSEG-RSPOS,
RSNUM TYPE MSEG-RSNUM,
RSPOS TYPE MSEG-RSPOS,
NOMNG TYPE RESB-NOMNG,
AUFNR TYPE MSEG-AUFNR,
PLNBEZ TYPE MATNR,
MATNR TYPE MAKT-MATNR,
MAKTX TYPE MAKT-MAKTX.
TYPES : END OF TY_FINAL.
DATA : IT_FINAL TYPE STANDARD TABLE OF TY_FINAL WITH HEADER LINE.
Select
Amblnr Amjahr Abwart Amatnr Acharg Amenge Aaufnr Arsnum A~rspos
Bnomng Brsnum B~rspos
Caufnr Cplnbez
D~maktx
INTO CORRESPONDING FIELDS OF ITAB
FROM MSEG AS A
INNER JOIN RESB AS B ON AMATNR = BMATNR
INNER JOIN AFKO AS C ON BMATNR = CPLNBEZ
INNER JOIN MAKT AS D ON CPLNBEZ = DMATNR
WHERE
BWART = '261' AND
MBLNR IN SO_MBLNR AND
MJAHR IN SO_MJAHR AND
SPRAS = 'EN'.
plz reward if it is helpful
regards
ranjith
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
y dont u avoid using four internal tables...
join tables and fetch data to a single internal table..directly
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Use the following logic.
loop at it_it_mseg.
* fill all the values from it_mseg to final internal table
ls_final-field_name = it_mseg-field_name "Note replace field_name with your field name
read table it_resb with key rsnum = it_mseg-rsnum
rspos = it_mseg-rspos.
if sy-subrc eq 0.
* Fill all the required values
ls_final-field_name = it_resb-field_name "Note replace field_name with your field name
endif.
read table it_afko with key aufnr = it_mseg-aufnr.
if sy-subrc eq 0.
ls_final-field_name = it_afko-field_name "Note replace field_name with your field name
endif.
read table it_makt with key matnr = it_afko-plnbez.
if sy-subrc eq 0.
ls_final-field_name = it_makt-field_name "Note replace field_name with your field name
endif.
append ls_final to lt_final.
endloop.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
84 | |
25 | |
12 | |
9 | |
6 | |
6 | |
5 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.