11-27-2007 10:58 AM
Could anybody please give me the whole code for joining two internal tables
and putting the data in a third internal table. Please, very urgent.
Regards,
SAURAV
11-27-2007 11:01 AM
inner join can be used to join 2 database tables not internal tables...
to achieve ur result.... 2 internal tables should have common field....
after populating internal tables....
loop at itab1.
itab_final-f1 = itab1-f1.
read table itab2 with key f1 = itab1-f1.
if sy-subrc = 0.
itab_final-f2 = itab2-f2.
itab_final-f3 = itab2-f3.
endif.
append itab_final.
clear itab_final.
endloop.
follow above logic....
11-27-2007 11:02 AM
Forst get the data into the header line of both the internal tables.itab1 and itab2.
now you can fill the data into the third internal table
itab1-fld1 = itab3-fld1.
itab2-fld2 = itab3-fld2.
...and so on...
Append itab3.
11-27-2007 11:02 AM
Hi,
Refer this code
&----
*& Form SUB_READ_VBRK
&----
text
----
FORM sub_read_vbrk.
SELECT vbeln
rplnr
bukrs
FROM vbrk
INTO TABLE it_vbrk
WHERE vbeln IN s_vbeln
AND rplnr NE ' '.
IF sy-subrc EQ 0.
SORT it_vbrk BY rplnr.
ENDIF.
ENDFORM. " SUB_READ_VBRK
&----
*& Form SUB_READ_FPLTC
&----
text
----
FORM sub_read_fpltc.
IF NOT it_vbrk[] IS INITIAL.
SELECT fplnr
fpltr
ccnum
FROM fpltc
INTO TABLE it_fpltc
FOR ALL ENTRIES IN it_vbrk
WHERE fplnr EQ it_vbrk-rplnr
AND ccins EQ 'GIFC'.
IF sy-subrc EQ 0.
SORT it_fpltc BY fplnr.
ENDIF.
ENDIF.
ENDFORM. " SUB_READ_FPLTC
&----
*& Form SUB_COLLECT_DATA
&----
text
----
FORM sub_collect_data.
*--Local variables
DATA : lv_count(3) TYPE c.
IF NOT it_fpltc[] IS INITIAL.
LOOP AT it_fpltc INTO wa_fpltc.
lv_count = wa_fpltc-fpltr+3(3).
wa_final-ccnum = wa_fpltc-ccnum.
wa_final-rfzei = lv_count.
CLEAR : wa_vbrk.
READ TABLE it_vbrk INTO wa_vbrk WITH KEY rplnr = wa_fpltc-fplnr
BINARY SEARCH.
IF sy-subrc EQ 0.
wa_final-vbeln = wa_vbrk-vbeln.
wa_final-bukrs = wa_vbrk-bukrs.
ENDIF.
APPEND wa_final TO it_final.
CLEAR : wa_vbrk,
wa_fpltc,
lv_count.
ENDLOOP.
ENDIF.
ENDFORM. " SUB_COLLECT_DATA
Regards,
prashant
11-27-2007 11:02 AM
11-27-2007 11:03 AM
hi,
what is the structure of those 3 itabs.
if they all are of same structure then u can move data with APPEND or MOVE-CORRESPONDING or INSERT LINES OF with these u can move data to 3rd internal table.
regards,
pavan.
11-27-2007 11:03 AM
Hi
U can't do it a join beetween internal tables (it's possible only for transparent dictionary table), but u can do it this:
LOOP AT ITAB1.
LOOP AT ITAB2 WHERE FIELD1 = ITAB1-FIELD1
AND ....................
ITAB3-FIELD1 = ....................
APPEND ITAB3.
ENDLOOP.
ENDLOOP.
Max
11-27-2007 11:04 AM
hI
You can use APPEND LINES OF itab1 TO itab2, when there is no condition and the structure of the 2 internal tables are the same.
If you have to join 2 internal tables upon some condition, then Loop is necessary.without looping it is not possible.
11-27-2007 11:04 AM
11-27-2007 11:06 AM
Hi,
You can join 2 database tables only, not 2 internal tables.
However,
itab1, itab2, itab3.
To add the records of itab2 into itab1.
Loop at itab2 into wa_itab2.
wa_itab1-fld1 = wa_tab2-fld1.
append wa_itab1 to itab1.
clear wa_itab1.
endloop.
Similarly , u combine itab1 and itab3.
Regards,
Vani.
11-27-2007 11:07 AM
You may have to write the code as follows for joining two tables and populationg the records to an internal table.
SELECT a~mblnr
a~mjahr
a~zeile
a~bwart
a~matnr
a~werks
a~meins
a~erfmg
b~bldat
FROM mseg AS a INNER JOIN
mkpf AS b ON a~mblnr = b~mblnr AND
a~mjahr = b~mjahr
INTO TABLE it_msmk WHERE a~matnr IN s_matnr
AND b~bldat IN s_bldat
AND a~werks IN s_werks.
Reward points if useful!
11-27-2007 11:07 AM
Hi Saurav,
To join the database tables you need to use JOINS.
U can use eiher inner join or outer join.
U cannot join Internal Tables
<b>Inner Join (Default)</b>
Sometimes a record in the first segment does not have a corresponding record in the second segment with which it is joined. For example, if not every FI document item, TXW_FI_POS is related to a vendor (i.e., the vendor field can be empty). When joining the vendor master TXW_VENDOR, with an inner join, the view would only include FI document items that were vendor postings (where the vendor field was filled).
An inner join condition specifies that when combining data from two segments, only the records that have a matching value in both segments are included in the resulting view report. The view report ignores any records from the first segment where there is no matching record from the second segment. In the above example, TXW_FI_POS segment records that do not have a corresponding TXW_VENDOR segment record are not included in the view.
The default for joining segments in DART is the inner join.
Syntax
<joined table> ::= <joined table primary>
( INNER | LEFT ( OUTER )? )? JOIN
<table reference> ON <search condition>.
<joined table primary> ::= <table reference>
| <joined table>
| '(' <joined table> ')'.
Example :
SELECT employee_name, manager_name
FROM employees AS e JOIN managers AS m
ON e.manager_id = m.manager_id
<b>Outer Join</b>
An outer join allows all records from the combined segments to appear in the view report, regardless of whether they have a matching value in both segments.
To use the FI transaction view example above, if you choose to make the join conditions outer joins, then the view includes a TXW_FI_POS segment record, even if it does not have a matching TXW_VENDOR segment record. In the view report, if no dependent vendor is found, the vendor master fields (TXW_VENDOR) will be left blank.
Message was edited by:
Chandra Prakash
11-27-2007 11:10 AM
Hi Saurav,
types: begin of ty_mara, " Material Data
matnr type mara-matnr,
mtart type mara-mtart,
end of ty_mara.
types: begin of ty_marc, " Plant Data
matnr type marc-matnr,
werks type marc-werks,
end of ty_marc.
types: begin of ty_final, " Combined data
matnr type mara-matnr,
mtart type mara-mtart,
werks type marc-werks,
end of ty_final.
data: it_mara type table of ty_mara,
wa_mara type ty_mara,
it_marc type table of ty_marc,
wa_marc type ty_marc,
it_final type table of ty_final,
wa_final type ty_final.
select matnr mtart from mara up to 10 rows into table it_mara.
select matnr werks from marc up to 10 rows into table it_marc for all entries in it_mara where matnr = it_mara-matnr.
loop at it_mara into wa_mara.
Move: wa_mara-matnr to wa_final-matnr,
wa_mara-mtart to wa_final-mtart.
read table it_marc into wa_marc with key matnr = wa_mara-matnr.
if sy-subrc = 0.
move wa_marc-werks to wa_final-werks.
append wa_final to it_final.
clear wa_final.
endif.
endloop.
<b>Reward Points if this helps,</b>
Regards,
Satish