Concatenate two select query

Hi ABAPers,
Can you please tell me how to concatenate this two select qureies.
select  ebeln knumv from ekko  INTO
TABLE  tt_knumv
where ebeln = p_ebeln.
select ebeln knumv from eslh INTO TABLE
tt_knumv  FOR ALL ENTRIES IN tt_esll
where  packno = tt_esll-sub_packno.
Regards
Abhinab Mishra

Hi,
I dont think inner join is possible in this case since you are selecting the same fields from the two different tables into the single internal table vertically. It can be used to collect the data into the internal table horizontally but that would make no sense in this case. May be you can try something like this
data: t_temp type table of tt_knumv.
select ebeln knumv
from eslh
INTO TABLE tt_knumv
FOR ALL ENTRIES IN tt_esll
where  packno = tt_esll-sub_packno.
select  ebeln knumv
from ekko
INTO TABLE  t_temp
where ebeln = p_ebeln.
loop at t_temp.
move-corresponding t_temp to tt_knumv.
append tt_knumv.
endloop.
Regards,
Vik

Similar Messages

  • Two select query in sender JDBC adaptor

    Hi
    We are doing JDFC-RFC scenario, in which i need to fetch the data from two tables (header  and item table) whch correspondes to the 2 table parameter of RFC .
    Any clues how to configure sender jdbc CC having  2 select query ??????
    Regards
    Vijay

    Swatantra,
    You can have a look at the below URL for more info on JOIN.
    http://www.w3schools.com/sql/sql_join.asp
    Best regards,
    raj.

  • Combine two select query

    Hi All,
    Many thanks for all kind support so far.
    I have two report (sql query)
    I want to add both the sql query
    1st sql query
    select distinct(a.item_number)
          ,a.quantity - b.quantity
    from QUANTITY_ONHAND_ATP a,BACKLOG_ATP_LT_CW b
    where a.item_number = b.item_number
    order by item_number2nd sql query
    select distinct(wb.item_number)
           ,wb.quantity - be.quantity
           ,a.quantity - b.quantity
    from BACKLOG_WEEK_BEFORE_ATP wb
        ,BACKLOG_ATP_ET_CW be
        ,BACKLOG_WEEK_AFTER_ATP a
        ,BACKLOG_ATP_GT_CW b
    where wb.item_number = be.item_number
       and a.item_number = b.item_number
       and wb.item_number = a.item_number
       and be.item_number = a.item_number
       and wb.item_number = b.item_number
       and be.item_number = b.item_number
    order by wb.ITEM_NUMBERIn 1st sql query i have 129 records and in 2nd sql query i have 14 records. I want to combine these two sql query. If the item_number of 1st sql query is not there in 2nd one then display it as it is in 1st sql only.
    Any help how to do that.
    Regards

    Hi,
    the gerenal approach to combine the results of two or more SQL queries would be the
    UNION / UNION ALL
    INTERSECT
    MINUS
    SQL clauses. Union just combines the results; INTERSECT will return the rows which are present
    in both result sets and MINUS will reduce the first result set by the rows of the second.
    Basically it works like this
    select * from emp where deptno = 10
    union all(
    select * from empo where deptno = 20
    All the queries must have identical columns in the result set - same number of columns
    and the same data types. So you would have to add a column to your first SQL query ...
    select distinct(a.item_number) item_number,
    to_number(*,null*) first_value
    ,a.quantity - b.quantity second_value
    from QUANTITY_ONHAND_ATP a,BACKLOG_ATP_LT_CW b
    where a.item_number = b.item_number
    order by item_number
    and in the second query I'd recommend to use the same aliases ....
    Does this help
    -Carsten
    Deutschsprachige APEX-Community: Tipps, Tricks, Best Practice
    http://tinyurl.com/apexcommunity
    SQL und PL/SQL: Tipps, Tricks & Best Practice
    http://sql-plsql-de.blogspot.com
    Twitter: @cczarski

  • How can i use index in select query.. facing problem with the select query.

    Hi Friends,
    I am facing a serious problem in one of the select query. It is taking a lot of time to fetch data in Production Scenario.
    Here is the query:
      SELECT * APPENDING CORRESPONDING FIELDS OF TABLE tbl_summary
        FROM ztftelat LEFT JOIN ztfzberep
         ON  ztfzberep~gjahr = st_input-gjahr
         AND ztfzberep~poper = st_input-poper
         AND ztfzberepcntr  = ztftelatrprctr
        WHERE rldnr  = c_telstra_accounting
          AND rrcty  = c_actual
          AND rvers  = c_ver_001
          AND rbukrs = st_input-bukrs
          AND racct  = st_input-saknr
          AND ryear  = st_input-gjahr
          And rzzlstar in r_lstar                            
          AND rpmax  = c_max_period.
    There are 5 indices present for Table ZTFTELAT.
    Indices of ZTFTELAT:
      Name   Description                                               
      0        Primary key( RCLNT,RLDNR,RRCTY,RVERS,RYEAR,ROBJNR,SOBJNR,RTCUR,RUNIT,DRCRK,RPMAX)                                          
      005    Profit (RCLNT,RPRCTR)
      1        Ledger, company code, account (RLDNR,RBUKRS, RACCT)                                
      2        Ledger, company code, cost center (RLDNR, RBUKRS,RCNTR)                           
      3        Account, cost center (RACCT,RCNTR)                                        
      4        RCLNT/RLDNR/RRCTY/RVERS/RYEAR/RZZAUFNR                        
      Z01    Activity Type, Account (RZZLSTAR,RACCT)                                        
      Z02    RYEAR-RBUKRS- RZZZBER-RLDNR       
    Can anyone help me out why it is taking so much time and how we can reduce it ? and also tell me if I want to use index number 1 then how can I use?
    Thanks in advance.

    Hi Shiva,
    I am using two more select queries with the same manner ....
    here are the other two select query :
    ***************1************************
    SELECT * APPENDING CORRESPONDING FIELDS OF TABLE tbl_summary
        FROM ztftelpt LEFT JOIN ztfzberep
         ON  ztfzberep~gjahr = st_input-gjahr
         AND ztfzberep~poper = st_input-poper
         AND ztfzberepcntr  = ztftelptrprctr
        WHERE rldnr  = c_telstra_projects
          AND rrcty  = c_actual
          AND rvers  = c_ver_001
          AND rbukrs = st_input-bukrs
          AND racct  = st_input-saknr
          AND ryear  = st_input-gjahr
          and rzzlstar in r_lstar             
          AND rpmax  = c_max_period.
    and the second one is
    *************************2************************
      SELECT * APPENDING CORRESPONDING FIELDS OF TABLE tbl_summary
        FROM ztftelnt LEFT JOIN ztfzberep
         ON  ztfzberep~gjahr = st_input-gjahr
         AND ztfzberep~poper = st_input-poper
         AND ztfzberepcntr  = ztftelntrprctr
        WHERE rldnr  = c_telstra_networks
          AND rrcty  = c_actual
          AND rvers  = c_ver_001
          AND rbukrs = st_input-bukrs
          AND racct  = st_input-saknr
          AND ryear  = st_input-gjahr
          and rzzlstar in r_lstar                              
          AND rpmax  = c_max_period.
    for both the above table program is taking very less time .... although both the table used in above queries have similar amount of data. And i can not remove the APPENDING CORRESPONDING. because i have to append the data after fetching from the tables.  if i will not use it will delete all the data fetched earlier.
    Thanks on advanced......
    Sourabh

  • Select query is taking lot of time to fetch data.....

    Select query is taking lot of time to fetch data.
        SELECT algnum atanum  abdatu abzeit abname abenum bmatnr bmaktx bqdatu bqzeit bvlenr bnlenr bvltyp bvlber b~vlpla
               bnltyp bnlber bnlpla bvsola b~vorga INTO TABLE it_final FROM ltak AS a
                       INNER JOIN ltap AS b ON  btanum EQ atanum AND algnum EQ blgnum
                       WHERE a~lgnum = p_whno
                       AND a~tanum IN s_tono
                       AND a~bdatu IN s_tocd
                       AND a~bzeit IN s_bzeit
                       AND a~bname IN s_uname
                       AND a~betyp = 'P'
                       AND b~matnr IN s_mno
                       AND b~vorga <> 'ST'.
    Moderator message: Please Read before Posting in the Performance and Tuning Forum
    Edited by: Thomas Zloch on Mar 27, 2011 12:05 PM

    Hi Shiva,
    I am using two more select queries with the same manner ....
    here are the other two select query :
    ***************1************************
    SELECT * APPENDING CORRESPONDING FIELDS OF TABLE tbl_summary
        FROM ztftelpt LEFT JOIN ztfzberep
         ON  ztfzberep~gjahr = st_input-gjahr
         AND ztfzberep~poper = st_input-poper
         AND ztfzberepcntr  = ztftelptrprctr
        WHERE rldnr  = c_telstra_projects
          AND rrcty  = c_actual
          AND rvers  = c_ver_001
          AND rbukrs = st_input-bukrs
          AND racct  = st_input-saknr
          AND ryear  = st_input-gjahr
          and rzzlstar in r_lstar             
          AND rpmax  = c_max_period.
    and the second one is
    *************************2************************
      SELECT * APPENDING CORRESPONDING FIELDS OF TABLE tbl_summary
        FROM ztftelnt LEFT JOIN ztfzberep
         ON  ztfzberep~gjahr = st_input-gjahr
         AND ztfzberep~poper = st_input-poper
         AND ztfzberepcntr  = ztftelntrprctr
        WHERE rldnr  = c_telstra_networks
          AND rrcty  = c_actual
          AND rvers  = c_ver_001
          AND rbukrs = st_input-bukrs
          AND racct  = st_input-saknr
          AND ryear  = st_input-gjahr
          and rzzlstar in r_lstar                              
          AND rpmax  = c_max_period.
    for both the above table program is taking very less time .... although both the table used in above queries have similar amount of data. And i can not remove the APPENDING CORRESPONDING. because i have to append the data after fetching from the tables.  if i will not use it will delete all the data fetched earlier.
    Thanks on advanced......
    Sourabh

  • Questions on the most efficient select query..

    What is the difference between the two select query & please explain y is the 2nd select query more efficient??
    DATA: MAX_MSGNR type t100-msgnr.
    MAX_MSGNR = '000'.
    SELECT * FROM T100 INTO T100_WA
      WHERE SPRSL = 'D' AND
            ARBGB = '00'.
      CHECK: T100_WA-MSGNR > MAX_MSGNR.
      MAX_MSGNR = T100_WA-MSGNR.
    ENDSELECT.
    DATA: MAX_MSGNR type t100-msgnr.
    SELECT MAX( MSGNR ) FROM T100 INTO max_msgnr
      WHERE SPRSL = 'D' AND
            ARBGB = '00'.

    Hi,
    First never use Check statement in the Select.
    Next thing Select ... end select.
    Coming to ur question In case of first select it will fetch each record from the data base and compares that record value with the variable(MAX_MSGNR) and assigns the value to the variable. And this process will continue till the select reads all the records of the data base. Also these operations happens on the data base server. SO this query not only affect ur program but also others who is accessing the same data base.
    Second query is most efficient because of the aggregate function MAX. Here it will fetch all the records in single go and checks the max value for that column using
    optimising algorithm. So number of checks, assignments(single assignment) and fetches will be less compared to first select. This is the main reason. Hope this clarified ur doubt.
    Another thing is in first query we are selecting all the fields where as in second we are selecting only one field(required)
    Thanks,
    Vinod.
    Edited by: Vinod Kumar Vemuru on Mar 13, 2008 4:55 PM

  • How to concatenate two fields CSKS-KOSTL & CSKT-LTXT in BEx Query?

    Hi,
    I have a requirement to concatenate two fields CSKS-KOSTL (Cost Center) and CSKT-LTXT (Cost Center Text) and show them as one field in the BEx query.
    I do not know what to do, so please help me out.
    Thanks in advance.
    Regards
    Harman

    Hi Harman,
    If cost center is a masterdata, it can have its own text..i doubt why do u have 2 different fileds..
    Anyways if its a masterdata object maitaining its own text, then in the query properties under Display tab select Key&Text option this give you both key and text values in the output.
    If its two different fileds then its better to use concatenate in the transformation.
    Regards,
    Geetha

  • Select query in materialized view with two dblinks

    Hi All,
    We have oracle 10g On windows.
    We are trying to create materialized view. Scenario is we have base table on other database and we are creating mview on different database.
    Basa database have two schema's and i am selecting records from that two schema's using two private db links.
    But when i am tryin gto create mview its not getting created. After 15 hrs. its still showing creation command and not finished.
    Query is :-
    Is it good practice to have two db links in select query of materialized view.

    Billy  Verreynne  wrote:
    Chanchal Wankhade wrote:
    Is it good practice to have two db links in select query of materialized view.Same db link being used twice, or two different db links?
    If the former, you ideally want the local Oracle db to send the join to the remote database, and for the remote database to drive the join between those 2 tables. There is a hint (<i>driving_site</i>) that can be used - or the join query can be defined on the remote database as a view, and the local materialised view can then use that remote view.
    If you have 2 different db links and joining across these - usually a bad idea to perform distributed database joins. There are lots of limitations as to how the tables can be joined. Worse case, full table scans of both remote tables, pulling all the rows from the 2 remote database tables to the local database, and joining these on the local database.
    I have seen some severe performance issues in the past as a result of distributed joins. I'll rather use 2 materialised views for pulling both distributed tables's data locally, and then do the join on local data (using indexes, partition pruning, etc)Hi Billy,
    My scenario is i have two database database A and database B. Database A is having two schema's SCOTT AND HR. SCOTT schema have select privileges on HR schema.
    DB LINK is between Database B to Database A. name is db.link.B.A.oracle.com.
    What if i priovide while creating materialized view, the schema name before the table name in database B for this particuler table so it will pick up the table from that schema using same DB LINK(db.link.B.A.oracle.com.) that i am using to fetch records from SCOTT schema.
    Above schnario is like two base schema's and one db link using two schema.

  • Can we use concatenate in where clause of a select query

    I have a select query as follows....
        SELECT ebeln ebelp belnr vgabe bwart DMBTR
                                 FROM ekbe
                                 INTO TABLE i_ekbe
                                 FOR ALL ENTRIES IN i_blck
                                 WHERE ebeln =  i_blck-ebeln AND ebelp =                                                                               
    i_blck-ebelp.
    Now i want to retrieve data from BKPF ..can i write a select query something like....
    select * from BKPF into itab
                FOR ALL ENTRIES IN i_ekbe
                where awkey = ( conatenate i_ekbe-belnr i_ekbe-gjahr )
    OR ELSE...is there any other way to link table ekbe and bseg ???

    Hi Poonam,
    SELECT ebeln ebelp belnr vgabe bwart DMBTR
    FROM ekbe
    INTO TABLE i_ekbe
    FOR ALL ENTRIES IN i_blck
    WHERE ebeln = i_blck-ebeln
    AND ebelp = i_blck-ebelp.
    select *
    from BKPF
    into  table itab
    FOR ALL ENTRIES IN i_ekbe
    where belnr = i_ekbe-belnr.
    If u want to check with AWKEY concatenate into seperate field and then use to check in where condition.
    data: lw_awkey(20) type c.
    CONCATENATE  i_ekbe-belnr  i_ekbe-gjahr  INTO lw_awkey.
    select *
    from BKPF
    into  table itab
    FOR ALL ENTRIES IN i_ekbe
    where awkey = lw_awkey
    Best regards,
    raam

  • Select query on two Database views

    Hi all,
    Can i fetch the data by writing a select query on two DATABASE VIEWS
    Because i am able to fetch data by writing a selct query on ONE DATABASE VIEW and ON TRANSPARANT TABLE
    but i am not able to fetch data by writing a query on TWO DATABASE VIEWS
    Query which i am able to fetch data is
    select * from CSKS where OBJNR = COVJ-OBJNR
    Query which i am NOT able to fetch data is
    Select * from COAS where OBJNR = COVJ-OBJNR
    Here
    COVJ is a DATABASE VIEW
    CSKS is a Transparant Table
    COAS is a DATABASE VIEW
    Thanks in advance
    Regards
    Ajay

    Hi
    I tried with code and I am able to fetch data from view COAS
    DATA:it_coas TYPE STANDARD TABLE OF coas.
    SELECT * FROM coas INTO TABLE it_coas.
    IF sy-subrc IS INITIAL.
      WRITE:/ 'Sucess'.
    ENDIF.
    I think in your case COAS view does not have a value for COVJ-OBJNR.
    Regards
    Srilaxmi

  • Select Query Using Two Tables

    Friends,
       I need to select some fields from two different tables which doesnot contain any field in common.How to Get this using a select query..
       But there is a field X in table 1 which is equalient to eight char of another field y in table 2.I tried using offset but it is giving error.
    Thanks in Advance
    Regards
    Yamini

    Hello,
    You can use a subquery
    SELECT * FROM SFLIGHT AS F INTO WA_SFLIGHT
        WHERE SEATSOCC < F~SEATSMAX
          AND EXISTS ( SELECT * FROM SPFLI
                        WHERE CARRID = F~CARRID
                           AND CONNID = F~CONNID
                           AND CITYFROM = 'FRANKFURT'
                           AND CITYTO = 'NEW YORK' )
          AND FLDATE BETWEEN '19990101' AND '19990331'.
      WRITE: / WA_SFLIGHT-CARRID, WA_SFLIGHT-CONNID,
               WA_SFLIGHT-FLDATE.
    ENDSELECT.
    or simply query the first table and then the second table with select endselect.
    select * from table a.
       select * from table b into output_table
                     where b-field1 eq a-field2.
    endselect.
    or read the data into one internal table loop at it and then query the other table.
    Regards,
    Shekhar Kulkarni

  • Select Query Between two dates...

    Hi Guru's,
    I need a Select Query between two dates, also if the record not found for any in between date then it should return NULL or 0 ...
    for Example
    1. I am having two records in DB for date 2-10-2008 & 4-10-2008
    2. Now suppose I have given Query for date between 1-10-2008 to 5-10-2008
    Then it should return me 5 records with valid values for 2 & 4 and NULL for other 1,3,5
    Thanks.

    Try like this:
    with
      t as
          select date '2008-10-02' as dt, 'Record #1 (in DB)' as str from dual union all
          select date '2008-10-04' as dt, 'Record #2 (in DB)' as str from dual
    select v.dt, t.str
      from (
             select date '2008-10-01' + level - 1 as dt
               from dual
             connect by level <= (date '2008-10-05' - date '2008-10-01') + 1
           ) v
      left join t
        on v.dt = t.dt
    order by 1

  • Concatenate name in select query...

    Hi Pals,
    I was wondering how to directly concetenate client name in the select query itself...
    Currently the code says :
    SELECT SINGLE NAME1 NAME2
               INTO (V_NAME1,V_NAME2)
               FROM KNA1
               WHERE KUNNR = I_PROJ-ZZCLIENT.
    CONCATENATE V_NAME1 V_NAME2 INTO I_PROJ-CLNAME SEPARATED BY SPACE.
    Can we say some thing like...
    SELECT SINGLE ( NAME1 + ' ' + NAME2 ) AS CLNAME
               INTO I_PROJ-CLNAME
               FROM KNA1
               WHERE KUNNR = I_PROJ-ZZCLIENT.
    But its giving error...
    Basically i need a single select query which would give me  space seperated clientname in I_PROJ directly
    Please help me...
    Regards,
    Abhishek B.

    Hi Abhishek,
    OPEN SQL.
    1. Sap works on the concept of Open Sql.
       ie. Sql  is database independent.
    2. ABAP Syntax does not have provision for
       using such EXPRESSIONS (like concatenate)
       directly in SQL.
    3. However u may use them in Native Sql.
    4. In open sql one can use aggregate functions
       like SUM COUNT etc.
       But Concatenate is not allowed.
    Hope u find the answer useful.
    (To newbees)
    U may please award points (if u find the reply useful)
    by clicking on the STAR on the left of the reply.
    Regards,
    Amit M.

  • Joining two tables having no common fields using one select query

    Hi Experts,
    How to join two tables which are NOT having any field in common using only one select query?
    Your help will be appreciated.
    Thank you.

    Identify a third table (or more tables) with common fields with your two tables, or change your question either removing JOIN or removing NO COMMON FIELDS, else you wont get many responses and will be left alone in outer space, as suggested by Thomas.
    If you acturally require what you written, better execute two select and merge the two internal tables merging every record from first table with every record of second table, til no more memory is available.
    Regards,
    Raymond

  • How to use offset in select query

    Suppose i have data like ssonje     00000001 as a one field in database table . i have to segregate this two data. how should I do this.the first part is of 12 characters and the last is of 10 character long.

    Hi Naveen,
    I am again in trouble, Now the requirement were changed. I am sending you the code which i had implemented.
    Now, the user enter username(ie UNAMED) and document id (ie. TEMPD) and the output should be doucment id, which has been search through database table RFDT , field SRTFD, this field contains both the username and the document id.
    That means: suppose user enters UNAMED as SSONJE and TEMPD as 0000000030, then i want to fier the select query from RFDT on field SRTFD and get only the document id of that user which user enter on input field-UNAMED.
    i had tried but result were not coming.
    please go through the code.
    data:uname type UF05A-UNAMD.
    data:temp type UF05A-TEMPD.
    TYPES: BEGIN OF TEITAB_RFDT,
           SRTFD TYPE RFDT-SRTFD,
           END OF TEITAB_RFDT.
    DATA: ITAB_RFDT TYPE TABLE OF TEITAB_RFDT.
    DATA: WA_RFDT TYPE TEITAB_RFDT.
    DATA: STR(22) TYPE c.
    SELECT-OPTIONS:UNAMED FOR uname,
    TEMPD FOR TEMP.
    UNAMED-option = 'CP'.
    append UNAMED.
    CONCATENATE UNAMED TEMPD INTO STR.
    SELECT SRTFD FROM RFDT INTO CORRESPONDING FIELDS OF TABLE ITAB_RFDT WHERE SRTFD eq str.
    LOOP AT ITAB_RFDT INTO WA_RFDT.
    SPLIT WA_RFDT AT SPACE INTO STR1 STR2.
      WRITE: / STR1,STR2.
    ENDLOOP.
    Please mentioned what is the way to do this.
    Thanks

Maybe you are looking for