How to join these tables?

hi,
i was asked to create a view with select fields in these four tables. but i'm having a hard-time with the joins.
oe_order_headers
wsh_delivery_details
ra_customers
ra_addresses
can someone help.
thanks
allen

Allen Try this
--Execute this first
begin
fnd_client_info.set_org_context(204); --R11
mo_global.set_policy_context('S',204); --R12
end;
Run this sql..
select * from oe_order_headers_all a, oe_ship_to_orgs_v b,wsh_delivery_details d
where a.ship_to_org_id=b.organization_id
and a.header_id=d.source_header_id;
Thanks
Nagamohan

Similar Messages

  • How to join two tables

    hi
    how to join two tables using inner join  if the first table has two primary keys and second table has 3 primary keys

    Would describe type of joins in ABAP, which might differ with other joins.
    The join syntax represents a recursively nestable join expression. A join expression consists of a left-hand and a right- hand side, which are joined either by means of INNER JOIN or LEFT OUTER JOIN. Depending on the type of join, a join expression can be either an inner (INNER) or an outer (LEFT OUTER) join. Every join expression can be enclosed in round brackets. If a join expression is used, the SELECT command circumvents SAP buffering.
    On the left-hand side, either a single database table, a view dbtab_left, or a join expression join can be specified. On the right-hand side, a single database table or a view dbtab_right as well as join conditions join_cond can be specified after ON. In this way, a maximum of 24 join expressions that join 25 database tables or views with each other can be specified after FROM.
    AS can be used to specify an alternative table name tabalias for each of the specified database table names or for every view. A database table or a view can occur multiple times within a join expression and, in this case, have various alternative names.
    The syntax of the join conditions join_cond is the same as that of the sql_cond conditions after the addition WHERE, with the following differences:
    At least one comparison must be specified after ON.
    Individual comparisons may be joined using AND only.
    All comparisons must contain a column in the database table or the view dbtab_right on the right-hand side as an operand.
    The following additions not be used: NOT, LIKE, IN.
    No sub-queries may be used.
    For outer joins, only equality comparisons (=, EQ) are possible.
    If an outer join occurs after FROM, the join condition of every join expression must contain at least one comparison between columns on the left-hand and the right-hand side.
    In outer joins, all comparisons that contain columns as operands in the database table or the view dbtab_right on the right-hand side must be specified in the corresponding join condition. In the WHERE condition of the same SELECT command, these columns are not allowed as operands.
    Resulting set for inner join
    The inner join joins the columns of every selected line on the left- hand side with the columns of all lines on the right-hand side that jointly fulfil the join_cond condition. A line in the resulting set is created for every such line on the right-hand side. The content of the column on the left-hand side may be duplicated in this case. If none of the lines on the right-hand side fulfils the join_cond condition, no line is created in the resulting set.
    Resulting set for outer join
    The outer join basically creates the same resulting set as the inner join, with the difference that at least one line is created in the resulting set for every selected line on the left-hand side, even if no line on the right-hand side fulfils the join_cond condition. The columns on the right-hand side that do not fulfil the join_cond condition are filled with null values.
    Note
    If the same column name occurs in several database tables in a join expression, they have to be identified in all remaining additions of the SELECT statement by using the column selector ~.
    Example
    Join the columns carrname, connid, fldate of the database tables scarr, spfli and sflight by means of two inner joins. A list is created of the flights from p_cityfr to p_cityto. Alternative names are used for every table.
    PARAMETERS: p_cityfr TYPE spfli-cityfrom,
    p_cityto TYPE spfli-cityto.
    DATA: BEGIN OF wa,
    fldate TYPE sflight-fldate,
    carrname TYPE scarr-carrname,
    connid TYPE spfli-connid,
    END OF wa.
    DATA itab LIKE SORTED TABLE OF wa
    WITH UNIQUE KEY fldate carrname connid.
    SELECT ccarrname pconnid f~fldate
    INTO CORRESPONDING FIELDS OF TABLE itab
    FROM ( ( scarr AS c
    INNER JOIN spfli AS p ON pcarrid = ccarrid
    AND p~cityfrom = p_cityfr
    AND p~cityto = p_cityto )
    INNER JOIN sflight AS f ON fcarrid = pcarrid
    AND fconnid = pconnid ).
    LOOP AT itab INTO wa.
    WRITE: / wa-fldate, wa-carrname, wa-connid.
    ENDLOOP.
    Example
    Join the columns carrid, carrname and connid of the database tables scarr and spfli using an outer join. The column connid is set to the null value for all flights that do not fly from p_cityfr. This null value is then converted to the appropriate initial value when it is transferred to the assigned data object. The LOOP returns all airlines that do not fly from p_cityfr.
    PARAMETERS p_cityfr TYPE spfli-cityfrom.
    DATA: BEGIN OF wa,
    carrid TYPE scarr-carrid,
    carrname TYPE scarr-carrname,
    connid TYPE spfli-connid,
    END OF wa,
    itab LIKE SORTED TABLE OF wa
    WITH NON-UNIQUE KEY carrid.
    SELECT scarrid scarrname p~connid
    INTO CORRESPONDING FIELDS OF TABLE itab
    FROM scarr AS s
    LEFT OUTER JOIN spfli AS p ON scarrid = pcarrid
    AND p~cityfrom = p_cityfr.
    LOOP AT itab INTO wa.
    IF wa-connid = '0000'.
    WRITE: / wa-carrid, wa-carrname.
    ENDIF.
    ENDLOOP.

  • How to join KNA1 table with SOOD, SOST or SOES table?

    Hi,
    I am creating an infoset and I cant join KNA1 with any of the following tables: SOST, SOES or SOOD.
    I am looking to get the following fields from the following table:
    KNA1 - KUNNR: Customer Number
    SOES - STATUS: Status
    SOOD- OBJNAM : Send Method
    SOOD - OBJDES : Document Title
    SOOD - CRONAM : Created by
    SOES- MSGV1 : Recipient
    SOST - STAT - DATE : Send date
    SOST - STAT - TIME : Send time
    I tried adding knvp table to find a common field but cant seem to join them. SOST, SOES and SOOD are easily joined with each other but KNA1 or KNVP cannot be joined, is there any intermediate table that I should use to join these tables to get the customer number against them or is there any other solution. kindly help.
    Regards,
    Moaz

    Hi,
    please try to connect KNA1 with SOOD using
    CALL METHOD cl_binary_relation=>read_links
       EXPORTING
         is_object           = ls_lpor
         it_relation_options = lt_relat
       IMPORTING
         et_links            = lt_links.
    where ls_por-instid = kna1-kunnr, ls_por-typeid = 'KNA1' and ls_por-catid = 'BO'
    and  lt_relat contains a line option 'I' 'EQ' 'NOTE'.
    Regards,
    Klaus

  • How to join four tables in Update query??

    Please how to join four tables in a single query to update one table row??

    You can use this syntax to update. Here updation of 1 column to a constant value (50) in multiple rows in Table A based on an associated 'SOURCE' value in table B
    Table A joins to Table B based on the TableA.definition_id = TableB.Att_Def_id
    like..
    update TableA
    set value =50
    where
    TableA.definition_id = TableB.Att_Def_id
    and TABLEB.Source = 'NEWPRODUCT'

  • Could you please help me in joining these tables

    Could you please help me in joining these tables
    ra_customers
    oe_order_headers_all
    oe_order_lines_all
    mtl_system_items_b
    mtl_item_categories
    mtl_categories
    I wrote the condition like this.Is there any more possibilities for join
    Tell me what more to join in this query....?
    select x.customer_name,x.segment1,x.description,x.segment2,sum(x.week1) week1, sum(x.week2) week2,
    sum(x.week3) week3, sum(x.week4) week4, sum(x.week5) week5
              from
              select a.customer_name,d.segment1,d.description,f.segment2,
              case
              when to_char(to_date(c.request_date,'DD-MON-YYYY'),'w')= 1 then
    nvl(c.ordered_quantity,0)
              else null
              end as WEEK1,
              case
              when to_char(to_date(c.request_date,'DD-MON-YYYY'),'w')= 2 then
    nvl(c.ordered_quantity,0)
              else null
              end as WEEK2,
              case
              when to_char(to_date(c.request_date,'DD-MON-YYYY'),'w')= 3 then
    nvl(c.ordered_quantity,0)
              else null
              end as WEEK3,
              case
              when to_char(to_date(c.request_date,'DD-MON-YYYY'),'w')= 4 then
    nvl(c.ordered_quantity,0)
              else null
              end as WEEK4,
              case
              when to_char(to_date(c.request_date,'DD-MON-YYYY'),'w')= 5 then
    nvl(c.ordered_quantity,0)
              else null
              end as WEEK5
              from
              ra_customers           a,
              oe_order_headers_all          b,
              oe_order_lines_all           c,
              mtl_system_items_b          d,
              mtl_item_categories      e,
              mtl_categories           f
              where
              a.customer_id=b.sold_to_org_id and
              b.header_id=c.header_id
              and c.request_date between sysdate-7 and sysdate+7
              and c.inventory_item_id=d.inventory_item_id
              and d.inventory_item_id = e.inventory_item_id
              and e.category_id = f.category_id
              and d.organization_id=e.organization_id
              and e.category_set_id=1
              ) x
         group by x.customer_name,x.segment1,x.description,x.segment2;

    Hw will I join the tables that have no column in common?I need to retrieve a value from table 2 by refering the value in table 1Post some sample data and show us what you want.

  • How to Join 2 tables if datetime diff is within range?

    Hi, problem figuring out how to join tables if the datediff ? is within range.  
    There are 3 tables  a main table then 2 sub tables, these are measurements with a date/time value.  Im trying to take the datetime entries from the 2 sub tables and match them, then add  them to the main table
    subtable1 has SampleID, datetime, 
    subtable2 has TesterID, datetime
    maintable has SampleID, datetime, TesterID, datetime
    so the maintable would always have the sampleID value and datetime regardless.  but it would only JOIN the testerID and its datetime, only IF these 2 datetime values were close, and the datediff interval was set to 1 second.
     its a function call that fills the main tables matching columns but only if the testerIDs datetime is close to the sampleIDs time????
    thanks

    Please post DDL, so that people do not have to guess what the keys, constraints, Declarative Referential Integrity, data types, etc. in your schema are. Learn how to follow ISO-11179 data element naming conventions and formatting rules. Temporal data should
    use ISO-8601 formats. Code should be in Standard SQL as much as possible and not local dialect. 
    This is minimal polite behavior on SQL forums. Thanks for making us do your typing and DDL for you :( 
    >> There are 3 tables; a main table then 2 sub tables, <<
    Really? Main table? Sub-tables? There are no such terms in SQL. Trust me on that; I helped with the Standards :) We have referenced referencing tables in the DRI model of SQL. 
    >> these are measurements with a date/time value. << 
    ++Both of them, the measurementID and otherID  have a millisecond timestamp, the goal is to associate these 2 measurements, they are coming from different systems.  
    Do you really need the full timestamp down to nanoseconds and not just a DATE? Oh, we also have no sample data :( So we have to guess at precision, constraints, keys, etc. 
    See why we need DDL? Is this relationship 1:1, 1:M OR N:1? My guess is that a tester can do many samples, but a sample has only one tester. And what were those two timestamps? Not redundant copies from the referenced tables!! That would non-normalized. 
    >> so the Sample_Tester_Relationship would always have the sample_nbr value and <something>_timestamp regardless. But it would only JOIN the tester_id and its DATETIME, only IF these 2 DATETIME values were close, and the DATEDIFF interval was set
    to 1 second. <<
    No, you do not do a JOIN inside a base table. That is VIEW.
    >> It is a function [sic: procedure, Functions return scalar values] call that fills the main tables matching columns but only if the tester_id DATETIME is close to the sample_id time? <<
    No sample data, no sample code and no business rules about ties. Here is my final guess at normalizing this problem: 
    CREATE TABLE Samples
    (sample_nbr CHAR(12) NOT NULL PRIMARY KEY,
    CREATE TABLE Testers
    (tester_id CHAR(10) NOT NULL PRIMARY KEY,
    CREATE TABLE Sample_Tester_Relationship --- needs a real name!
    (sample_nbr CHAR(12) NOT NULL PRIMARY KEY
     REFERENCES Samples
      ON UPDATE CASCADE
      ON DELETE CASCADE,
     tester_id CHAR(10) NOT NULL
     REFERENCES Testers
      ON UPDATE CASCADE
      ON DELETE CASCADE,
     PRIMARY KEY (sample_nbr, tester_id),
     tester_timestamp DATETIME2(1) DEFAULT CURRENT_TIMESTAMP NOT NULL,
     sample_timestamp DATETIME2(1) DEFAULT CURRENT_TIMESTAMP NOT NULL,
     CHECK (ABS (DATEDIFF (SECOND, tester_timestamp, sample_timestamp) <= 1) );
    Most of the work in SQL is in DDL, not DML. 
    I will try this out and advise.
    --CELKO-- Books in Celko Series for Morgan-Kaufmann Publishing: Analytics and OLAP in SQL / Data and Databases: Concepts in Practice Data / Measurements and Standards in SQL SQL for Smarties / SQL Programming Style / SQL Puzzles and Answers / Thinking in
    Sets / Trees and Hierarchies in SQL
    Dear Celko
    thank you for this constructive feedback, clearly you're an expert and I am going to be better for following this advice.  In the 1970s I was told to avoid going into software because Japan had invented a way for computers to write their own code, so
    programmers would be out of a job and the field would be a dead-end.  I didnt formally begin training in sw until the 90s.  SQL is one of those last frontiers i never trained in.  but now Im trying to learn and find anything i can read to absorb
    it.
    I posted in laymans words because i thought thats how you experts would prefer it described, clearly not.  I will now take the time to read each reference to the standards...

  • How to join 3 tables.

    Hi ALL,
    I am using 3 tables ( VBAK VBRK VBRP)
    I want to link VBAK to VBRK .
                                             So I am Using VBRP as common table for both .
    Here I am choosing VBRP-AUBEL  Linking with VBAK-VBELN
                                           AND
                                  VBRP-VBELN  Linking with VBRK-VBELN.
    Now I want to know the syntax and steps to join these fields in 1 command.
    Thanks & Regards,
    R.Vinoth.

    hey,
    u have to select the itab_final in such a way that it must have all the fields , ie, vbeln,erdat,waerk,posnr.
    then you have started an IF statement, but haven't mentioned, where its getting ended.Even though, one can fill that, but try to finish the codes.
    bye now.
    report zvinutha message-id zyv.
    DATA:begin of st_vbak.
    include structure vbak.
    types:end of st_vbak.
    types: begin of st_vbrk.
    include structure vbrk.
    types: end of st_vbrk.
    types: begin of st_vbrp.
    include structure vbrp.
    types: end of st_vbrp.
    data:begin of itab_final occurs 0,
           vbeln like vbak-vbeln,
           erdat like vbak-erdat,
           posnr like vbrp-posnr,
          waerk like vbrk-waerk,
         end of itab_final.
    data:itab_vbak type table of st_vbak,
           itab_vbrk type table of st_vbrk,
           itab_vbrp type table of st_vbrp.
    select * from vbak into corresponding fields of table itab_vbak
    where vbeln = vbrk-vbeln.
    if not itab_vbak[] is initial.
    select * from vbrk into corresponding fields of table itab_vbrk
    where vbeln = vbak-vbeln.
    if not itab_vbrp[] is initial.
    select * from vbrp into corresponding fileds of table itab_vbrp
    where vbeln = vbrk-vbeln.
    loop at itab_vbak.
    itab_final-vbeln = itab_vbak-vbeln.
    itab_final-erdat = itab_vbak-erdat.
    append itab_vbak.
    endloop.
    loop at itab_final.
    read table itab_vbrk with key vbeln = itab_final-vbeln.
    if sy-subrc = 0.
    itab_final-waerk = itab_vbrk-warek.
    modify itab_final transporting waerk.
    endif.
    read table itab_vbrp with key vbeln = itab_final-vbeln.
    if sy-subrc = 0
    itab_final-POSNR = itab_vbrp-posnr.
    modify itab_final transporting posnr.
    endif.
    clear itab_final.
    endloop.
    loop at itab_final.
    write :/ itab_final.
    endloop.
    else.           "for if itab_vbrp[] is not initial.
    message e001 with 'no records found for itab_vbrp'.
    endif.
    else.          "for  if itab_vbrk[] is not initial.
    message e002 with ' no records found for itab_vbrk'.
    endif.
    I guess this is a completed code.
    bye now

  • How to join multiple tables !

    Give me the Example to join multiple tables 1

    Inner join
    IF p_bsart IS INITIAL.
    SELECT ekko~bukrs
    ekko~lifnr
    ekko~ebeln
    ekko~waers
    ekko~bsart
    ekko~ekorg
    ekko~ekgrp
    ekpo~ebelp
    ekpo~txz01
    ekpo~matnr
    ekpo~werks
    ekpo~menge
    ekpo~meins
    ekpo~netpr
    ekpo~netwr
    INTO TABLE t_itab1 FROM
    ekko INNER JOIN ekpo ON ekkoebeln = ekpoebeln
    WHERE ekko~ebeln IN s_ebeln AND
    ekko~bukrs IN s_bukrs AND
    ekko~lifnr IN s_lifnr AND
    ekko~ekorg IN s_ekorg AND
    ekko~ekgrp IN s_ekgrp AND
    ekpo~matnr IN s_matnr.
    The difference between an INNER JOIN and an OUTER JOIN is the following. If a query on an INNER JOIN of VBAK (outer table) and VBAP (inner table) finds a record in VBAK but no matching records in VBAP, then no data is retrieved from the database because the inner table is empty. If you still want to keep VBAK rows for which there are no matching VBAP rows, you need to use the OUTER JOIN construct available in ABAP/4 Open SQL in 4.x..
    Hi
    Syntax
    ... [(] {dbtab_left [AS tabalias_left]} | join
    {[INNER] JOIN}|{LEFT [OUTER] JOIN}
    {dbtab_right [AS tabalias_right] ON join_cond} [)] ... .
    Effect
    The join syntax represents a recursively nestable join expression. A join expression consists of a left-hand and a right- hand side, which are joined either by means of [INNER] JOIN or LEFT [OUTER] JOIN . Depending on the type of join, a join expression can be either an inner ( INNER) or an outer (LEFT OUTER) join. Every join expression can be enclosed in round brackets. If a join expression is used, the SELECT command circumvents SAP buffering.
    On the left-hand side, either a single database table, a view dbtab_left, or a join expression join can be specified. On the right-hand side, a single database table or a view dbtab_right as well as join conditions join_cond can be specified after ON. In this way, a maximum of 24 join expressions that join 25 database tables or views with each other can be specified after FROM.
    AS can be used to specify an alternative table name tabalias for each of the specified database table names or for every view. A database table or a view can occur multiple times within a join expression and, in this case, have various alternative names.
    The syntax of the join conditions join_cond is the same as that of the sql_cond conditions after the addition WHERE, with the following differences:
    At least one comparison must be specified after ON.
    Individual comparisons may be joined using AND only.
    All comparisons must contain a column in the database table or the view dbtab_right on the right-hand side as an operand.
    The following language elements may not be used: BETWEEN, LIKE, IN.
    No sub-queries may be used.
    For outer joins, only equality comparisons (=, EQ) are possible.
    If an outer join occurs after FROM, the join condition of every join expression must contain at least one comparison between columns on the left-hand and the right-hand side.
    In outer joins, all comparisons that contain columns as operands in the database table or the view dbtab_right on the right-hand side must be specified in the corresponding join condition. In the WHERE condition of the same SELECT command, these columns are not allowed as operands.
    Resulting set for inner join
    The inner join joins the columns of every selected line on the left- hand side with the columns of all lines on the right-hand side that jointly fulfil the join_cond condition. A line in the resulting set is created for every such line on the right-hand side. The content of the column on the left-hand side may be duplicated in this case. If none of the lines on the right-hand side fulfils the join_cond condition, no line is created in the resulting set.
    Resulting set for outer join
    The outer join basically creates the same resulting set as the inner join, with the difference that at least one line is created in the resulting set for every selected line on the left-hand side, even if no line on the right-hand side fulfils the join_cond condition. The columns on the right-hand side that do not fulfil the join_cond condition are filled with null values.
    Example
    Join the columns carrname, connid, fldate of the database tables scarr, spfli and sflight by means of two inner joins. A list is created of the flights from p_cityfr to p_cityto. Alternative names are used for every table.
    PARAMETERS: p_cityfr TYPE spfli-cityfrom,
    p_cityto TYPE spfli-cityto.
    DATA: BEGIN OF wa,
    fldate TYPE sflight-fldate,
    carrname TYPE scarr-carrname,
    connid TYPE spfli-connid,
    END OF wa.
    DATA itab LIKE SORTED TABLE OF wa
    WITH UNIQUE KEY fldate carrname connid.
    SELECT ccarrname pconnid f~fldate
    INTO CORRESPONDING FIELDS OF TABLE itab
    FROM ( ( scarr AS c
    INNER JOIN spfli AS p ON pcarrid = ccarrid
    AND p~cityfrom = p_cityfr
    AND p~cityto = p_cityto )
    INNER JOIN sflight AS f ON fcarrid = pcarrid
    AND fconnid = pconnid ).
    LOOP AT itab INTO wa.
    WRITE: / wa-fldate, wa-carrname, wa-connid.
    ENDLOOP.
    Example
    Join the columns carrid, carrname and connid of the database tables scarr and spfli using an outer join. The column connid is set to the null value for all flights that do not fly from p_cityfr. This null value is then converted to the appropriate initial value when it is transferred to the assigned data object. The LOOP returns all airlines that do not fly from p_cityfr.
    PARAMETERS p_cityfr TYPE spfli-cityfrom.
    DATA: BEGIN OF wa,
    carrid TYPE scarr-carrid,
    carrname TYPE scarr-carrname,
    connid TYPE spfli-connid,
    END OF wa,
    itab LIKE SORTED TABLE OF wa
    WITH NON-UNIQUE KEY carrid.
    SELECT scarrid scarrname p~connid
    INTO CORRESPONDING FIELDS OF TABLE itab
    FROM scarr AS s
    LEFT OUTER JOIN spfli AS p ON scarrid = pcarrid
    AND p~cityfrom = p_cityfr.
    LOOP AT itab INTO wa.
    IF wa-connid = '0000'.
    WRITE: / wa-carrid, wa-carrname.
    ENDIF.
    ENDLOOP.

  • How to join two tables using EJB-QL

    Hi There,
    How to join tables using EJB-QL ?
    Thanks.
    Edited by: vamseebobby on Nov 6, 2007 8:12 AM

    You might try
    SELECT b.entity2property FROM Entity1 a JOIN a.entity2 b
    for example, to retrieve players names, from a Players table, that belong to the team 'My Team' in the Teams table
    SELECT b.playerName FROM Teams a JOIN a.players b WHERE a.teamName = 'My Team'

  • How to join cluster table?

    How to join the cluster table with the transparent table?In specific ,can you pls tell me how can i join bkpf and bseg?

    Hi Aravind,
    Check this code,
    tables : bkpf,
             bseg.
       INTERNAL TABLE AND WORK AREA FOR THE FIELDS IN BKPF TABLE         *
    data : begin of itab_bkpf occurs 0,
           bukrs like bkpf-bukrs,            "Company Code.
           gjahr like bkpf-gjahr,            "Fiscal Year.
           budat like bkpf-budat,            "Posting Date in the Document.
           belnr like bkpf-belnr,            "Accounting document number.
           blart like bkpf-blart,            "Document Type.
           end of itab_bkpf.
    data : wa_bkpf like line of itab_bkpf.
       INTERNAL TABLE AND WORK AREA FOR THE FIEDLS IN BSEG TABLE         *
    data : begin of itab_bseg_debit occurs 0,
           bukrs like bseg-bukrs,            "Company Code.
           gjahr like bseg-gjahr,            "Fiscal Year.
           belnr like bseg-belnr,            "Accounting Document Number.
           buzei like bseg-buzei,            "Line Item.
           hkont like bseg-hkont,            "General Leadger Account.
           shkzg like bseg-shkzg,            "Credit/Debit Indicator.
           wrbtr like bseg-wrbtr,            "Amount in Document Currency.
           pswsl like bseg-pswsl,            "Update Currency for Gen.Ledger
           dmbtr like bseg-dmbtr,            "Amount in local currency.
           sgtxt like bseg-sgtxt,            "Item Text.
           zuonr like bseg-zuonr,            "Assignment Number.
           end of itab_bseg_debit.
    data : itab_bseg_credit like standard table of itab_bseg_debit with
           header line.
                      FINAL OUTPUT INTERNAL TABLE                        *
    data : begin of itab_output occurs 0,
           belnr(08)            ,
           bukrs(04)            ,
           budat like bkpf-budat,
           buzei(03)            ,
           hkont(07)            ,
           blart(02)            ,
           shkzg(01)            ,
           wrbtr(08)            ,
           pswsl(05)            ,
           dmbtr(10)            ,
           sgtxt(19)            ,
           zuonr(10)            ,
    end of itab_output.
    constants : c_debit  type c value 'S',
                c_credit type c value 'H'.
                               SELECT-OPTIONS                            *
    selection-screen begin of block input with frame title text-t01.
    select-options : s_bukrs for bkpf-bukrs.
    parameters     : p_year like bkpf-gjahr visible length 2.
    select-options : s_budat  for bkpf-budat,
                     s_dbacct for bseg-hkont,
                     s_cracct for bseg-hkont,
                     s_amt    for bseg-dmbtr.
    selection-screen end of block input.
         SELECTING RECORDS FROM BKPF TABLE BASED ON THE CONDITION        *
    select bukrs gjahr budat belnr blart
           from  bkpf into table itab_bkpf
           where bukrs in s_bukrs and
                 gjahr eq p_year  and
                 budat in s_budat.
        SELECTING DEBIT LINE ITEMITEMS FROM BSEG FOR THE DOCUMENT        *
                      NUMBER SELECTED FROM BKPF                          *
    if not itab_bkpf[] is initial.
      select bukrs gjahr belnr buzei
             hkont shkzg wrbtr pswsl
             dmbtr sgtxt zuonr
             from bseg into table itab_bseg_debit
             for all entries in itab_bkpf
             where bukrs eq itab_bkpf-bukrs and
                   belnr eq itab_bkpf-belnr and
                   gjahr eq itab_bkpf-gjahr and
                   hkont in s_dbacct        and
                   shkzg eq c_debit         and
                   dmbtr in s_amt.
        SELECTING CREDIT LINE ITEMITEMS FROM BSEG FOR THE DOCUMENT       *
                      NUMBER SELECTED FROM BKPF                          *
      select bukrs gjahr belnr buzei
             hkont shkzg wrbtr pswsl
             dmbtr sgtxt zuonr
             from bseg into table itab_bseg_credit
             for all entries in itab_bkpf
             where bukrs eq itab_bkpf-bukrs and
                   belnr eq itab_bkpf-belnr and
                   gjahr eq itab_bkpf-gjahr and
                   hkont in s_cracct        and
                   shkzg eq c_credit        and
                   dmbtr in s_amt.
    endif.
    sort itab_bkpf        by bukrs gjahr belnr.
    sort itab_bseg_credit by bukrs gjahr belnr.
                         LOOPING THE DEBIT ENTRIES                       *
    loop at itab_bseg_debit.
    READING THE CREDIT ENTRIES WHICH MATCHES WITH HE CURRENT DOC. NUMBER *
      read table itab_bseg_credit with key
                 bukrs = itab_bseg_debit-bukrs
                 gjahr = itab_bseg_debit-gjahr
                 belnr = itab_bseg_debit-belnr binary search.
      if sy-subrc eq 0.
    *READING THE POSTING DATE AND DOCUMENT TYPE FOR THE CURRENT DOUCMENT   *
           AND APPENDING THE DEBIT AND CREDIT ENTRIES                    *
        read table itab_bkpf into wa_bkpf with key
                   bukrs = itab_bseg_debit-bukrs
                   gjahr = itab_bseg_debit-gjahr
                   belnr = itab_bseg_debit-belnr binary search.
        itab_output-belnr = itab_bseg_debit-belnr.
        itab_output-bukrs = itab_bseg_debit-bukrs.
        itab_output-budat = wa_bkpf-budat.
        itab_output-buzei = itab_bseg_debit-buzei.
        itab_output-hkont = itab_bseg_debit-hkont.
        itab_output-blart = wa_bkpf-blart.
        itab_output-shkzg = itab_bseg_debit-shkzg.
        itab_output-wrbtr = itab_bseg_debit-wrbtr.
        itab_output-pswsl = itab_bseg_debit-pswsl.
        itab_output-dmbtr = itab_bseg_debit-dmbtr.
        itab_output-sgtxt = itab_bseg_debit-sgtxt.
        itab_output-zuonr = itab_bseg_debit-zuonr.
        append itab_output.
        itab_output-belnr = itab_bseg_credit-belnr.
        itab_output-bukrs = itab_bseg_credit-bukrs.
        itab_output-budat = wa_bkpf-budat.
        itab_output-buzei = itab_bseg_credit-buzei.
        itab_output-hkont = itab_bseg_credit-hkont.
        itab_output-blart = wa_bkpf-blart.
        itab_output-shkzg = itab_bseg_credit-shkzg.
        itab_output-wrbtr = itab_bseg_credit-wrbtr.
        itab_output-pswsl = itab_bseg_credit-pswsl.
        itab_output-dmbtr = itab_bseg_credit-dmbtr.
        itab_output-sgtxt = itab_bseg_credit-sgtxt.
        itab_output-zuonr = itab_bseg_credit-zuonr.
        append itab_output.
      endif.
    endloop.
    sort itab_output by belnr budat shkzg.
                     LOOPING OUTPUT INTERNAL TABLE                       *
    *FORMAT INTENSIFIED INPUT.
    *FORMAT INVERSE ON.
    loop at itab_output.
      format hotspot on.
      format color 5 inverse.
      write :/  sy-vline,
               000 itab_output-belnr, 12  sy-vline,
               013 itab_output-bukrs, 17  sy-vline,
               019 itab_output-budat,     sy-vline,
               034 itab_output-buzei, 40  sy-vline,
               042 itab_output-hkont,     sy-vline,
               054 itab_output-blart, 60  sy-vline,
               065 itab_output-shkzg, 70  sy-vline,
               072 itab_output-wrbtr,     sy-vline,
               085 itab_output-pswsl,     sy-vline,
               093 itab_output-dmbtr,     sy-vline,
               106 itab_output-sgtxt,     sy-vline,
                   itab_output-zuonr,     sy-vline.
      format hotspot off.
    endloop.
    uline 0(139).
    <b>Regards,
    Jackie.</b>

  • How to join three tables?

    I have used this query to join three tables but it displays an error : field vbak-vbeln is unknown.
    please help me out..
    SELECT vbak-vbeln vbak-bstnk vbap-matnr vbap-zmeng makt-maktx
    INTO CORRESPONDING FIELDs OF TABLE itab FROM vbak
    inner JOIN vbap ON vbak-vbeln eq vbap-vbeln
    inner JOIN makt ON vbap-matnr eq makt-matnr
    WHERE vbak-bstnk = s_bstnk.

    Hi mohan kumar ,
    just follow the Syntax
    SELECT FLD1 FLD2 FLD3 FLD4 FLD5 INTO CORRESPONDING FIELDS OF TABLE ITAB FROM TABLE1 INNER JOIN TABLE2 ON
    TABLE1FLD1 = TABLE2FLD1 INNER JOIN TABLE3 ON TABLE2FLD2 = TABLE3FLD2 INNER JOIN TABL4 ON  TABLE3FLD3 = TABLE4FLD3
    WHERE FLD1 = 'AA'
    Hope this may be helpful.
    Please reward points if found ok.
    Thanks and regards,
    Rajeshwar.

  • How to join 2 tables with unequal rows without resulting in a cartesian join

    Hello,
    This is the first time I have ever posted in any forum so please tell me if I should be doing this better.
    Basically I have 2 tables with an unequal number of rows. For demonstration purposes, assume these are my 2 tables:
    Table 1:
    BaseKey
    Letters
    A
    A
    A
    B
    A
    C
    B
    A
    B
    B
    Table 2:
    BaseKey
    Numbers
    A
    1
    A
    2
    B
    1
    B
    2
    B
    3
    I need to join them so that the data would appear like this
    BaseKey
    Letters
    Numbers
    A
    A
    1
    A
    B
    2
    A
    C
    null
    B
    A
    1
    B
    B
    2
    B
    null
    3
    Does anyone have any ideas how to do this using T-SQL without creating a cartesian join of 12 rows?
    Thanks.

    >> This is the first time I have ever posted in any forum so please tell me if I should be doing this better. <<
    Please post DDL, so that people do not have to guess what the keys, constraints, Declarative Referential Integrity, data types, etc. in your schema are. Learn to follow ISO-11179 data element naming conventions and formatting rules. Temporal data should
    use ISO-8601 formats. Code should be in Standard SQL as much as possible and not local dialect.
    This is minimal polite behavior on SQL forums. What you did post is useless! Can you program from it? Neither can we. And we have to do all the extra typing for you.
    CREATE TABLE Foo
    (base_something  CHAR(1) NOT NULL,
     something_letter CHAR(1) NOT NULL,
     PRIMARY KEY (base_something, something_letter));
    INSERT INTO Foo
    VALUES ('A', 'A'),
    ('A', 'B'),
    ('A', 'C'),
    ('B', 'A'),
    ('B', 'B');
    CREATE TABLE Bar
    (CHAR(1) NOT NULL,
     something_digit CHAR(1) NOT NULL,
     PRIMARY KEY (base_something, something_digit));
    INSERT INTO Foo
    VALUES ('A', '1'),
    ('A', '2'),
    ('B', '1'),
    ('B', '2'),
    ('B', '3');
    >> I need to join them so that the data would appear like this
    base_something Letters Numbers <<
    This looks like you are taking two decks of punch cards and merging them together, without any logical rules, just physical position in their decks relative to the base_something groups.
    WITH Foo_Deck
    AS
    (SELECT base_something, something_letter,
           ROW_NUMBER()
            OVER (PARTITION BY base_something
                   ORDER BY something_letter) AS card),
    Bar_Deck
    AS
    (SELECT base_something, something_digit,
           ROW_NUMBER()
            OVER (PARTITION BY base_something
                   ORDER BY something_digit) AS card),
    SELECT F.base_something, F.something_digit, B.something_letter
      FROM Foo_Deck AS F
           LEFT OUTER JOIN
           Bar_Deck AS B
           ON B.base_something = F.base_something
              AND B.card = F.card;
    --CELKO-- Books in Celko Series for Morgan-Kaufmann Publishing: Analytics and OLAP in SQL / Data and Databases: Concepts in Practice Data / Measurements and Standards in SQL SQL for Smarties / SQL Programming Style / SQL Puzzles and Answers / Thinking
    in Sets / Trees and Hierarchies in SQL

  • How to join these two queries

    Hi experts,
    I need to join two queries but not sure how:
    select id from test_table1;
    select *
      from table(f_function(null
                           ,null
                           ,1 -- the id
                           ,sysdate);One query has IDs needed to run the second query. Is there a way to join those two?
    The result should be all columns from test_table1 + all columns from f_function.
    Best regards,
    Igor
    Edited by: Igor S. on Mar 8, 2013 5:18 AM

    Hi,
    Igor S. wrote:
    select  *
    from  test_table1,
    table(
    f_function(
    null,
    null,
    id,
    sysdate
    select  *
    from  test_table1,
    table(
    f_function(
    null,
    null,
    id,
    sysdate
    ) xyz
    where test_table1.id = xyz.id
    /So these two queries are the same?Try it and see.
    You'll find that the 2nd one produces an error. But if you change it to
    select  *
      from  test_table1,
            table(
                  f_function(
                             null,
                             null,
                             id,
                             sysdate
                            )      -- No alias here
                 ) xyz             -- Alias here, instead
    where test_table1.id = xyz.id
    /Then, assuming f_function produces a column called id, it will work.
    Whether it produces the same results or not depends on what the function returns, and whether either id is NULL.
    If the id column that the function returns is the same as the id value that you pass to it, and is never NULL, then the 2 queries will produce the same results.
    Either way, each row of test_table1 will be joined to each row that the function produces with the argument(s) from that row. The column names produced by the function and the values in those columns are determined by the function; they do not need to have anything in common with any table. In practice, a function like f_function will usually not return an column that is always identical to any of its inputs, since that value is already available from the input.

  • How to join two tables in a cursor

    i have a cursor that selects data from one table,
    i want it to select data from one other table also.. how i can do that.. is there any alternate way to do that if yes then suggest .. waiting for ur reply....

    employee_number" and other has column name as "comp_employee_number" .. Well that would be quite simple ....
    SELECT e1.foo, e2.bar 
    FROM   employees e1, staff_members e2
    WHERE e1.employee_number = e2.comp_employee_number;.... unless what you're really expecting is for the datbase to somehow figure out by itself that although those columns have different names they actually represent the same data and magically derive the join for you.
    Perhaps, you really need to explain in more detail precisely what your problem is.
    Cheers, APC

  • How to join three tables and practical difference between 10g and 11g

    I want to know with example how to outer join three different tables in Oracle.
    Also if you have any website or reference for understand syntax or performance difference between 10g and 11g then please paste a link in.thanks!!

    Hi,
    897293 wrote:
    I want to know with example how to outer join three different tables in Oracle.The 3rd table comes into the result set the same way the 2nd one did:
    FROM           table_1  t1
    LEFT OUTER JOIN      table_2  t2  ON   ...
    LEFT OUTER JOIN      table_3  t3  ON   ...The join condition(s) for t3 can reference t1, or t2, or both.
    Also if you have any website or reference for understand syntax or performance difference between 10g and 11g then please paste a link in.thanks!!The main manuals all have "What's New" sections near the beginning. For example:
    http://download.oracle.com/docs/cd/B28359_01/server.111/b28286/wnsql.htm#sthref5
    Hoek,
    We've missed you. Welcome back!

Maybe you are looking for