Skip to Content
avatar image
Former Member

hey all!

can i populate one internal table by taking data from three different databse tables

...... because the internal table contains fields from different tables....???

what kind of sql query it will be.

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

4 Answers

  • Best Answer
    Oct 10, 2007 at 05:11 AM

    Hi,

    You can use JOIN statement. Check the below code.

    DATA: BEGIN OF WA,

    CARRID TYPE SPFLI-CARRID,

    CONNID TYPE SPFLI-CONNID,

    FLDATE TYPE SFLIGHT-FLDATE,

    BOOKID TYPE SBOOK-BOOKID,

    END OF WA,

    ITAB LIKE SORTED TABLE OF WA

    WITH UNIQUE KEY CARRID CONNID FLDATE BOOKID.

    SELECT PCARRID PCONNID FFLDATE BBOOKID

    INTO CORRESPONDING FIELDS OF TABLE ITAB

    FROM ( ( SPFLI AS P

    INNER JOIN SFLIGHT AS F ON PCARRID = FCARRID AND

    PCONNID = FCONNID )

    INNER JOIN SBOOK AS B ON BCARRID = FCARRID AND

    BCONNID = FCONNID AND

    BFLDATE = FFLDATE )

    WHERE P~CITYFROM = 'FRANKFURT' AND

    P~CITYTO = 'NEW YORK' AND

    FSEATSMAX > FSEATSOCC.

    LOOP AT ITAB INTO WA.

    AT NEW FLDATE.

    WRITE: / WA-CARRID, WA-CONNID, WA-FLDATE.

    ENDAT.

    WRITE / WA-BOOKID.

    ENDLOOP.

    Add comment
    10|10000 characters needed characters exceeded

  • Oct 10, 2007 at 05:10 AM

    Jyoti,

    U can do it as shown below,

    SELECT VBAK~KUNNR

    VBAK~VBELN

    VBAK~AUDAT

    VBAK~VBTYP

    VBAP~MATNR

    VBAP~ZMENG

    VBAP~NETPR

    VBAP~NETWR

    MAKT~MAKTX

    INTO TABLE IT_OUTPUT

    FROM VBAK

    INNER JOIN VBAP ON VBAKVBELN EQ VBAPVBELN

    INNER JOIN MAKT ON VBAPMATNR EQ MAKTMATNR

    WHERE VBAK~KUNNR IN SKUNNR

    VBAK~AUDAT IN SAUDAT

    VBAK~VBTYP IN SVBTYP

    MAKT~SPRAS EQ SY-LANGU.

    Reward if helpful,

    Karthik

    Message was edited by:

    Karthik Potharaju

    Add comment
    10|10000 characters needed characters exceeded

  • Oct 10, 2007 at 05:13 AM

    Hi ..

    We can use the INNER JOIN for this..

    Eg:

    SELECT MARAMATNR MARAMTART

    MAKT~MAKTX

    MARCWERKS MARCEKGRP

    FROM MARA

    INNER JOIN MAKT

    ON MARAMATNR = MAKTMATNR

    INNER JOIN MARC

    ON MARAMATNR = MARCMATNR

    INTO TABLE ITAB.

    reward if Helpful.

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Oct 10, 2007 at 05:22 AM

    1 way is by using JOINS

    2 by selecting data from one table and then filling rest of cols by using MODIFY cmd

    Regards

    Add comment
    10|10000 characters needed characters exceeded