Inner join command

Hi Forum,
How to use Inner join command?
Please explain with an example.
Thanks,
Mahathi

Inner Join and Outer Join
The data that can be selected with a view depends primarily on whether the view implements an inner join or an outer join. With an inner join, you only get the records of the cross-product for which there is an entry in all tables used in the view. With an outer join, records are also selected for which there is no entry in some of the tables used in the view.
The set of hits determined by an inner join can therefore be a subset of the hits determined with an outer join.
Database views implement an inner join. The database therefore only provides those records for which there is an entry in all the tables used in the view. Help views and maintenance views, however, implement an outer join.
Specifying Database Tables
The FROM clause determines the database tables from which the data specified in the SELECT clause is read. You can specify either a single table or more than one table, linked using inner or outer joins. The names of database tables may be specified statically or dynamically, and you can use alias names. You can also use the FROM clause to bypass the SAP buffer and restrict the number of lines to be read from the database.
"Database table" can equally mean an ABAP Dictionary view. A view links two or more database tables in the ABAP Dictionary, providing a static join that is available systemwide. You can specify the name of a view wherever the name of a database table may occur in the FROM clause.
The FROM clause has two parts - one for specifying database tables, and one for other additions:
SELECT... FROM <tables> <options>...
In <tables>, you specify the names of database tables and define joins. <options> allows you to specify further additions that control the database access.
Specifying Database Tables Statically
To specify the name of a database table statically, use the following:
SELECT... FROM <dbtab> [AS <alias>] <options> . ..
The database table <dbtab> must exist in the ABAP Dictionary. The AS addition allows you to specify an alternative name <alias> that you can then use in the SELECT; FROM, WHERE, and GROUP BY clauses. This can eliminate ambiguity when you use more than one database table, especially when you use a single database table more than once in a join. Once you have defined an alias, you may no longer use the real name of the database table
Specifying Database Tables Dynamically
To specify the name of a database table dynamically, use the following:
SELECT... FROM (<name>) <options> . ..
The field <name> must contain the name of a database table in the ABAP Dictionary. The table name must be written in uppercase. When you specify the name of a database table dynamically, you cannot use an empty INTO clause to read all of the columns into the work area <dbtab>. It is also not possible to use alternative table names.
Specifying Two or More Database Tables as an Inner Join
In a relational database, you normally need to read data simultaneously from more than one database table into an application program. You can read from more than one table in a single SELECT statement, such that the data in the tables all has to meet the same conditions, using the following join expression:
SELECT...
  FROM <tab> [INNER] JOIN <dbtab> [AS <alias>] ON <cond> <options>
where <dbtab> is a single database table and <tab> is either a table or another join expression. The database tables can be specified statically or dynamically as described above. You may also use aliases. You can enclose each join expression in parentheses. The INNER addition is optional.
A join expression links each line of <tab> with the lines in <dbtab> that meet the condition <cond>. This means that there is always one or more lines from the right-hand table that is linked to each line from the left-hand table by the join. If <dbtab> does not contain any lines that meet the condition <cond>, the line from <tab> is not included in the selection.
The syntax of the <cond> condition is like that of the WHERE clause, although individual comparisons can only be linked using AND. Furthermore, each comparison must contain a column from the right-hand table <dbtab>. It does not matter on which side of the comparison it occurs. For the column names in the comparison, you can use the same names that occur in the SELECT clause, to differentiate columns from different database tables that have the same names.
The comparisons in the condition <cond> can appear in the WHERE clause instead of the ON clause, since both clauses are applied equally to the temporary table containing all of the lines resulting from the join. However, each join must contain at least one comparison in the condition <cond>.
Specifying Two or More Database Tables as a Left Outer Join
In an inner join, a line from the left-hand database table or join is only included in the selection if there is one or more lines in the right-hand database table that meet the ON condition <cond>. The left outer join, on the other hand, reads lines from the left-hand database table or join even if there is no corresponding line in the right-hand table.
SELECT...
  FROM <tab> LEFT [OUTER] JOIN <dbtab> [AS <alias>] ON <cond>
       <options>
<tab> and <dbtab> are subject to the same rules and conditions as in an inner join. The OUTER addition is optional. The tables are linked in the same way as the inner join with the one exception that all lines selected from <tab> are included in the final selection. If <dbtab> does not contain any lines that meet the condition <cond>, the system includes a single line in the selection whose columns from <dbtab> are filled with null values.
In the left outer join, more restrictions apply to the condition <cond> than in the inner join. In addition to the above restrictions:
EQ or = is the only permitted relational operator.
There must be at least one comparison between columns from <tab> and <dbtab>.
The WHERE clause may not contain any comparisons with columns from <dbtab>. All comparisons using columns from <dbtab> must appear in the condition <cond>.
Client Handling
As already mentioned, you can switch off the automatic client handling in Open SQL statements using a special addition. In the SELECT statement, the addition comes after the options in the FROM clause:
SELECT... FROM <tables> CLIENT SPECIFIED. ..
If you use this addition, you can then address the client fields in the individual clauses of the SELECT statement.
Disabling Data Buffering
If buffering is allowed for a table in the ABAP Dictionary, the SELECT statement always reads the data from the buffer in the database interface of the current application server. To read data directly from the database table instead of from the buffer, use the following:
SELECT... FROM <tables> BYPASSING BUFFER. ..
This addition guarantees that the data you read is the most up to date. However, as a rule, only data that does not change frequently should be buffered, and using the buffer where appropriate improves performance. You should therefore only use this option where really necessary.
Restricting the Number of Lines
To restrict the absolute number of lines included in the selection, use the following:
SELECT... FROM <tables> UP TO <n> ROWS. ..
If <n> is a positive integer, the system reads a maximum of <n> lines. If <n> is zero, the system reads all lines that meet the selection criteria. If you use the ORDER BY clause as well, the system reads all lines belonging to the selection, sorts them, and then places the first <n> lines in the selection set.
Examples
Specifying a database table statically:
REPORT demo_select_static_database.
DATA wa TYPE scarr.
SELECT *
  INTO wa
  FROM scarr UP TO 4 ROWS.
  WRITE: / wa-carrid, wa-carrname.
ENDSELECT.
The output is:
The system reads four lines from the database table SCARR.
Specifying a database table dynamically:
REPORT demo_select_dynamic_database.
DATA wa TYPE scarr.
DATA name(10) TYPE c VALUE 'SCARR'.
SELECT  *
  INTO  wa
  FROM  (name) CLIENT SPECIFIED
  WHERE mandt = '000'.
  WRITE: / wa-carrid, wa-carrname.
ENDSELECT.
A condition for the MANDT field is allowed, since the example uses the CLIENT SPECIFIED option. If NAME had contained the value ‘scarr’ instead of ‘SCARR’, a runtime error would have occurred.
Inner join:
REPORT demo_select_inner_join.
DATA: BEGIN OF wa,
        carrid TYPE spfli-carrid,
        connid TYPE spfli-connid,
        fldate TYPE sflight-fldate,
        bookid TYPE sbook-bookid,
      END OF wa,
      itab LIKE SORTED TABLE OF wa
                WITH UNIQUE KEY carrid connid fldate bookid.
SELECT  pcarrid pconnid ffldate bbookid
  INTO  CORRESPONDING FIELDS OF TABLE itab
  FROM  ( ( spfli AS p
            INNER JOIN sflight AS f ON pcarrid = fcarrid AND
                                       pconnid = fconnid    )
            INNER JOIN sbook   AS b ON bcarrid = fcarrid AND
                                       bconnid = fconnid AND
                                       bfldate = ffldate     )
  WHERE p~cityfrom = 'FRANKFURT' AND
        p~cityto   = 'NEW YORK'  AND
        fseatsmax > fseatsocc.
LOOP AT itab INTO wa.
  AT NEW fldate.
    WRITE: / wa-carrid, wa-connid, wa-fldate.
ENDAT.
  WRITE / wa-bookid.
ENDLOOP.
This example links the columns CARRID, CONNID, FLDATE, and BOOKID of the table SPFLI, SFLIGHT, and SBOOK, and creates a list of booking numbers for all flights from Frankfurt to New York that are not fully booked. An alias name is assigned to each table.
Left outer join:
REPORT demo_select_left_outer_join.
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 = 'FRANKFURT'.
LOOP AT itab INTO wa.
  WRITE: / wa-carrid, wa-carrname, wa-connid.
ENDLOOP.
The output might look like this:
The example links the columns CARRID, CARRNAME, and CONNID of the tables SCARR and SPFLI using the condition in the left outer join that the airline must fly from Frankfurt. All other airlines have a null value in the CONNID column in the selection.
If the left outer join is replaced with an inner join, the list looks like this:
Only lines that fulfill the ON condition are included in the selection.

Similar Messages

  • Inner join command is not supporting pooled table

    Hi Forum,
    I'm new to abap. I tried passing fields of two tables into a single table using inner join command. But one of the tables is a pooled table so the command "inner join" is not supporting that. How to pass the fields in those two tables into a single table? Kindly help me out.
    Rgrds,
    Mahathi

    Hi ....
    U can't perform JOIN with Pooled or Cluster tables
    trying to join A018 and KONP .... here A018 is Pooled table... Look at below threads...
    Re: abap query join A018/KONP
    Can't perform join table
    Hope it will solve your problem..
    <b>Reward points if useful.</b>
    Thanks & Regards
    ilesh 24x7

  • MS Access Update Inner Join command conversion

    I have code in a Microsoft Access Database View, that I'm trying to convert to Oracle. I tried using Oracle SQL Developer's Migration tool and it basically skipped this command.
    Update Table1 INNER JOIN Table2 On Table1.COL1 = Table2.COL2 SET Table1.COL3 = 1;
    I've tried a number of things including selecting all the rows with something like
    select * from Table1 o inner join Table2 t on o.COL1 = t.COL2
    and then trying to somehow hook it to an update command where the command gets the above results and does a Table1.COL3 = 1 on all of those rows.
    However I can't get the syntax correct.
    Can someone please help?
    Thanks,
    Jeff
    BTW: The code is in a MS Access view but probably belongs in a stored procedure. It also uses a Access-only Boolean instead of 1, which may be part of the reason the command conversion failed.

    maybe this?
    Update Table1
       set Table1.COL3 = 1
    Where Table1.col1 in (select table2.col2 from table2);
    or
    Update Table1
       set Table1.COL3 = 1
    Where exists (select 'x'
                     from table2
                    where table2.col2 = table1.col1);note: untested.

  • Documentation on "Inner Join"

    We are in the process of migrating to Oracle 9.2 and I was reading about some of the new features. In one of the code examples there was a query written using the "inner join" command, something that I was not familiar with but that was not presented as a new feature. I've since tried using this and there appears to be significant performance gains in its use but I am unable to find any documentation relating to it. One of the developers here said that MS Access often uses this syntax so is it included for compatibility or is it something I should be looking to use more often?
    Can someone provide me with the link to the relevant documentation for this feature or explain its use more fully i.e. can it deal with complex joins?
    Thanks
    Richard

    There isn't much documentation that I've found on the ANSI joins. Here is one in the SQL reference:
    http://download-west.oracle.com/docs/cd/B10501_01/server.920/a96540/statements_103a.htm#2080352
    One advantage to using the ANSI joins is greater flexibility with outer joins. Another advantage is explicit documentation of cartesian products with the CROSS JOIN keyword (no reson to wonder why someone just left out the join). Finally, the ANSI join syntax allows one to remove join-code from the WHERE clause making the WHERE clause much easier to read (it only has conditions).
    As far as performance goes, I haven't noticed any change (good or bad) whilist switching over to ANSI joins...
    Stan

  • Urgent help please.  Inner Join caused ora-00933 error

    I ran this one , works fine:
    SELECT DISTINCT EXP.EXP_ID,
    EXP.DATU_EXP_WIRE_CENTER_CLLI,
    EXP.DATU_EXP_IP,
    EXP.DATU_EXP_CLLI,
    EXP.DATU_EXP_PORT,
    EXP.DATU_EXP_NAME,
    EXP.DATU_EXP_CITY,
    EXP.DATU_EXP_STATE,
    EXP.DATU_EXP_SW_VERSION,
    DECODE(LAST_ALARM.LAST_ALARM_DATE, NULL, TO_CHAR(SYSDATE,'YYYY/MM/DD HH24:MI:SS'),
         TO_CHAR(LAST_ALARM.LAST_ALARM_DATE,'YYYY/MM/DD HH24:MI:SS')) AS STATUS_DATE,
    DECODE(LAST_ALARM.ALARM_NAME, NULL, 'Disconnected', LAST_ALARM.ALARM_NAME) AS DATU_STATUS,
    DECODE(LAST_ALARM.ALARM_CLASS, NULL, 'OTHER', LAST_ALARM.ALARM_CLASS) AS IS_ERROR_STATUS,
         DECODE(LAST_RESOURCE.LAST_ALARM_DATE, NULL, '', TO_CHAR(LAST_RESOURCE.LAST_ALARM_DATE,'YYYY/MM/DD HH24:MI:SS')) AS RESOURCE_STATUS_DATE,
         DECODE(LAST_RESOURCE.RESOURCE_CODE_NAME, NULL, '', LAST_RESOURCE.RESOURCE_CODE_NAME) AS RESOURCE_STATUS,
         DECODE(LAST_RESOURCE.RESOURCE_CODE_CLASS, NULL, '', LAST_RESOURCE.RESOURCE_CODE_CLASS) AS IS_RESOURCE_ERROR_STATUS,
         DECODE(LAST_OPER.LAST_ALARM_DATE, NULL, '', TO_CHAR(LAST_OPER.LAST_ALARM_DATE,'YYYY/MM/DD HH24:MI:SS')) AS OPER_STATUS_DATE,
         DECODE(LAST_OPER.OPER_CODE_NAME, NULL, '', LAST_OPER.OPER_CODE_NAME) AS OPER_STATUS,
         DECODE(LAST_OPER.OPER_CODE_CLASS, NULL, '', LAST_OPER.OPER_CODE_CLASS) AS IS_OPER_ERROR_STATUS,
    EXP.BEGIN_MAINT_WINDOW, RTU.RTU_NAME
    FROM TT_DATU_EXP_UNIT_INFO EXP
         left outer join
    ( SELECT distinct alarmed_datus.EXP_ID, c.ALARM_NAME, c.ALARM_TYPE, c.ALARM_CLASS, alarmed_datus.LAST_ALARM_DATE
    FROM ( SELECT EXP_ID, MAX(ALARM_TIME) AS LAST_ALARM_DATE FROM TT_DATU_EXP_ALARM_INFO GROUP BY EXP_ID ) alarmed_datus
    inner join TT_DATU_EXP_ALARM_INFO b on b.EXP_ID = alarmed_datus.EXP_ID AND b.ALARM_TIME = alarmed_datus.LAST_ALARM_DATE
    inner join TT_DATU_EXP_ALARM_TYPES c on b.ALARM_TYPE = c.ALARM_TYPE
    ) LAST_ALARM on EXP.EXP_ID = LAST_ALARM.EXP_ID
         left outer join
         ( SELECT distinct a.EXP_ID, c.RESOURCE_CODE_NAME, c.RESOURCE_CODE_TYPE, c.RESOURCE_CODE_CLASS, a.LAST_ALARM_DATE
         FROM ( SELECT EXP_ID, MAX(RESOURCE_CODE_TIME) AS LAST_ALARM_DATE
         FROM TT_DATU_EXP_RESOURCE_CODE_INFO GROUP BY EXP_ID ) a
    inner join TT_DATU_EXP_RESOURCE_CODE_INFO b on b.EXP_ID = a.EXP_ID AND b.RESOURCE_CODE_TIME = a.LAST_ALARM_DATE
    inner join TT_DATU_EXP_RESOURCECODE_TYPES c on b.RESOURCE_CODE_TYPE = c.RESOURCE_CODE_TYPE
         ) LAST_RESOURCE on EXP.EXP_ID = LAST_RESOURCE.EXP_ID
         left outer join
         ( SELECT distinct a.EXP_ID, c.OPER_CODE_NAME, c.OPER_CODE_TYPE, c.OPER_CODE_CLASS, a.LAST_ALARM_DATE
         FROM ( SELECT EXP_ID, MAX(OPER_CODE_TIME) AS LAST_ALARM_DATE
         FROM TT_DATU_EXP_OPER_CODE_INFO GROUP BY EXP_ID ) a
    inner join TT_DATU_EXP_OPER_CODE_INFO b on b.EXP_ID = a.EXP_ID AND b.OPER_CODE_TIME = a.LAST_ALARM_DATE
    inner join TT_DATU_EXP_OPER_CODE_TYPES c on b.OPER_CODE_TYPE = c.OPER_CODE_TYPE) LAST_OPER on EXP.EXP_ID = LAST_OPER.EXP_ID
    inner join TT_DATU_LRN_MAP LRNS on EXP.EXP_ID = LRNS.EXP_ID AND TRIM(LRNS.LRN) LIKE p_LRN
    inner join TT_RTU_TYPES RTU ON EXP.RTU_TYPE_ID = RTU.RTU_TYPE_ID
    WHERE NOT EXISTS (SELECT SATELLITE_EXP_ID FROM TT_HOST_SATELLITE WHERE EXP.EXP_ID = SATELLITE_EXP_ID)
    AND EXP.IS_PRIMARY_ADDRESS LIKE p_isPrimary;
         ELSE
         OPEN v_cursor FOR
    SELECT EXP.EXP_ID,
    EXP.DATU_EXP_WIRE_CENTER_CLLI,
    EXP.DATU_EXP_IP,
    EXP.DATU_EXP_CLLI,
    EXP.DATU_EXP_PORT,
    EXP.DATU_EXP_NAME,
    EXP.DATU_EXP_CITY,
    EXP.DATU_EXP_STATE,
    EXP.DATU_EXP_SW_VERSION,
    DECODE(LAST_ALARM.LAST_ALARM_DATE, NULL, TO_CHAR(SYSDATE,'YYYY/MM/DD HH24:MI:SS'), TO_CHAR(LAST_ALARM.LAST_ALARM_DATE,'YYYY/MM/DD HH24:MI:SS')) AS STATUS_DATE,
    DECODE(LAST_ALARM.ALARM_NAME, NULL, 'Disconnected', LAST_ALARM.ALARM_NAME) AS DATU_STATUS,
    DECODE(LAST_ALARM.ALARM_CLASS, NULL, 'OTHER', LAST_ALARM.ALARM_CLASS) AS IS_ERROR_STATUS,
         DECODE(LAST_RESOURCE.LAST_ALARM_DATE, NULL, '', TO_CHAR(LAST_RESOURCE.LAST_ALARM_DATE,'YYYY/MM/DD HH24:MI:SS')) AS RESOURCE_STATUS_DATE,
         DECODE(LAST_RESOURCE.RESOURCE_CODE_NAME, NULL, '', LAST_RESOURCE.RESOURCE_CODE_NAME) AS RESOURCE_STATUS,
         DECODE(LAST_RESOURCE.RESOURCE_CODE_CLASS, NULL, '', LAST_RESOURCE.RESOURCE_CODE_CLASS) AS IS_RESOURCE_ERROR_STATUS,
         DECODE(LAST_OPER.LAST_ALARM_DATE, NULL, '', TO_CHAR(LAST_OPER.LAST_ALARM_DATE,'YYYY/MM/DD HH24:MI:SS')) AS OPER_STATUS_DATE,
         DECODE(LAST_OPER.OPER_CODE_NAME, NULL, '', LAST_OPER.OPER_CODE_NAME) AS OPER_STATUS,
         DECODE(LAST_OPER.OPER_CODE_CLASS, NULL, '', LAST_OPER.OPER_CODE_CLASS) AS IS_OPER_ERROR_STATUS,
    EXP.BEGIN_MAINT_WINDOW, RTU.RTU_NAME
    FROM TT_DATU_EXP_UNIT_INFO EXP
         left outer join (
    SELECT distinct alarmed_datus.EXP_ID, c.ALARM_NAME, c.ALARM_TYPE, c.ALARM_CLASS, alarmed_datus.LAST_ALARM_DATE
    FROM (SELECT EXP_ID, MAX(ALARM_TIME) AS LAST_ALARM_DATE FROM TT_DATU_EXP_ALARM_INFO GROUP BY EXP_ID ) alarmed_datus
         inner join TT_DATU_EXP_ALARM_INFO b on b.EXP_ID = alarmed_datus.EXP_ID AND b.ALARM_TIME = alarmed_datus.LAST_ALARM_DATE
         inner join TT_DATU_EXP_ALARM_TYPES c on b.ALARM_TYPE = c.ALARM_TYPE )
         LAST_ALARM on EXP.EXP_ID = LAST_ALARM.EXP_ID
         left outer join
              ( SELECT distinct a.EXP_ID, c.RESOURCE_CODE_NAME, c.RESOURCE_CODE_TYPE, c.RESOURCE_CODE_CLASS, a.LAST_ALARM_DATE
              FROM ( SELECT EXP_ID, MAX(RESOURCE_CODE_TIME) AS LAST_ALARM_DATE
              FROM TT_DATU_EXP_RESOURCE_CODE_INFO GROUP BY EXP_ID ) a
         inner join TT_DATU_EXP_RESOURCE_CODE_INFO b on b.EXP_ID = a.EXP_ID AND b.RESOURCE_CODE_TIME = a.LAST_ALARM_DATE
         inner join TT_DATU_EXP_RESOURCECODE_TYPES c on b.RESOURCE_CODE_TYPE = c.RESOURCE_CODE_TYPE) LAST_RESOURCE on EXP.EXP_ID = LAST_RESOURCE.EXP_ID
         left outer join
              ( SELECT distinct a.EXP_ID, c.OPER_CODE_NAME, c.OPER_CODE_TYPE, c.OPER_CODE_CLASS, a.LAST_ALARM_DATE
              FROM ( SELECT EXP_ID, MAX(OPER_CODE_TIME) AS LAST_ALARM_DATE
              FROM TT_DATU_EXP_OPER_CODE_INFO GROUP BY EXP_ID ) a
         inner join TT_DATU_EXP_OPER_CODE_INFO b on b.EXP_ID = a.EXP_ID AND b.OPER_CODE_TIME = a.LAST_ALARM_DATE
         inner join TT_DATU_EXP_OPER_CODE_TYPES c on b.OPER_CODE_TYPE = c.OPER_CODE_TYPE
              ) LAST_OPER on EXP.EXP_ID = LAST_OPER.EXP_ID ORDER BY EXP.DATU_EXP_CLLI
         inner join TT_RTU_TYPES RTU ON EXP.RTU_TYPE_ID = RTU.RTU_TYPE_ID
    WHERE NOT EXISTS (SELECT SATELLITE_EXP_ID FROM TT_HOST_SATELLITE WHERE EXP.EXP_ID = SATELLITE_EXP_ID) AND EXP.IS_PRIMARY_ADDRESS like
    p_isPrimary;
    However this one:
    SELECT EXP.EXP_ID,
    EXP.DATU_EXP_WIRE_CENTER_CLLI,
    EXP.DATU_EXP_IP,
    EXP.DATU_EXP_CLLI,
    EXP.DATU_EXP_PORT,
    EXP.DATU_EXP_NAME,
    EXP.DATU_EXP_CITY,
    EXP.DATU_EXP_STATE,
    EXP.DATU_EXP_SW_VERSION,
    DECODE(LAST_ALARM.LAST_ALARM_DATE, NULL, TO_CHAR(SYSDATE,'YYYY/MM/DD HH24:MI:SS'),
         TO_CHAR(LAST_ALARM.LAST_ALARM_DATE,'YYYY/MM/DD HH24:MI:SS')) AS STATUS_DATE,
    DECODE(LAST_ALARM.ALARM_NAME, NULL, 'Disconnected', LAST_ALARM.ALARM_NAME) AS DATU_STATUS,
    DECODE(LAST_ALARM.ALARM_CLASS, NULL, 'OTHER', LAST_ALARM.ALARM_CLASS) AS IS_ERROR_STATUS,
         DECODE(LAST_RESOURCE.LAST_ALARM_DATE, NULL, '', TO_CHAR(LAST_RESOURCE.LAST_ALARM_DATE,'YYYY/MM/DD HH24:MI:SS')) AS RESOURCE_STATUS_DATE,
         DECODE(LAST_RESOURCE.RESOURCE_CODE_NAME, NULL, '', LAST_RESOURCE.RESOURCE_CODE_NAME) AS RESOURCE_STATUS,
         DECODE(LAST_RESOURCE.RESOURCE_CODE_CLASS, NULL, '', LAST_RESOURCE.RESOURCE_CODE_CLASS) AS IS_RESOURCE_ERROR_STATUS,
         DECODE(LAST_OPER.LAST_ALARM_DATE, NULL, '', TO_CHAR(LAST_OPER.LAST_ALARM_DATE,'YYYY/MM/DD HH24:MI:SS')) AS OPER_STATUS_DATE,
         DECODE(LAST_OPER.OPER_CODE_NAME, NULL, '', LAST_OPER.OPER_CODE_NAME) AS OPER_STATUS,
         DECODE(LAST_OPER.OPER_CODE_CLASS, NULL, '', LAST_OPER.OPER_CODE_CLASS) AS IS_OPER_ERROR_STATUS,
    EXP.BEGIN_MAINT_WINDOW, RTU.RTU_NAME
    FROM TT_DATU_EXP_UNIT_INFO EXP
         left outer join
    SELECT distinct alarmed_datus.EXP_ID, c.ALARM_NAME, c.ALARM_TYPE, c.ALARM_CLASS, alarmed_datus.LAST_ALARM_DATE
    FROM ( SELECT EXP_ID, MAX(ALARM_TIME) AS LAST_ALARM_DATE FROM TT_DATU_EXP_ALARM_INFO GROUP BY EXP_ID) alarmed_datus
         inner join TT_DATU_EXP_ALARM_INFO b on b.EXP_ID = alarmed_datus.EXP_ID AND b.ALARM_TIME = alarmed_datus.LAST_ALARM_DATE
         inner join TT_DATU_EXP_ALARM_TYPES c on b.ALARM_TYPE = c.ALARM_TYPE ) LAST_ALARM on EXP.EXP_ID = LAST_ALARM.EXP_ID
         left outer join
              ( SELECT distinct a.EXP_ID, c.RESOURCE_CODE_NAME, c.RESOURCE_CODE_TYPE, c.RESOURCE_CODE_CLASS, a.LAST_ALARM_DATE
              FROM ( SELECT EXP_ID, MAX(RESOURCE_CODE_TIME) AS LAST_ALARM_DATE
              FROM TT_DATU_EXP_RESOURCE_CODE_INFO GROUP BY EXP_ID ) a
         inner join TT_DATU_EXP_RESOURCE_CODE_INFO b on b.EXP_ID = a.EXP_ID AND b.RESOURCE_CODE_TIME = a.LAST_ALARM_DATE
         inner join TT_DATU_EXP_RESOURCECODE_TYPES c on b.RESOURCE_CODE_TYPE = c.RESOURCE_CODE_TYPE) LAST_RESOURCE on EXP.EXP_ID = LAST_RESOURCE.EXP_ID
         left outer join
              ( SELECT distinct a.EXP_ID, c.OPER_CODE_NAME, c.OPER_CODE_TYPE, c.OPER_CODE_CLASS, a.LAST_ALARM_DATE
              FROM ( SELECT EXP_ID, MAX(OPER_CODE_TIME) AS LAST_ALARM_DATE
              FROM TT_DATU_EXP_OPER_CODE_INFO GROUP BY EXP_ID ) a
         inner join TT_DATU_EXP_OPER_CODE_INFO b on b.EXP_ID = a.EXP_ID AND b.OPER_CODE_TIME = a.LAST_ALARM_DATE
         inner join TT_DATU_EXP_OPER_CODE_TYPES c on b.OPER_CODE_TYPE = c.OPER_CODE_TYPE
              ) LAST_OPER on EXP.EXP_ID = LAST_OPER.EXP_ID ORDER BY EXP.DATU_EXP_CLLI
    inner join TT_RTU_TYPES RTU ON EXP.RTU_TYPE_ID = RTU.RTU_TYPE_ID
    WHERE EXP.IS_PRIMARY_ADDRESS like p_isPrimary;
    this one not work kept giving me errors:
    [ ORA-00933: SQL command not properly ended
    Any guru can help? I need to have this resolved end of today.
    Thanks in advance.

    Hi,
    Never write, let alone post, unformatted code.
    Indent the code so that it's easy to set the scope of sub-queries, and the majoc clauses (SELECT, FROM, WHERE, ORDER BY, ...) in each.
    When posting any formatted text on this site, type these 6 characters:
    \(small letters only, inside curly brackets) before and after each section of formatted text, to preserve spacing.
    If you do that to the code you posted, you'll see that it ends like this:... inner join     TT_DATU_EXP_OPER_CODE_INFO     b on b.EXP_ID     = a.EXP_ID
                                       AND      b.OPER_CODE_TIME = a.LAST_ALARM_DATE
         inner join      TT_DATU_EXP_OPER_CODE_TYPES      c on      b.OPER_CODE_TYPE = c.OPER_CODE_TYPE
         ) LAST_OPER          on EXP.EXP_ID = LAST_OPER.EXP_ID
    ORDER BY EXP.DATU_EXP_CLLI
    inner join TT_RTU_TYPES RTU     ON EXP.RTU_TYPE_ID = RTU.RTU_TYPE_ID
    WHERE EXP.IS_PRIMARY_ADDRESS      like p_isPrimary
    You can't put an ORDER BY clause  in the middle of the FROM clause.
    The ORDER BY clause always goes after the WHERE clause, like this:... inner join     TT_DATU_EXP_OPER_CODE_INFO     b on b.EXP_ID     = a.EXP_ID
                                       AND      b.OPER_CODE_TIME = a.LAST_ALARM_DATE
         inner join      TT_DATU_EXP_OPER_CODE_TYPES      c on      b.OPER_CODE_TYPE = c.OPER_CODE_TYPE
         ) LAST_OPER          on EXP.EXP_ID = LAST_OPER.EXP_ID
    inner join TT_RTU_TYPES RTU     ON EXP.RTU_TYPE_ID = RTU.RTU_TYPE_ID
    WHERE EXP.IS_PRIMARY_ADDRESS      like p_isPrimary
    ORDER BY EXP.DATU_EXP_CLLI

  • Dynamic Table name in Inner Join in  4.6c

    data: tab1(10) type c value 'MARA',
            tab2(10) type c value 'MAKT'.
    data: dbtab1(10) type c,
             dbtab2(10) type c .
    dbtab1 = tab1. 
    dbtab2 = tab2. 
    DATA: BEGIN OF itab occurs 0,
               matnr TYPE mara-matnr,
               maktx type makt-maktx,
    END OF itab.
    DATA: column_syntax TYPE string,
                dbtab_syntax TYPE string.
    PARAMETERS: p_matnr TYPE mara-matnr.
    dbtab_syntax = '( (dbtab1) AS t1 '
    &' INNER JOIN (dbtab2) AS t4 ON t1MATNR = t4MATNR )'.
    SELECT  matnr maktx
    FROM (dbtab_syntax)
    INTO TABLE itab  WHERE t4~matnr   = p_matnr.
    Got the following error:
    "A table name, specified in an SQL command, is unknown"
    It seems not able to read dynamic table name in dbtab_syntax.
    thanks
    anya
    Moderation Message: Duplicate Post.
    Edited by: kishan P on Nov 29, 2010 11:17 AM

    Hi,
    Check this link.
    [http://help.sap.com/saphelp_nw04/helpdata/en/fc/eb39c4358411d1829f0000e829fbfe/frameset.htm]
    [Re: accessing dynamic internal table's fields??;
    hope it'll help u.
    Regards,
    Sneha.
    Edited by: sneha kumari on Jun 18, 2009 1:57 PM

  • Difference between inner join and outer join

    1.Difference between inner join and outer join
    2.wht is the difference in using hide and get crusor value in interactive.
    3. Using join is better or views in writting program . Which is better.

    Table 1                      Table 2
    A
    B
    C
    D
    D
    E
    F
    G
    H
    a1
    b1
    c1
    1
    1
    e1
    f1
    g1
    h1
    a2
    b2
    c2
    1
    3
    e2
    f2
    g2
    h2
    a3
    b3
    c3
    2
    4
    e3
    f3
    g3
    h3
    a4
    b4
    c4
    3
    |--|||--|
        Inner Join
        |--||||||||--|
        | A  | B  | C  | D  | D  | E  | F  | G  | H  |
        |--||||||||--|
        | a1 | b1 | c1 | 1  | 1  | e1 | f1 | g1 | h1 |
        | a2 | b2 | c2 | 1  | 1  | e1 | f1 | g1 | h1 |
        | a4 | b4 | c4 | 3  | 3  | e2 | f2 | g2 | h2 |
        |--||||||||--|
    Example
    Output a list of all flights from Frankfurt to New York between September 10th and 20th, 2001 that are not sold out:
    DATA: DATE   LIKE SFLIGHT-FLDATE,
          CARRID LIKE SFLIGHT-CARRID,
          CONNID LIKE SFLIGHT-CONNID.
    SELECT FCARRID FCONNID F~FLDATE
        INTO (CARRID, CONNID, DATE)
        FROM SFLIGHT AS F INNER JOIN SPFLI AS P
               ON FCARRID = PCARRID AND
                  FCONNID = PCONNID
        WHERE P~CITYFROM = 'FRANKFURT'
          AND P~CITYTO   = 'NEW YORK'
          AND F~FLDATE BETWEEN '20010910' AND '20010920'
          AND FSEATSOCC < FSEATSMAX.
      WRITE: / DATE, CARRID, CONNID.
    ENDSELECT.
    If there are columns with the same name in both tables, you must distinguish between them by prefixing the field descriptor with the table name or a table alias.
    Note
    In order to determine the result of a SELECT command where the FROM clause contains a join, the database system first creates a temporary table containing the lines that meet the ON condition. The WHERE condition is then applied to the temporary table. It does not matter in an inner join whether the condition is in the ON or WHEREclause. The following example returns the same solution as the previous one.
    Example
    Output of a list of all flights from Frankfurt to New York between September 10th and 20th, 2001 that are not sold out:
    DATA: DATE   LIKE SFLIGHT-FLDATE,
          CARRID LIKE SFLIGHT-CARRID,
          CONNID LIKE SFLIGHT-CONNID.
    SELECT FCARRID FCONNID F~FLDATE
        INTO (CARRID, CONNID, DATE)
        FROM SFLIGHT AS F INNER JOIN SPFLI AS P
               ON FCARRID = PCARRID
        WHERE FCONNID = PCONNID
          AND P~CITYFROM = 'FRANKFURT'
          AND P~CITYTO   = 'NEW YORK'
          AND F~FLDATE BETWEEN '20010910' AND '20010920'
          AND FSEATSOCC < FSEATSMAX.
      WRITE: / DATE, CARRID, CONNID.
    ENDSELECT.
    Note
    Since not all of the database systems supported by SAP use the standard syntax for ON conditions, the syntax has been restricted. It only allows those joins that produce the same results on all of the supported database systems:
    Only a table or view may appear to the right of the JOIN operator, not another join expression.
    Only AND is possible in the ON condition as a logical operator.
    Each comparison in the ON condition must contain a field from the right-hand table.
    If an outer join occurs in the FROM clause, all the ON conditions must contain at least one "real" JOIN condition (a condition that contains a field from tabref1 amd a field from tabref2.
    Note
    In some cases, '*' may be specified in the SELECT clause, and an internal table or work area is entered into the INTO clause (instead of a list of fields). If so, the fields are written to the target area from left to right in the order in which the tables appear in the FROM clause, according to the structure of each table work area. There can then be gaps between table work areas if you use an Alignment Request. For this reason, you should define the target work area with reference to the types of the database tables, not simply by counting the total number of fields. For an example, see below:
    Variant 3
    ... FROM tabref1 LEFT [OUTER] JOIN tabref2 ON cond
    Effect
    Selects the data from the transparent database tables and/or views specified in tabref1 and tabref2. tabref1 und tabref2 both have either the same form as in variant 1 or are themselves join expressions. The keyword OUTER can be omitted. The database tables or views specified in tabref1 and tabref2 must be recognized by the ABAP-Dictionary.
    In order to determine the result of a SELECT command where the FROM clause contains a left outer join, the database system creates a temporary table containing the lines that meet the ON condition. The remaining fields from the left-hand table (tabref1) are then added to this table, and their corresponding fields from the right-hand table are filled with ZERO values. The system then applies the WHERE condition to the table.
    Left outer join between table 1 and table 2 where column D in both tables set the join condition:
    Table 1                      Table 2
    A
    B
    C
    D
    D
    E
    F
    G
    H
    a1
    b1
    c1
    1
    1
    e1
    f1
    g1
    h1
    a2
    b2
    c2
    1
    3
    e2
    f2
    g2
    h2
    a3
    b3
    c3
    2
    4
    e3
    f3
    g3
    h3
    a4
    b4
    c4
    3
    |--|||--|
        Left Outer Join
        |--||||||||--|
        | A  | B  | C  | D  | D  | E  | F  | G  | H  |
        |--||||||||--|
        | a1 | b1 | c1 | 1  | 1  | e1 | f1 | g1 | h1 |
        | a2 | b2 | c2 | 1  | 1  | e1 | f1 | g1 | h1 |
        | a3 | b3 | c3 | 2  |NULL|NULL|NULL|NULL|NULL|
        | a4 | b4 | c4 | 3  | 3  | e2 | f2 | g2 | h2 |
        |--||||||||--|
    Regards
    Prabhu

  • Urgent: inner joins

    i wanna add inner joins in my report,plz give me d link of websites which provide suitable example.. if u r having example of it den do tell me...
    its really urgent...

    HI
    SELECT - join
    ... [(] {dbtab_left [AS tabalias_left]} | join
              {[INNER] JOIN}|{LEFT [OUTER] JOIN}
                {dbtab_right [AS tabalias_right] ON join_cond} [)] ...  .
    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.
    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.
    REWARD if usefull

  • Time Out by select on DD04L inner join DD04T

    Hello,
    I just installed ERP 2005. After the import of a language package (SMLT, IT, FR, ES) I get some problem.
    If I logon with EN or IT (and I think with any language other than DE) many transaction get a Time Out error in the function module DDIF_FIELDINFO_GET by the following selection:
    *             get texts of primary language (inner join here !)
                  SELECT DD04L~ROLLNAME DD04L~DOMNAME DD04L~HEADLEN
                         DD04L~SCRLEN1  DD04L~SCRLEN2 DD04L~SCRLEN3
                         DD04T~DDLANGUAGE DD04T~DDTEXT    DD04T~REPTEXT
                         DD04T~SCRTEXT_S  DD04T~SCRTEXT_M DD04T~SCRTEXT_L
                         INTO TABLE Rolltexts
                         FROM DD04L inner JOIN DD04T
                         ON DD04T~ROLLNAME = DD04L~ROLLNAME AND
                            DD04T~AS4LOCAL = 'A' AND
                            DD04T~DDLANGUAGE = langu_loc
                         FOR ALL ENTRIES IN missing
                         WHERE DD04L~ROLLNAME = missing-ROLLNAME
                           AND DD04L~AS4LOCAL = 'A'.
    That is, the ERP is using sequential read instead of direct read.
    Any idea is welcomed.
    Thanks & regards,
    Tommaso

    Hello,
    Thanks for your replies.
    I checked OSS and I found nothing.
    ST05 gives me this SQL command: (more than 500 sec!)
    SELECT T_00 . "ROLLNAME" , T_00 . "DOMNAME" , T_00 . "HEADLEN" , T_00 . "SCRLEN1" , T_00 . "SCRLEN2" , T_00 . "SCRLEN3" , T_01 . "DDLANGUAGE" , T_01 . "DDTEXT" , T_01 . "REPTEXT" , T_01 . "SCRTEXT_S" , T_01 . "SCRTEXT_M" , T_01 . "SCRTEXT_L" FROM "DD04L"
    T_00 INNER JOIN "DD04T" T_01 ON T_01 . "ROLLNAME" = T_00 . "ROLLNAME" AND T_01 . "AS4LOCAL" = 'A' AND T_01 . "DDLANGUAGE" = 'I' WHERE T_00 . "ROLLNAME" = 'VAL_TEXT' AND T_00 . "AS4LOCAL" = 'A'
    I executed it in SQL Studio and I got also a big execution time.
    But if I try
    SELECT  "ROLLNAME" ,  "DOMNAME" ,  "HEADLEN" , "SCRLEN1" , "SCRLEN2" , "SCRLEN3"  FROM "DD04L" WHERE T_00 . "ROLLNAME" = 'VAL_TEXT' AND T_00 . "AS4LOCAL" = 'A'
    I get the result in 1 ms.
    Is there something wrong in the inner join?
    What does it mean the operation "REOPEN"?
    How can I see from ST05 if an index has been used?
    Thanks & Regards,
    Tommaso

  • Dynamic Inner Join in 4.6c

    Requirement is dynamic specification of  Table name in inner join. The table names to be used in join would be derived in a variable using select statement. These names to be supplied to join dynamically. The other join conditions and where conditions will remain same.
    For example :
    On the basis of 1st select statement tables names are fetched in 2 variables tab1 & tab2.
    Now want to use these two variables in inner join statement.
    Searched and as per few example tried to do in following manner but its not working
    data: tab1(10) type c value 'MARA',
            tab2(10) type c value 'MAKT'.
    data: dbtab1(10) type c,
             dbtab2(10) type c .
    dbtab1 = tab1. 
    dbtab2 = tab2. 
    DATA: BEGIN OF itab occurs 0,
               matnr TYPE mara-matnr,
               maktx type makt-maktx,
    END OF itab.
    DATA: column_syntax TYPE string,
                dbtab_syntax TYPE string.
    PARAMETERS: p_matnr TYPE mara-matnr.
    dbtab_syntax = '( (dbtab1) AS t1 '
    &' INNER JOIN (dbtab2) AS t4 ON t1~MATNR = t4~MATNR )'.
    SELECT  matnr maktx
    FROM (dbtab_syntax)
    INTO TABLE itab  WHERE t4~matnr   = p_matnr.
    Got the following error:
    "A table name, specified in an SQL command, is unknown"
    It seems not able to identify table name dynamiccaly in dbtab_syntax.
    thanks
    anya
    Edited by: Thomas Zloch on Nov 29, 2010 10:18 AM - please use code tags

    Hi Anya,
    Following code will be work
    CONCATENATE dbtab1 ' as t1 INNER JOIN ' dbtab2 ' as t4 ON t1MATNR = t4MATNR ' INTO dbtab_syntax RESPECTING BLANKS.
    TRANSLATE dbtab_syntax TO UPPER CASE.
    SELECT  t1~matnr maktx
    FROM (dbtab_syntax)
    INTO TABLE itab  WHERE t4~matnr   = p_matnr.
    Note the following point
    1) Don't used un-necessary bracket inside the SQL.
    2) Specify alias name or table name when fields exit in both table while projection.
        i.e. SELECT  matnr maktx will be now SELECT  t1~matnr maktx

  • Syntax of  inner join

    hello sir,
                 plz tell me the syntax of inner join for three tables.

    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.
    we r using 2 type of joins in abap they are
    1) inner join.
    this will join 2 tables using an common fiend and return the result with field values wich are common in both the tables
    itab1 itab2
    a b c a d
    1 2 3 1 5
    2 3 4 3 6
    after innerjoining itab1 n itab2 on field a we wil get the o/p as
    a b c d
    1 2 3 5
    only common field is taken..
    2)left outer join
    here it wil work in opossite way it will give values whic are not common
    itab1 itab2
    a b c a d
    1 2 3 1 5
    2 3 4 3 6
    after left outer joining itab1 n itab2 on field a we wil get the o/p as
    a b c d
    2 3 4
    only fields which are not common is taken from the left table..other field(d here) wil be empty
    I think it will help u.
    Reward Points if helpful.
    Check for ALVROBOT.COM also it is also helpful.

  • Update Con Inner Join

    haber tengo una duda, existe en oracle los Inner join, si existen me podrian decir cual es el error en este update
    me envia este codigo de oracle
    ORA-00933: SQL command not properly ended
    Código HTML:
    UPDATE NOTAS SET C5=0, P5=0, C6=0, P6=0, C7=0, P7=0, C8=0, P8=0, C9=0, P9=0, C10=0, P10=0, C11=0, P11=0, C12=0, P12=0, C13=0, P13=0, C14=0, P14=0, C15=0, P15=0, EX3=0, PEX3=0, P1=0, GLOSA_C1='SIN COMENTARIO', P2=0, GLOSA_C2='SIN COMENTARIO', P3=0, GLOSA_C3='SIN COMENTARIO', P4=0, GLOSA_C4='SIN COMENTARIO', PEX1=0, GLOSA_EX1='SIN COMENTARIO', PEX2=0, GLOSA_EX2='SIN COMENTARIO', CANT_NOTAS=4, CANT_EXAMENES=2 INNER JOIN DETALLE_ASIGNACION_ALUMNO ON(DETALLE_ASIGNACION_ALUMNO.ID_ALUMNO=ALUMNO.ID_ALUMNO) INNER JOIN NOTAS ON(DETALLE_ASIGNACION_ALUMNO.ID_ALUMNO=NOTAS.ID_ALUMNO) WHERE DETALLE_ASIGNACION_ALUMNO.ID_DETALLE_ALUMNO='1' AND NOTAS.ID_ASIGNATURA='2'
    grax por la ayuda
    Responder Con Cita

    Check from the INNER JOIN.

  • Why is a cross join classified as an inner join?

    hi guys,
    searching the web is just confusing me, so maybe someone here could help.
    On wikipedia (for join) it says:
    An outer join does not require each record in the two joined tables to have a matching record
    Now, a cross join does not require any of the records of the table to have a matching record, therefore I would classify it as an outer join. Why then is it classified as an inner join?
    thanks

    Cross join produces the cross-product. You can not specify cross join condition since there is none - it always implies every row in table1 joined with every row in table2:
    SQL> select ename,dname from emp cross join dept on(1=1)
      2  /
    select ename,dname from emp cross join dept on(1=1)
    ERROR at line 1:
    ORA-00933: SQL command not properly ended
    SQL> With outer join you must specify join condition:
    SQL> select ename,dname from emp left join dept
      2  /
    select ename,dname from emp left join dept
    ERROR at line 1:
    ORA-00905: missing keyword
    SQL> And join result rules are completely different - matching rows or NULL row.
    SY.

  • Problem in Accession inner join with [Microsoft][SQLServer 2000 Driver

    Hi
    Can you tell me what can be cause my sql statement is correct gives result but
    if i used below statement in my JSP ,cause error
    1)
    ps1=connection.prepareStatement("select RQM_IN_RQSTN_ID_PK,RQD_IN_ITM_ID_FKPK,RQD_VC_ITM_DSCRPTN,RQD_IN_STTS_ID_FK,C.SMT_VC_STTS_NM,a.RQM_DT_PRPSD_DLVRY_DT"+
    "from PAS_RQM_RQSTN_MSTR a "+
    "inner join PAS_RQD_RQSTN_DTLS b on a.RQM_IN_RQSTN_ID_PK = b.RQD_IN_RQSTN_ID_FKPK and RQD_IN_STTS_ID_FK = 4"+
    "INNER JOIN PAS_SMT_STTS_MSTR C ON C.SMT_IN_STTS_ID_PK=B.RQD_IN_STTS_ID_FK" +
    "where a.RQM_VC_DTRTMNT_INVLV='Technology' ");
    2) Error Generate
    java.sql.SQLException
    [Microsoft][SQLServer 2000 Driver for JDBC][SQLServer]Line 1: Incorrect syntax near 'a'.
    What can be the cause
    Thanks

    ps1=connection.prepareStatement("select
    RQM_IN_RQSTN_ID_PK,RQD_IN_ITM_ID_FKPK,RQD_VC_ITM_DSCRP
    TN,RQD_IN_STTS_ID_FK,C.SMT_VC_STTS_NM,a.RQM_DT_PRPSD_D
    LVRY_DT"+
    "from PAS_RQM_RQSTN_MSTR a "+
    "inner join PAS_RQD_RQSTN_DTLS b on
    a.RQM_IN_RQSTN_ID_PK = b.RQD_IN_RQSTN_ID_FKPK and
    RQD_IN_STTS_ID_FK = 4"+
    "INNER JOIN PAS_SMT_STTS_MSTR C ON
    C.SMT_IN_STTS_ID_PK=B.RQD_IN_STTS_ID_FK" +
    "where a.RQM_VC_DTRTMNT_INVLV='Technology' ");This is a problem due to not providing spaces where they are needed. See the places where I have highlighted.
    A better way is to generate the String first [use StringBuffer as a good practice for appending instead of String "+"] and print it out to check if it is correct.
    ***Annie***

  • Data is not fetching in inner join

    Hi Experts,
    I developed a select query using inner joins, all the fields data is gettting appended, but one field DISPO data is not getting appeneded. please check the innerjoin and suggest me ur soluitons.
    MODULE GET_DATA OUTPUT.
      select   arbpl
             sptag
             aufnr
             plnum
             posnr
             plnfl
             werks  from s022
                        into table it_s022
                         where arbpl in s_arbpl
                          and  werks in s_werks
                          and  sptag in s_sptag
                          and  matnr in s_matnr.
    if sy-subrc eq 0.
    select a~aufnr
           a~posnr
           a~kdauf
           a~pgmng
           a~plnum
           a~strmp
           b~plnty
           b~gamng
           b~igmng
           b~iasmg
           b~rmnga
           b~gstrp
           b~rsnum
           b~plnbez
           b~dispo
           c~maktx
           b~plnnr
           b~plnty
           b~zaehl
           d~vornr
           d~ltxa1
           b~aufpl
           b~aplzt
           e~astnr
           into corresponding fields of table it_afpo from  afko as b
                    inner join afpo as  a
                     on a~aufnr = b~aufnr
                    inner join makt as c
                     on b~plnbez = c~matnr
                    inner join plpo as d
                     on b~plnnr  = d~plnnr
                      and b~plnty = d~plnty
                      and b~zaehl  = d~zaehl
                     inner join aufk as e
                      on b~aufnr = e~aufnr
                    inner join marc as f
                     on bplnty = fmatnr
                    for all entries in it_s022
                     where b~aufnr = it_s022-aufnr.
                         and e~erdat = it_s022-sptag
                     and  a~posnr = it_s022-posnr
                    and  a~plnum = it_s022-plnum .  .
      if sy-subrc eq 0.
        it_afpo1[] = it_afpo[].
        sort it_afpo1 by aufpl." aplzt."""
        delete ADJACENT DUPLICATES FROM it_afpo1 COMPARING aufpl." aplzt ."""
        select aufpl
               aplzl
               fsavd
               fsavz
               ssedd
               ssedz
               mgvrg
                FROM  afvv  INTO TABLE It_afvv
                               FOR ALL ENTRIES IN IT_afpo1
                               WHERE aufpl = IT_afpo1-aufpl.
                                and aplzl = it_afpo1-aplzt.
       endif.
    loop at it_afpo into wa_afpo.
    DATA : G_SLNO(8) TYPE C.
    G_SLNO = G_SLNO + 1.
    wa_afpo-slno = g_slno.
        move-corresponding wa_afpo to wa_final.
       move-corresponding wa_afko to wa_final.
      read table it_afvv into wa_afvv with key
                aufpl = wa_afpo-aufpl binary search."aplzl = wa_afpo-aplzt binary search."""
    *read table it_afko into wa_afko with key aufnr = wa_final-aufnr.
      IF SY-SUBRC EQ 0.
        move-corresponding wa_afvv to wa_final.
    bal_qty = wa_final-gamng - wa_final-igmng.
        move : wa_afpo-slno  to wa_final-slno,
               wa_afpo-aufnr to wa_final-aufnr,
               wa_afpo-posnr to wa_final-posnr,
               wa_afpo-kdauf to wa_final-kdauf, " Sales order Number
               wa_afpo-pgmng to wa_final-pgmng, " Order item qty
               wa_afpo-plnum to wa_final-plnum, " Planned  Order Qty
               wa_afpo-strmp to wa_final-strmp, " Planned Order Date
               wa_afpo-gstrp to wa_final-gstrp, " Basic Finish  date
               wa_afpo-rsnum to wa_final-rsnum, " Number of Reservation
               wa_afpo-plnbez to wa_final-plnbez, " Material Number
               wa_afpo-maktx to wa_final-maktx,
               wa_afpo-plnnr to wa_final-plnnr,
               wa_afpo-plnty to wa_final-plnty,
               wa_afpo-zaehl to wa_final-zaehl,
               wa_afpo-vornr to wa_final-vornr,
               wa_afpo-ltxa1 to wa_final-ltxa1,
               wa_afpo-aufpl to wa_final-aufpl,
               wa_afvv-fsavd to wa_final-fsavd,
               wa_afvv-fsavz to wa_final-fsavz,
               wa_afvv-ssedd to wa_final-ssedd,
               wa_afvv-ssedz to wa_final-ssedz,
               wa_afvv-mgvrg to wa_final-mgvrg,
               wa_afko-igmng to wa_final-igmng,
               wa_afko-iasmg to wa_final-iasmg,
               wa_afko-rmnga to wa_final-rmnga,
               wa_afko-dispo to wa_final-dispo,
              wa_afko-bal_qty to wa_final-bal_qty,
               wa_aufk-astnr to wa_final-astnr,
               wa_afpo-text  to wa_final-text.
    *bal_qty = wa_final-gamng - wa_final-igmng.
    *bal_qty = wa_afko-bal_qty.
      endif.
      append wa_final to it_final.
      clear:wa_final ,wa_afpo,wa_afvv,wa_aufk,wa_afko.
    endloop.
    endif.
    ENDMODULE.                 " GET_DATA  OUTPUT
    *&      Module  DISPLAY_DATA  OUTPUT
          text
    MODULE DISPLAY_DATA OUTPUT.
      IF REF_CONTAINER IS INITIAL.
         PERFORM FIELD_CAT.
      CREATE OBJECT REF_CONTAINER
      EXPORTING
           PARENT                      =
        CONTAINER_NAME              = 'CUSTOM_CONTROL'
           STYLE                       =
           LIFETIME                    = lifetime_default
           REPID                       =
           DYNNR                       =
           NO_AUTODEF_PROGID_DYNNR     =
          EXCEPTIONS
            CNTL_ERROR                  = 1
            CNTL_SYSTEM_ERROR           = 2
            CREATE_ERROR                = 3
            LIFETIME_ERROR              = 4
            LIFETIME_DYNPRO_DYNPRO_LINK = 5
            others                      = 6
      IF SY-SUBRC <> 0.
        MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
                   WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
      ENDIF.
      L_LAYO-ZEBRA = 'X'.
      L_LAYO-GRID_TITLE = 'JOB CARD'.
      data: variant type disvariant.
      CREATE OBJECT REF_ALV_GRID
        EXPORTING
           I_SHELLSTYLE      = 0
           I_LIFETIME        =
          I_PARENT          = REF_CONTAINER
           I_APPL_EVENTS     = space
           I_PARENTDBG       =
           I_APPLOGPARENT    =
           I_GRAPHICSPARENT  =
           I_NAME            =
           I_FCAT_COMPLETE   = SPACE
          EXCEPTIONS
            ERROR_CNTL_CREATE = 1
            ERROR_CNTL_INIT   = 2
            ERROR_CNTL_LINK   = 3
            ERROR_DP_CREATE   = 4
            others            = 5
      IF SY-SUBRC <> 0.
        MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
                   WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
      ENDIF.
    l_variant-report = sy-cprog.
    *data: l_prnt type lvc_s_prnt.
    *l_prnt-print = 'X'.
      SORT T_FCAT.
      call method ref_alv_grid->set_ready_for_input
       exporting
        i_ready_for_input = 1.
    create object event_receiver.
       set handler event_receiver->handle_top_of_page for ref_alv_grid.
      CALL METHOD REF_ALV_GRID->SET_TABLE_FOR_FIRST_DISPLAY
           EXPORTING
           I_BUFFER_ACTIVE               =
           I_BYPASSING_BUFFER            =
           I_CONSISTENCY_CHECK           =
           I_STRUCTURE_NAME              =
            is_variant                     =  variant   "l_variant
            i_save                        = 'X'
           I_DEFAULT                     = 'X'
             IS_LAYOUT                     = L_LAYO
           IS_PRINT                      =
           IT_SPECIAL_GROUPS             =
           IT_TOOLBAR_EXCLUDING          =
           IT_HYPERLINK                  =
           IT_ALV_GRAPHICS               =
           IT_EXCEPT_QINFO               =
           IR_SALV_ADAPTER               =
        CHANGING
          IT_OUTTAB                     = IT_final[]
          IT_FIELDCATALOG               = T_FCAT
           IT_SORT                       =
           IT_FILTER                     =
          EXCEPTIONS
            INVALID_PARAMETER_COMBINATION = 1
            PROGRAM_ERROR                 = 2
            TOO_MANY_LINES                = 3
            others                        = 4
      IF SY-SUBRC <> 0.
        MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
                   WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
      ENDIF.
       create object g_event_receiver.
       set handler g_event_receiver->handle_user_command for ref_alv_grid.
       set handler g_event_receiver->handle_toolbar for ref_alv_grid.
    § 4.Call method 'set_toolbar_interactive' to raise event TOOLBAR.
       call method ref_alv_grid->set_toolbar_interactive.
       call method cl_gui_control=>set_focus exporting control = ref_alv_grid.
    ENDIF.
    ENDMODULE.                 " DISPLAY_DATA  OUTPUT
    *&      Module  STATUS_0100  OUTPUT
          text
    MODULE STATUS_0100 OUTPUT.
      SET PF-STATUS 'MAIN001'.
    SET TITLEBAR 'xxx'.
    Regards,
    Bharath Kumar

    I agree with Shiva Kumar - most likely there is no such field in it_afpo. A few more suggestions though:
    1) Do not post large pieces of code here - if you have a question about a particular SELECT statement, post only that statement and relevant data definitions. No one is going to read your whole program  anyway - we have work to do too.
    2) Your JOIN is way too big and would be difficult to analyze if anything goes wrong. You might want to start with smaller SELECTs and, when you're sure everything is working correctly, then combine them into one. Also huge JOINT is not necessarily more efficient.
    3) You don't have to use aliases "AS a... AS b", etc. Instead, just use the table name, e.g. AFKO... AFPO... .It is much easier to read this way. The aliases are needed only if you're joining the same table more than once. Also they're not limited to one letter either.

Maybe you are looking for

  • How can I automatically incorporate 'shuffle' into a playlist?

    I have a 20 GB IPOD full of music. I have playlists that I like to listen to 'shuffled' and then sometimes I like to listen to entire albums (from start to finish, not shuffled). I am tired of going to the IPOD settings and changing this each time. I

  • ITunes/my phone won't let me put music on my phone? I can see it but it won't let me select it in "on this phone"

    Hey there, I have had my iPhone 5 since October and every time I would do an update the phone would crash and I had to start from scratch every time (thank god for back ups). So I finally got the chance to switch out my phone at an apple store about

  • Usb not connecting in oracle vm virtual box

    hi , I am using vm virtual box 4.1.18. From my guest os solaris 10 i cant access USB i have install virtual box extension on it and also add filter but when i click on the second button add filter from device it show me message no device available. K

  • Contacts added in iPhone don not sync into Outlook on PC

    Has anyone else had this issue: I have added new contacts into my iPhone and have tried to sync the iPhone with Outlook and the newly added contacts do not show up in Outlook Contacts. Is there a method to force sync of newly added contacts? Thanks R

  • Srw.get_report_name error

    I got an Oracle report 6i report where I use srw.get_report_name(:c_reportname) and it works fine when I'm using it. But when the report is handed over to my client and run on their database (in same way as I do) an error appears : REP-1418: 'beforep