How to populate an internal table from three different tables

My requirement is to populate an itab by retrieving data from three diff db tables,
ekko,ekpo and Ekbe.
below is the code for data retrieval .
SELECT EBELN INTO TABLE IT_EKKO FROM EKKO WHERE EBELN IN S_EBELN.
  IF NOT IT_EKKO[] IS INITIAL.
    SELECT  EBELP TXZ01 NETWR BUKRS INTO CORRESPONDING FIELDS OF TABLE IT_EKPO FROM EKPO FOR ALL ENTRIES IN IT_EKKO
      WHERE EBELN EQ IT_EKKO-EBELN.
IF NOT IT_EKPO[] IS INITIAL.
      SELECT  EMATN WAERS WERKS GJAHR BEWTP INTO CORRESPONDING FIELDS OF TABLE IT_EKBE FROM EKBE FOR ALL ENTRIES IN IT_EKPO
        WHERE EBELN EQ IT_EKPO-EBELN
         AND  EBELP EQ IT_EKPO-EBELP
         AND  BEWTP EQ 'E' OR BEWTP EQ 'Q'.
        ENDIF.
        ENDIF.
please tell me how to populate data from it_ekko,it_ekpo and it_ekbe into an internal table ITAB.

Hi Mayana,
You take one final structure & final internal table, & within that structure take all the fields which is required to be displayed as a final output.
for data fetching from different table, you take three different structures & three internal table for that, because into corresponding fields of table is not good for performance wise. Use into table syntax.
follow the below example:(similarly)
sort it_klah by key fields.
LOOP AT IT_KSSK INTO WA_KSSK.
    READ TABLE IT_KLAH INTO WA_KLAH WITH KEY CLINT = WA_KSSK-CLINT
                                             KLART = WA_KSSK-KLART.
    IF SY-SUBRC EQ 0.
      MOVE:  WA_KLAH-OBJEK to WA_final-OBJEK.
Read another table........(2nd one)
IF SY-SUBRC EQ 0.
      MOVE:  ....................................
      APPEND WA_final TO IT_final.
    ENDIF.
clear wa_final.
  ENDLOOP.
finally display it_final records.
Hope this can solve your problems.
Regards,
Tutun

Similar Messages

  • Create one tables from 2 different tables

    Hi,
    How I can create one table from 2 different tables. Source tables have data and I want to include it in new table.
    I try this:
    create table NEW_ONE
    select * from OLD_ONE
    union
    select * from OLD_ONE2;
    But it didn't work correctly :/

    I don't have any error. This syntax create table NEW_ONE, but this table have columns only from OLD_ONE table :/ There aren't any column from OLD_ONE2 :/ Any suggestions?
    I don't forget about "as" in my query, only in this post.
    Edited by: tutus on Sep 8, 2008 6:36 AM

  • How to create a foreign key for the table from two different tables?

    Hi All,
    I have a three table like below. In the below table SAMPLE_CONS_CHECK and SAMPLE_CONS2_CHECK will be having the primary key for NAME column. The same SAMPLE_CONS3_CHECK table also having the primary key for NAME column and forieign key for SAMPLE_CONS_CHECK and SAMPLE_CONS2_CHECK tables. See the below code 2
    code 1:
    CREATE TABLE SAMPLE_CONS_CHECK
            (NAME VARCHAR2(10),
            SERIES  VARCHAR2(5)
    CREATE TABLE SAMPLE_CONS2_CHECK
            (NAME  VARCHAR2(5),
             MODEL  NUMBER
    CREATE TABLE SAMPLE_CONS3_CHECK
            (NAME  VARCHAR2(5),
             MODEL_NO  NUMBER
            )code 2
    alter table SAMPLE_CONS_CHECK
    add constraint SAMPLE_CONS_CHECK_pk primary key (NAME)
    alter table SAMPLE_CONS2_CHECK
    add constraint SAMPLE_CONS2_CHECK_pk primary key (NAME)
    alter table SAMPLE_CONS3_CHECK
    add constraint SAMPLE_CONS3_CHECK_pk primary key (NAME)
    ALTER TABLE SAMPLE_CONS3_CHECK ADD
    CONSTRAINT SAMPLE_CONS3_CHECK_FK1 FOREIGN KEY
         NAME
    ) REFERENCES SAMPLE_CONS_CHECK
        NAME
    ) ON DELETE CASCADE;
    ALTER TABLE SAMPLE_CONS3_CHECK ADD
    CONSTRAINT SAMPLE_CONS3_CHECK_FK2 FOREIGN KEY
         NAME
    ) REFERENCES SAMPLE_CONS2_CHECK
        NAME
    ) ON DELETE CASCADE;From the above schenario i am able to insert the data to SAMPLE_CONS3_CHECK table. But the parent data is already available in the parent table. The problem is here two different constarints from two different tables. While inserting, it is checking from both the tables whether the parent is exist or not.
    How can i solve this problem? Can anyone halp me about this?
    Thanks
    Edited by: orasuriya on Aug 8, 2009 2:02 AM

    Actually the design is completely incorrect.
    What you say is
    I have
    'foo', 'foo series'
    'foo','foo model'
    'foo',666
    By virtue of table3 referring to both table1 and table2.
    This means you actually need to have 1 (one) table:
    'foo','foo series','foo model', 666
    And the 'problem' disappears.
    Sybrand Bakker
    Senior Oracle DBA

  • How to populate last 10 records from data base table

    Hi,
    My requirement is to populate last 10 transfer order items confirmed from LTAP. as the table is too large there is no point to fetch all the records and filter them...
    Please let me know better way (in terms of performace) to get last 10 records from LTAP.
    Thanks in advance.
    Nag

    Hi brother,
    the following code is working......(sample code)
    data itmara type mara occurs 0 with header line.
    select matnr from mara into corresponding fields of table itmara up to 20 rows.
    sort itmara descending by matnr.
    loop at itmara .
    write:/ itmara-matnr.
    if sy-tabix = 10.
    exit.
    endif.
    endloop.
    plz reward with maximum points
    Edited by: sreejith gn on May 13, 2008 12:52 PM

  • How do I fill a column from a different table

    I am using numbers V3.5 on Yosemite V10.10 and have a question about filling table columns.  I want the new table to ignore some values in the original column.  The first table is a has a matrix of values for multiple stocks and accounts.
    I would like to create a new table for a specific account with only the stocks listed that have a value > $0.  The table would appear something like this.
    I have looked at other posts but could not apply what I have found to this problem.  TIA for any suggestions

    Hi Marty,
    I would suggest you use a filter on your account column- >0 after your bring your data over.
    quinn

  • Creating LOV from 2 different tables

    I tried doing some searches on this, but haven't been able to find an answer. Can I create an LOV (to populate a select list) from two different tables? Both tables have the exact same column names/datatypes, just different data.
    Or if this isn't possible, should I just create a new table, and then do a union query to populate it with the values from both of these tables? Just wondering if anyone's had experience with this situation. Thanks!

    Hmm. That is weird. Wonder why it's not working for me.
    The SORT_ORDER column appears in both tables. I was hoping to be able to sort by the number value that appears in this column in both tables (could duplicate values in this table be causing an issue?).
    I even tried changing it to:
    SELECT DISPLAY_AS d1, CONTENT_KEY v1
    FROM SER_LISTS_JOB_TYPE
    WHERE ACTIVE = 'YES'
    UNION
    SELECT DISPLAY_AS d2, CONTENT_KEY v2
    FROM SER_LISTS_COMPANY_TYPE
    WHERE ACTIVE = 'YES'
    ORDER BY SORT_ORDERBut still get the same error message.
    Message was edited by:
    taneal
    OK. It appears the ORDER BY SORT_ORDER was causing the issue. I took it out and it worked. The only problem is that I have 1 duplicate entry, called "Other" that now appears twice in my LOV. Any thoughts on this? The value of CONTENT_KEY is different, but the value for DISPLAY_AS is the same. Is there anyway to pull out one of these?

  • How to join THREE different tables into internal table using one select statement .

    How to join THREE different tables into internal table using one select statement .
    Hi experts,
    I would like to request your guidance in solving the problem of joining the data from three different database tables into one internal table
    Scenario:
    Database tables:
    SPFLI
    SFLIGHT
    SBOOK.
    Table Fields:
    SPFLI - CARRID CONNID COUNTRYFR CITYFRM COUNTRYTO CITYTO
    SFLIGHT - CARRID CONNID FLDATE SEATSMAX SEATSOCC SEATSMAX_C
    SEATSOCC_C SEATSMAX_F SEATSOCC_F
    SBOOK - CARRID CONNID CLASS
    MY INTERNAL TABLE IS IT_XX.
    Your help much appreciated.
    Thanks in advance.
    Pawan.

    Hi Pawan,
    please check below codes. hope it can help you.
    TYPES: BEGIN OF ty_xx,
            carrid     TYPE spfli-carrid   ,
            connid     TYPE spfli-connid   ,
            countryfr  TYPE spfli-countryfr,
            cityfrom   TYPE spfli-cityfrom  ,
            countryto  TYPE spfli-countryto,
            cityto     TYPE spfli-cityto   ,
            fldate     TYPE sflight-fldate ,
            seatsmax   TYPE sflight-seatsmax ,
            seatsocc   TYPE sflight-seatsocc ,
            seatsmax_b TYPE sflight-seatsmax_b,
            seatsocc_b TYPE sflight-seatsocc_b,
            seatsmax_f TYPE sflight-seatsmax_f,
            seatsocc_f TYPE sflight-seatsocc_f,
            class      TYPE sbook-class,
          END OF ty_xx,
          t_xx TYPE STANDARD TABLE OF ty_xx.
    DATA: it_xx TYPE t_xx.
    SELECT spfli~carrid
           spfli~connid
           spfli~countryfr
           spfli~cityfrom
           spfli~countryto
           spfli~cityto
           sflight~fldate
           sflight~seatsmax
           sflight~seatsocc
           sflight~seatsmax_b
           sflight~seatsocc_b
           sflight~seatsmax_f
           sflight~seatsocc_f
           sbook~class
      INTO TABLE it_xx
      FROM spfli INNER JOIN sflight
      ON spfli~carrid = sflight~carrid
      AND spfli~connid = sflight~connid
      INNER JOIN sbook
      ON spfli~carrid = sbook~carrid
      AND spfli~connid = sbook~connid.
    Thanks,
    Yawa

  • How to move data from a staging table to three entity tables #2

    Environment: SQL Server 2008 R2
    I have a few questions:
    How would I prevent duplicate records, when/ IF SSIS is executed many times?
    How would I know that all huge volume of data being loaded in the entity tables?
    In reference to "how to move data from a staging table to three entity tables ", since I am loading large volume of data, while using lookup transformation:
    which of the merge components is best suited.
    How to configure merge component correctly. (screen shot is preferred) 
    Please refer to the following link
    http://social.msdn.microsoft.com/Forums/en-US/5f2128c8-3ddd-4455-9076-05fa1902a62a/how-to-move-data-from-a-staging-table-to-three-entity-tables?forum=sqlintegrationservices

    You can use RowCount transformation in the path where you want to capture record details. Then inside rowcount transformation pass a integer variable to get count value inside
    the event handler can be configured as below
    Inside Execute SQL task add INSERT statement to add rowcount to your audit table
    Can you also show me how to Check against destination table using key columns inside a lookup task and insert only non
    matched records (No Match output)
    This is explained clearly in below link which Arthur posted
    http://www.sqlis.com/sqlis/post/Get-all-from-Table-A-that-isnt-in-Table-B.aspx
    For large data I would prefer doing this in T-SQL. So what you could do is dump data to staging table and then apply
    T-SQL MERGE between tables (or even a combination of INSERT/UPDATE statements)
    Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs

  • Hello Anybody, I have a question. Can any of you please suggest me how to make an xml file from the database table with all the rows? Note:- I am having the XSD Schema file and the resulted XML file should be in that XSD format only.

    Hello Anybody, I have a question. Can any of you please suggest me how to make an xml file from the database table with all the records?
    Note:- I am having the XSD Schema file and the resulted XML file should be in that XSD format only.

    The Oracle documentation has a good overview of the options available
    Generating XML Data from the Database
    Without knowing your version, I just picked 11.2, so you made need to look for that chapter in the documentation for your version to find applicable information.
    You can also find some information in XML DB FAQ

  • How can i import tables from a different schema into the existing relational model... to add these tables in the existing model? plss help

    how can i import tables from a different schema into the existing relational model... to add these tables in the existing relational/logical model? plss help
    note; I already have the relational/logical model ready from one schema... and I need to add few more tables to this relational/logical model
    can I import the same way as I did previously??
    but even if I do the same how can I add it in the model?? as the logical model has already been engineered..
    please help ...
    thanks

    Hi,
    Before you start, you should probably take a backup copy of your design (the .dmd file and associated folder), in case the update does not work out as you had hoped.
    You need to use Import > Data Dictionary again, to start the Data Dictionary Import Wizard.
    In step 1 use a suitable database connection that can access the relevant table definitions.
    In step 2 select the schema (or schemas) to import.  The "Import to" field in the lower left part of the main panel allows you to select which existing Relational Model to import into (or to specify that a new Relational Model is to be created).
    In step 3 select the tables to import.  (Note that if there are an Foreign Key constraints between the new tables and any tables you had previously imported, you should also include the previous tables, otherwise the Foreign Key constraints will not be imported.)
    After the import itself has completed, the "Compare Models" dialog is displayed.  This shows the differences between the model being imported and the previous state of the model, and allows you to select which changes are to be applied.
    Just selecting the Merge button should apply all the additions and changes in the new import.
    Having updated your Relational Model, you can then update your Logical Model.  To do this you repeat the "Engineer to Logical Model".  This displays the "Engineer to Logical Model" dialog, which shows the changes which will be applied to the Logical Model, and allows you to select which changes are to be applied.
    Just selecting the Engineer button should apply all the additions and changes.
    I hope this helps you achieve what you want.
    David

  • How to use dynamic select query which queries from 3 different table.

    Hi All,
    I am new to Toplink, i would like to use a named query to select some of the columns from 3 different tables with dynamic where clause.
    I have used the following lines. Please tell me how to get code for the dynamic where clause.
    First try :
    Vector objPersons = (Vector)session.executeQuery("findPersonByGlobalID",Person.class,vQueryArguments);
    The above method is not returning the vector or collection.
    Second Try:
    ReadAllQuery query = new ReadAllQuery(Person.class);
    query.useCollectionClass(LinkedList.class);
    LinkedList person = (LinkedList) session.executeQuery(query);
    The second try is returning the collection but, this fetches all the record from the table.
    1. How to query for range of records?
    2. How to query from multiple tables for some range. How to use dynamic range values ?
    Please reply with your answers or some pointers would help.
    Thanks and Regards,
    Vijay.B

    Hi,
    Did you try using a SQLCall ? It might be able to satisfy you requirements .. :-
    Employee employee = (Employee) session.executeSelectingCall(
        new SQLCall("SELECT * FROM EMPLOYEE WHERE EMP_ID = 44")
    );You can get more information here :-
    http://www.oracle.com/technology/products/ias/toplink/doc/1013/MAIN/_html/qrybas004.htm
    Regards,
    Sandeep

  • How to create a table from an existing table with new column

    Hi !
    Please help me.
    I want to create a table from an existing table with data and add two new column to the new table.
    What will be the syntax?

    craete table new_table as select a.*, 'somevalue' new_col1, 'somevalue'
    new_col2 from old_table a;Also there is a pitfall - newly created table will accept column type and precision from the select statement, so further you can be needed to modify columns
    if you want to have VARCHAR2 instead of CHAR for example:
    SQL> create table new_dept as select dept.*, 'New data' new_col from dept;
    Table created.
    SQL> desc new_dept
    Name                                      Null?    Type
    DEPTNO                                             NUMBER(2)
    DNAME                                              VARCHAR2(14)
    LOC                                                VARCHAR2(13)
    NEW_COL                                            CHAR(8)
    SQL> alter table new_dept modify (new_col varchar2(8));
    Table altered.
    SQL> desc new_dept
    Name                                      Null?    Type
    DEPTNO                                             NUMBER(2)
    DNAME                                              VARCHAR2(14)
    LOC                                                VARCHAR2(13)
    NEW_COL                                            VARCHAR2(8)Rgds.
    Didn't see michael's post - it reflects the fix for this problem using CAST.
    Message was edited by:
    dnikiforov

  • Insert data into fact table from source database tables

    here i try to insert data into fact table from source database tables here is the query 
    ALTER procedure [dbo].[facttable]
    as
    insert into [pp dw].dbo.Dimfact(Prod_ID,Production_ID,Material_ID,Equip_ID,WC_ID,Recipe_ID,Quantity,costprice)
    select Products.[Product ID],[Production ID],Materials.[Material ID],[Equipment ID],[Work Centre ID],[Recipy ID],Quantity,[cost price]
    from
    [PRODUCTION PLANNING 2].dbo.[Products],
    [PRODUCTION PLANNING 2].dbo.[Production Detail],
    [PRODUCTION PLANNING 2].dbo.[Material category],
    [PRODUCTION PLANNING 2].dbo.[Materials],
    [PRODUCTION PLANNING 2].dbo.[Equipment],
    [PRODUCTION PLANNING 2].dbo.[Working Centre] ,
    [PRODUCTION PLANNING 2].dbo.[Recipies]
    where
    Products.[Product ID] in (13, 14, 15, 16, 17) and
    [Production Detail].[Production ID] in (1, 2, 3) and
    [Materials].[Material ID] in (1, 2, 3, 4, 5) and
    [Equipment].[Equipment ID] in (1, 2, 3, 4) and
    [Working Centre].[Work Centre ID] in (1, 2, 3) and
    [Recipies].[Recipy ID] in (1, 2, 3) and
    [Material category].[Category ID] in (8, 9, 10, 11, 12, 13)
    and when i execute query it shows me error 
    The INSERT statement conflicted with the FOREIGN KEY constraint "FK_Dimfact_Dimproduct". The conflict occurred in database "pp dw", table "dbo.Dimproduct", column 'Prod_ID'.
    ERD IS
    HOW TO SOLVE THIS PROBLEM?

    I cant see any join conditions in your query posted. Whats the purpose of the query above. It will just bring you a cartesian product (cross join) of tables involved subjected to filters. Are you sure this is the correct query?
    The error you're getting may be because you've not yet populated DimProduct or may be because of logic you used in popultaing DimProduct causing it to miss some records which is what query is referring to in above case.
    Please Mark This As Answer if it solved your issue
    Please Mark This As Helpful if it helps to solve your issue
    Visakh
    My MSDN Page
    My Personal Blog
    My Facebook Page

  • Selecting data from two different tables.

    Do we need to use join two tables with primary/foreign key while trying to use select statement for getting data from those to table.? If no who can i go about do it.

    872959 wrote:
    If i am using From clause to get data from two different tables, is it necessary that both tables have column of identical data in them.In general, they ought to (or you need to join in a third table that tells you how to map rows from one table to rows of the other table).
    It is not strictly necessary that there be any join condition between tables. If you don't provide a join condition, Oracle has to do a Cartesian product. That means that if there are n rows in one table and m rows in the other, the result set will have n * m rows. It is very rarely a good idea to write queries that do Cartesian products but it does occasionally happen.
    Justin

  • Can we run an assignment on a qualified table from a main table?

    Can I run an assignment on a qualified table from a main table.
    For example: My main table Vendor and Qualified  Table is Company Qualified .
    Company Qualified - VendorNr (Non- Qualifier),Company(Qualifier,lookupFlat - Company)
    Company  - Name,Description (It has valid values in it already).
    How to add a default value into the Company Qualified table.
    When i add a assignment like
    If(is_null(Company Qualified [Record],default lookup value from Company)  ...it says invalid.
    Any help greatly appreciated  thanks

    This is not possible currently in MDM.  I've tried many times to find a good way to do this and so far have been unsuccessful.  I also have tried to have a workflow on the main table call an assignment in a lookup / qualified table, and that doesn't work either.  The biggest reason is because you have to select a table field when you create an assignment, and it doesn't give you the option to choose fields within a table.
    Hopefully they will address this in a future release.
    Edited by: Harrison Holland on Jun 3, 2008 2:33 PM

Maybe you are looking for

  • How to fix a corrupt QuickTime file?

    Hey all, Today I recorded all of our church services via iMovie (one long 4 hour clip), as I have been doing for more than a month now. However, the guy running the camera turned the camera off before I told iMovie to stop importing, so iMovie litera

  • How to color correct this:

    Hi, I need help with a color correction. How would you grade the right image to get the look of the left one? Regards from Germany.

  • Simulation Loop ODE Solver

    I keep getting Error 2324: Labview Simulation Module: The ODE solver cannot meet the error tolerance using the minimum step size. I've broken my code down and my signal multiplication function seems to be the cause. If I don't multiply things it work

  • Complex BI structure not displayed correct

    Hello Expert, I am using the latest Portal Version. I want to realize some VC Dashboards. Unfortunately - like mentioned in note 936768 - complex structures are not supported. I cannot believe that this true ? Does anybody know - how long this note i

  • [iPhone] Can't play multiple compressed sounds, seems to block!

    I'm writing an app that needs to play a variety of audio samples of different lengths back to back, but only one at a time. The system I came up with works great when using WAV files or whenever running on the simulator no matter what audio type, but