Skip to Content

how to add 3 different fields from 3 diffrent internal table into a single internal table

hi abapers,


how i can achieve the following steps?? please help me as i am new to this abap thing.

Thanks in adv.


1. Select field1, field2 from table db1

Where field1 starts with ‘PR’ and

Field2 starts with ‘DJ’

2. for each field2 value, select field3 and field4

From db2 where

Field1 = field2 (from selection in 1.)

3. for each field1 value [from 1.] select field5 from db3

4. hold these combinations in LT_tab (field1[from 1.], field5 [from 3.], field3 [from 2.], field4 [from 2.])



Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

4 Answers

  • Best Answer
    Posted on Jan 07, 2014 at 12:48 PM

    It is better to provide actual table and field names, such generic placeholders make in unnecessarily difficult for others to properly understand the issue, and important information might be missing.

    If data from two or more DB tables must end up in one internal table, and these DB tables are logically related, then first look into using JOIN SELECTs as suggested by Asim. You can save yourself a lot of internal table handling and performance issues.

    Thomas

    Add a comment
    10|10000 characters needed characters exceeded

    • Hi Dhananjay,

      There won't be any "Performance Depreciation" but only "Appreciation'' 😉 if you use joins, since joins are better performers than ''FOR ALL ENTRIES IN''. FOR ALL ENTRIES show poor performance when the internal table size grows. What better solution you could ask when your need is fulfilled in one neat SELECT query. 😎

      Regards,

      Philip.

  • author's profile photo Former Member
    Former Member
    Posted on Jan 07, 2014 at 12:12 PM

    Hi Dhananjay ,

    I actually read your combination 3 times but i did not get it but you can use in select

    "WHERE field1 EQ 'PR%'. to choose which ones starting with PR if you just needs this than here is your answer if you need the all query if you can be more clear i will try to help you ...

    Add a comment
    10|10000 characters needed characters exceeded

    • Hi Dhanjay,

      tables : db2, db3.

      Select field1 field2 into corresponding fields of table lt_tab from table db2 where field1 like 'PR%' and field2 like 'DJ%'.

      loop at lt_tab into lw_tab.

      select single * into db2 from db2 where field2 = lw_tab-field2.

      select single * into db3 from db3 where field1 = lw_tab-field1.

      lw_tab-field3 = db2-field3.

      lw_tab-field4 = db2-field4.

      lw_tab-field5 = db5-field5.

      modify lt_tab from lw_tab.

      endloop.

      Else, use a join statement as suggested by Isik.

  • author's profile photo Former Member
    Former Member
    Posted on Jan 07, 2014 at 12:23 PM

    Hi,


    Create an internal table LT_tab containing (field1[from 1.], field5 [from 3.], field3 [from 2.], field4 [from 2.]) and a work area wa_final.

    Create internal table and work area of type db1, db2 and db3.

    1) Select field1 field2 from table db1

    Into Table int_tab1

    Where field1+0(2) = ‘PR’ and

    Field2+0(2) = ‘DJ’.


    2) Select field3 field4

    From db2 into table int_tab2

    for all entries in int_tab1

    where Field3 = int_tab1-field2.


    3) Select field5

    From db3 into table int_tab3

    for all entries in int_tab1

    where Field5 = int_tab1-field1.


    Loop at int_tab1 into wa1.

    Loop at int_tab2 into wa2 where field3 = wa1-field2.

    Loop at int_tab3 into wa3 where field5 = wa2-field1.

    wa_final-field1 = wa1-field1.

    wa_final-field3 = wa2-field3.

    wa_final-field4 = wa2-field4.

    wa_final-field5 = wa3-field5

    Append wa_final to lt_tab.

    clear wa_final.

    Endloop.

    Endloop.

    Endloop.



    Regards


    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member Dhananjay Choubey

      Instead of loop you can use read statement. Even that will work fine.

      Make sure you sort the table before loop and read.

      Read int_tab2 into wa2 with key field3 = wa1-field2.

      Read int_tab3 into wa3 with key field5 = wa2-field1.

      Hope this helps

      Regards

  • author's profile photo Former Member
    Former Member
    Posted on Jan 07, 2014 at 12:16 PM

    hi,

    You can make use of FOR ALL ENTRIES IN for the second and third select statements.

    now you will have 3 internal tables with correct values.. Move the values into one internal table by using MOVE-CORRESPONDING IT_T100 TO IT_ZT100.

    Regards,

    sivaganesh

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.