Skip to Content
author's profile photo Former Member
Former Member

Regarding select statements

Hello experts,

Can we fetch data from two different database tables into one one internal table.

regards,

raman

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

4 Answers

  • author's profile photo Former Member
    Former Member
    Posted on Jul 10, 2007 at 11:13 AM

    <b>Below is the example of 3 table into one internal table .... using Joins</b>

    REPORT  zdemo_alvgrid                 .
    
    TABLES:   mara , mard , makt .
    
    type-pools: slis.                                 "ALV Declarations
    *Data Declaration
    *----------------
    TYPES: BEGIN OF t_Mara,
    matnr   like   mara-matnr  ,
    meins   like  mara-meins,
    werks   like mard-werks  ,
    lgort   like mard-lgort ,
    labst   like mard-labst ,
    maktx  like makt-maktx ,
     END OF t_Mara.
    
    DATA: it_Mara TYPE STANDARD TABLE OF t_Mara INITIAL SIZE 0,
          wa_Mara TYPE t_Mara.
    
    select-options  : p_mat  for  mara-matnr   ,
     p_werks  for   mard-werks ,
     p_lgort  for  mard-lgort.
    ************************************************************************
    *Start-of-selection.
    START-OF-SELECTION.
    
    perform data_retrieval.
    
    
    *&---------------------------------------------------------------------*
    *&      Form  DATA_RETRIEVAL
    *&---------------------------------------------------------------------*
    *       Retrieve data form EKPO table and populate itab it_Mara
    *----------------------------------------------------------------------*
    form data_retrieval.
    select mara~matnr mara~meins  mard~werks mard~lgort  mard~labst  makt~maktx  into  corresponding fields of  table  it_Mara
      from ( ( mara  join  mard  on   mard~matnr  =  mara~matnr   ) join
           makt  on   makt~matnr  =  mard~matnr )  where  mara~matnr in  p_mat
           and  mard~werks  in  p_werks
           and  mard~lgort  in p_lgort  .
    
    loop  at  it_Mara  into  wa_Mara .
    
    write : /  wa_Mara-matnr  ,  wa_Mara-maktx ,  wa_Mara-lgort  ,  wa_Mara-labst ,  wa_Mara-meins .
    
    endloop .
    
    
    endform.                    " DATA_RETRIEVAL

    reward points if it is usefull ....

    Girish

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jul 10, 2007 at 10:39 AM

    Hi Prakash,

    <b>Yes, You can.</b>

    Declare the internal table with the fields required from data base tables and get the data into interntal table using SELECT statement with JOINS/FOR ALL ENTRIES.

    DATA:

    BEGIN OF ITAB OCCURS 0,

    MATNR TYPE MARA-MATNR,

    WERKS TYPE MARC-WERKS,

    END OF ITAB.

    SELECT AMATNR BWERKS

    FROM MARA AS A

    INNER JOIN MARC AS B

    INTO TABLE ITAB

    ON AMATNR = BMATNR.

    Thanks,

    Vinay

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jul 10, 2007 at 10:40 AM

    Hello,

    Check this.

    data: begin of itab occurs 0,
             matnr like mara-matnr,
             maktx like makt-maktx,
            end of itab.
    select a~matnr b~maktx into table itab from mara as a inner join makt as b on a~matnr = b~matnr where b~spras = sy-langu.
    
    

    Vasanth

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jul 10, 2007 at 10:49 AM

    Hi,

    Yes.

    You can use SELECT statement with an inner join.

    Please check this link for sample code.

    http://www.sap-img.com/abap/inner-joins.htm

    SELECT afield1 afield2

    bfield3 cfield4 INTO TABLE itab

    FROM dbtab1 AS a INNER JOIN

    dbtab2 AS b ON bcodeno = acodeno

    INNER JOIN

    dbtab3 AS c ON ccodeno = bcodeno

    WHERE <whereclause>.

    Regards,

    Priyanka.

    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.