2008 Feb 15 10:44 AM
Hi,
I have 2 internal tables say itab1, itab2.
Itab1 has fng fields say A, B, C, D.
Itab2 has fng fields say D, E.
How to combine these 2 itabs and put all the data accordingly into another itab3 (containing fields A,B, C,D, E) ?
Help me by giving sample code.
Regards,
Kalai
2008 Feb 15 10:48 AM
Loop at itab1.
read table itab2 with key d = itab1-d.
if sy-subrc = 0.
move-corresponding itab1 to itab3.
itab3-e = itab2-e.
append itab3.
clear itab3.
endif.
endloop.
Hi,
I have 2 internal tables say itab1, itab2.
Itab1 has fng fields say A, B, C, D.
Itab2 has fng fields say D, E.
How to combine these 2 itabs and put all the data accordingly into another itab3 (containing fields A,B, C,D, E) ?
Help me by giving sample code.
Regards,
Kalai
2008 Feb 15 10:46 AM
Hi
If both of them are having same structure then use
append lines itab to itab2.
otherwise use loop and append the work to this
regards
Shiva
2008 Feb 15 10:47 AM
Hi
LOOP AT it_ekpo INTO wa_ekpo.
READ TABLE it_ekko INTO wa_ekko WITH KEY ebeln = wa_ekpo-ebeln BINARY SEARCH .
IF sy-subrc = 0.
MOVE-CORRESPONDING wa_ekpo TO wa_itab.
MOVE-CORRESPONDING wa_ekko TO wa_itab.
APPEND wa_itab TO it_itab.
ENDIF.
ENDLOOP.
Regards,
Jay
2008 Feb 15 10:47 AM
hi,
do this way...
loop at itab1.
itab3-fld1 = itab1-fld1.
itab3-fld2 = itab1-fld2.
itab3-fld3 = itab1-fld3.
append itab3.
clear itab3.
endloop.
loop at itab2.
itab3-fld4 = itab1-fld4.
itab3-fld5 = itab1-fld5.
append itab3.
clear itab3.
endloop.
Regards,
Santosh
Edited by: Santosh Kumar Patha on Feb 15, 2008 4:18 PM
2008 Feb 15 10:48 AM
Loop at itab1.
read table itab2 with key d = itab1-d.
if sy-subrc = 0.
move-corresponding itab1 to itab3.
itab3-e = itab2-e.
append itab3.
clear itab3.
endif.
endloop.
2008 Feb 15 10:52 AM
Hi,
Check the below code...
Loop at itab1.
itab3-a = itab1-a.
itab3-b = itab1-b.
itab3-c = itab1-c.
itab3-d = itab1-d.
append itab3.
endloop.
loop at itab3.
v_index = sy-tabix.
Loop at itab2 where d = itab3-d. <Read table itab2 with key b = itab3-d.>
itab3-e = itab2-e.
modify itab3 index v_index.
endloop.
endloop.
Rgds,
Bujji
2008 Feb 15 10:53 AM
try one among following :
1)
you can use this:
append lines of itab1 to it_final.
append lines of itab2 to it_final.
....
2)
loop at itab1.
move-corresponding itab1 to it_final. "For same field name purpose
it_final-field1 = itab1-field2. "For different field name purpose
append it_final.
endloop.
loop at itab2.
move-corresponding itab2 to it_final. "For same field name purpose
it_final-field2 = itab2-field2. "For different field name purpose
append it_final.endloop.
3)
data declaration part
TABLES: mara,marc,mard .
**********TYPES
TYPES: BEGIN OF t_mara,
matnr TYPE matnr, "Material Number
mtart TYPE mtart, "Material Type
meins TYPE meins, "Basic Unit Of measure
END OF t_mara.
TYPES: BEGIN OF t_marc,
matnr TYPE matnr, "Material Number
werks TYPE werks_d, "Plant
END OF t_marc.
TYPES: BEGIN OF t_mard,
matnr TYPE matnr,
werks TYPE werks_d,
lgort TYPE lgort_d,
END OF t_mard.
TYPES: BEGIN OF t_tab,
matnr TYPE matnr,
mtart TYPE mtart,
meins TYPE meins ,
werks TYPE werks_d ,
lgort TYPE lgort_d,
END OF t_tab.
**********WORKAREA
DATA: wa_mara TYPE t_mara,
wa_marc TYPE t_marc,
wa_mard type t_mard,
wa_tab TYPE t_tab,
e_matnr TYPE matnr,
wa_matnr TYPE matnr.
DATA : i_fieldcat TYPE slis_t_fieldcat_alv.
DATA: d_field(40), d_value(40),
AMBER(20).
**********INTERNAL TABLES
DATA: it_mara TYPE STANDARD TABLE OF t_mara,
it_marc TYPE STANDARD TABLE OF t_marc,
it_mard TYPE STANDARD TABLE OF t_mard,
it_tab TYPE STANDARD TABLE OF t_tab.
Data Selection Part
*select data from mara table
SELECT matnr
mtart
meins
FROM mara
INTO TABLE it_mara
WHERE matnr IN s_matnr.
*select data from marc table
SELECT matnr
werks
FROM marc
INTO TABLE it_marc
FOR ALL ENTRIES IN it_mara
WHERE matnr = it_mara-matnr.
**********************************************************
THIS BLOCK MOVES THE FIELDS FROM DIFFERENT *
TABLES(mara,marc) INTO A FINAL TABLE IT_TAB *
*********************************************************
LOOP AT it_marc INTO wa_marc .
READ TABLE it_mara INTO wa_mara WITH KEY matnr = wa_marc-matnr BINARY SEARCH.
IF sy-subrc = 0 .
wa_tab-matnr = wa_mara-matnr .
wa_tab-mtart = wa_mara-mtart.
wa_tab-meins = wa_mara-meins.
ENDIF.
wa_tab-werks = wa_marc-werks .
APPEND wa_tab TO it_tab.
ENDLOOP.
do reward if helpful
2008 Feb 15 11:01 AM
While merging there must be key field existing the two internal tables.
either u can create a new internal table and dump the data of the two itabs to it.
or u can modify the primary table(itab1) from the secondary table(itab2)
1) itab1 has field A B C D
2) itab 2 has field D E
loop at itab1.
read table itab2 with key D = itab1-D.
check sy-subrc = 0.
itab3-D = itab1-D.
itab3-A = itab1-A.
itab3-B = itab1-B.
itab3-B = itab1-C.
itab3-B = itab2-E.
append itab3.
endloop.
it can be done also like this.
put field E in itab1 and modify it.
loop at itab1.
read table itab2 with key D = itab1-D.
check sy-subrc = 0.
itab1-E = itab1-E.
modify itab1 transporting E.
append itab3.
endloop.
the above statements can be used if u r sure that the inner join condition exists in the tables.
if the itab2 has more than one entries for the D in itab 1
( ex: more than one E for a D).
Then use this.
loop at itab1.
Loop at itab2 where D = itab1-D.
itab3-D = itab1-D.
itab3-A = itab1-A.
itab3-B = itab1-B.
itab3-C = itab1-C.
itab3-E = itab2-E.
append itab3.
endloop.
endloop.
reward if usefull
| User | Count |
|---|---|
| 4 | |
| 2 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |