10-09-2007 3:47 PM
Can I populate one internal table by taking data from three different database tables? because the fields of the internal table which I have declared are taken from three different tables. Can any one please tell me how will be the select statement ?
10-09-2007 3:50 PM
hi,
you have to use JOIN, read the documentation in SAPhelp and come back if you need more information. If you tell the name of the tables I can help more.
regards
ec
10-09-2007 3:51 PM
hi,
check this program to extract data from two internal tables in to final table,
to combine three internal tables, there should be some common link between the three internal tables
TABLES : KNA1,KNVV.
SELECTION-SCREEN : BEGIN OF BLOCK b1 WITH FRAME TITLE text-101.
select-options : p_kunnr like kna1-kunnr.
SELECTION-SCREEN : END OF BLOCK b1.
data :BEGIN OF T_KNA1 OCCURS 0,
KUNNR LIKE KNA1-KUNNR,
LAND1 LIKE KNA1-LAND1,
NAME1 LIKE KNA1-NAME1,
END OF T_KNA1.
DATA :BEGIN OF T_KNVV OCCURS 0,
KUNNR LIKE KNA1-KUNNR,
VKORG LIKE KNA1-VKORG
VTEWG LIKE KNA1-VTEWG,
END OF T_KNVV.
FINAL INTERNAL TABLE
DATA : BEGIN OF T_FINAL OCCURS 0,
KUNNR LIKE KNA1-KUNNR,
LAND1 LIKE KNA1-LAND1,
NAME1 LIKE KNA1-NAME1,
VKORG LIKE KNA1-VKORG
VTEWG LIKE KNA1-VTEWG,
END OF T_FINAL.
START-OF-SELECTION
SELECT KUNNR LAND1 NAME1 FROM KNA1 INTO TABLE T_KNA1 WHERE KUNNR IN P_KUNNR
IF SY-SUBRC = 0.
select KUNNR
VKORG VTEWG
from KNVV
into CORRESPONDING FIELDS OF table T_KNVV
for all entries in T_KNA1
where KUNNR = T_KNA1-KUNNR.
ENDIF.
LOOP AT T_KNA1.
MOVE T_KNA1-KUNNR TO T_FINAL-KUNNR.
MOVE T_KNA1-LAND1 TO T_FINAL-LAND1.
MOVE T_KNA1-NAME1 TO T_FINAL-NAME1.
READ TABLE T_KNVV WITH KEY KUNNR = T_KNA1-KUNNR.
IF SY-SUBRC = 0.
MOVE T_KNVV-VKORG TO T_FINAL-VKORG.
MOVE T_KNVV-VTEWG TO T_FINAL-VTEWG.
ENDIF.
APPEND T_FINAL.
CLEAR T_FINAL.
ENDLOOP.
LOOP AT T_FINAL.
WRITE: (FIELDS U WANT TO DISPLAY)
ENDLOOP.
regards
siva
10-09-2007 3:51 PM
Hi,
declare 1 internal table itab say with all fields u want.
say itab1 , itab2 , itab3 are the tables storing your selected data.
loop at itab1.
move fields to corresponding fields of itab.
read itab1.
if sy-subrc EQ 0.
populate itab with values from itab1.
endif.
read itab2.
if sy-subrc EQ 0.
populate itab with values from itab2.
endif.
..... repeat this for itab3.
append itab.
endloop.
reward if solved**