Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Please Help!

Former Member
0 Kudos

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 ?

3 REPLIES 3

JozsefSzikszai
Active Contributor
0 Kudos

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

Former Member
0 Kudos

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

Former Member
0 Kudos

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**