About inner join in abap

hi
    i am new to sap , i dont no about inner join in abap coding
plz send me some notes or coding.
                        thank u.
                                                          your regrads
                                                                divya.

hi
use this links
INNER JOIN  and OUTER JOINhttp://help.sap.com/erp2005_ehp_03/helpdata/EN/cf/21ec77446011d189700000e8322d00/frameset.htm
JOINED TABLES
http://help.sap.com/erp2005_ehp_03/helpdata/EN/0f/49bd6a5d5049edba7b3afe6c7956e3/frameset.htm
u will find all thins related to joins with example and how to use it
Cheers
Snehi
Edited by: snehi chouhan on Jul 25, 2008 9:45 AM

Similar Messages

  • SUBQUERY with INNER JOIN in ABAP

    Hi Expert
    How Can I write SUBQUERY with INNER JOIN in ABAP.
    thanks

    Thanks Sidhharth for your Respose
    Actually I need data from VBAP, VBAK, VBUP, VBUK and VBKD with all functional validation satisfied for a sales order item data. The requirement is to report all item data with other information from table VBAK, VBUP, VBUK and VBKD in a corresponding record with ALL data in VBAP.
    Your help is appriciated.
    see the below query for reference
    select   alias_vbap~vbeln from  vbap as
    alias_vbap inner join vbak as alias_vbak
    on  alias_vbapvbeln eq  alias_vbakvbeln
    "and  alias_vbak~bukrs_vf eq '2400'
    inner join vbuk as alias_vbuk
    on alias_vbukvbeln = alias_vbapvbeln
    inner join vbup as alias_vbup
    on alias_vbupvbeln = alias_vbapvbeln
    and alias_vbupposnr = alias_vbapposnr
    left OUTER join veda as alias_veda
    on alias_vedavbeln = alias_vbapvbeln
    and alias_vedavposn = alias_vbapposnr
    left outer join vbkd as alias_vbkd
    on alias_vbkdvbeln = alias_vbapvbeln
    and alias_vbkdposnr = alias_vbapposnr

  • Inner join in ABAP and exporting the data

    Hi,
    I want to use inner join in ABAP for retrieving data from 2 tables and export that data.How will i do it?

    Hi,
    Refer following code
    *--Select query to pick the data from table VBRK
    VBRP and VBPA using inner join
      SELECT a~vbeln                            "Billing document
             a~fkdat                            "Billing date
             a~fktyp                            "Billing category
             a~fkart                            "Billing type
             a~vtweg                            "Distribution channel
             a~knumv                            "Number of doc condition
             b~posnr                            "Billing item
             b~matnr                            "Material Number
             b~werks                            "Plant
             b~vgbel                            "Referance
             b~netwr                            "Net value of billing item
             b~wavwr                            "Cost in document currency
             c~kunnr                            "Partner function
             FROM vbrk AS a
             INNER JOIN vbrp AS b
             ON avbeln EQ bvbeln
             INNER JOIN vbpa AS c
             ON  bvbeln EQ cvbeln
            AND bposnr EQ cposnr
             INTO CORRESPONDING FIELDS OF TABLE it_vbrp
             WHERE fkdat IN s_erdat
             AND   parvw EQ 'ZS'.
      IF sy-subrc EQ 0.
    *--Sort table by
        SORT it_vbrp BY vgbel1.
      ENDIF.
    Regards,
    Prashant

  • About inner join problem

    Hi Friends,
    I have given the innerjoin between BKPF & BSEG tables,
    And i am fetching BUKRS, BELNR,GJAHR, BLART,BLDAT,BUDAT  fields from BKPF and BUZEi from BSEG table, but it is showing error as u cannot create inner join for BSEG table,
    Kindly help me on this .
    Thanks & Regards,

    Hi,
    I using the code like this,
    It displaying the output without displaying any data in BUZEI field,  Even i have given the field name in the field catalog.
    Could u plz help me on this,
    Waiting for ur reply.
    TYPES  : BEGIN OF T_BKPF,
            BUKRS TYPE BKPF-BUKRS,
            BELNR TYPE BKPF-BELNR,
            GJAHR TYPE BKPF-GJAHR,
            BLART TYPE BKPF-BLART,
            BLDAT TYPE BKPF-BLDAT,
            BUDAT TYPE BKPF-BUDAT,
            BUZEI TYPE BSEG-BUZEI,
            END OF T_BKPF.
    types: begin of t_bseg,
           BUKRS TYPE BSEG-BUKRS,
           BELNR TYPE BSEG-BELNR,
           GJAHR TYPE BSEG-GJAHR,
           end of t_bseg.
    DATA : it_bkpf TYPE STANDARD TABLE OF t_bkpf with header line,
          wa_bkpf TYPE t_bkpf,
           it_bseg type standard table of t_bseg.
          wa_bseg type t_bseg.
    select bukrs belnr gjahr from bseg into table it_bseg.
    perform data_retrieval_bseg.
    perform data_retrieval.
    form data_retrieval_bseg .
      select buzei from bseg into table it_bkpf.
    endform.                    " data_retrieval_bseg
    *&      Form  DATA_RETRIEVAL
    form data_retrieval.
    IF it_bseg[] IS NOT INITIAL.
       select bukrs belnr gjahr blart bldat budat from bkpf into
         table it_bkpf for all entries in it_bseg
         where bukrs = it_bseg-bukrs
         and belnr = it_bseg-belnr
         and gjahr = it_bseg-gjahr.
         endif.
    endform.

  • Diff between database view and inner join

    Hello,
    I need to select data from multiple tables. I need to choose between 2 options.
    1) create a database view and use this view for select.
    2) write an inner join in abap prorgam.
    In which cases we should create a view and in which cases we should use a inner join?
    What are the factors which decide these?
    Pls advice.
    Thanks,
    Rupali.

    Hi,
    Both are same..
    But if you use regulary and used view in Multiple programs then create view..
    If inner join in abap prorgam between two or more table used in less Programs and do not want to
    create View (Means not to create transport request) then go for JOin in Program.
    Prabhudas

  • Inner join Vs Outer join with ABAP code...?

    Inner join Vs Outer join with ABAP code...?

    Inner Join means, it will not select that recor at all, unless there is a matching entry in the second table.
    suppose table VBAK INNER join table VBAP on VBAKVBELN = VBAPVBELN.
    In this case, if there are no entries in VBAP, the header entry also will not show up.
    But in case of OUTER JOIN, even if there is no items, it will show the header entry(VBAK) with blank columns for fields  from item table.(VBAP)
    here is one sample for inner join.
    SELECT   A~EBELN
               A~EKORG
               A~EKGRP
               A~BSART
               A~LPONR
               A~LOEKZ
               A~LIFNR
               A~RESWK
               B~AEDAT
               B~WERKS
               B~MATNR
               B~MENGE
               B~EBELP
               B~ELIKZ
               B~PLIFZ
               B~PSTYP
               B~KNTTP
               B~MATKL
               B~ZZD_PLANT
               FROM EKKO AS A INNER JOIN EKPO AS B
               ON
               AEBELN = BEBELN
               INTO CORRESPONDING FIELDS OF TABLE T_DATA
               FOR ALL ENTRIES IN T_EKET
               WHERE
               A~EBELN EQ T_EKET-EBELN AND
               A~BSART EQ C_UBSTO      AND
               A~EKORG IN S_EKORG      AND
               A~EKGRP IN S_EKGRP      AND
               A~BSTYP EQ C_BSTYP      AND
               A~LOEKZ EQ SPACE        AND " Order not deleted
               A~RESWK IN S_RESWK      AND
               B~EBELN EQ T_EKET-EBELN AND
               B~EBELP EQ T_EKET-EBELP AND
               B~WERKS IN S_WERKS      AND
               B~MATNR IN S_MATNR      AND
               B~MATKL IN S_MATKL      AND
               B~LOEKZ EQ SPACE.           " Line item not deleted

  • About a question using Update ... inner join ?

    select *
    FROM a
    INNER JOIN b ON a.ProductID=b.ProductID
    WHERE a.HeadID='000246'
    this statement is ok ;
    But the following statement does not work ! Why ?
    UPDATE a SET
    a.Quantity=a.PurchaseQuantity/b.ConversionGene
    FROM a
    INNER JOIN b ON a.ProductID=b.ProductID
    WHERE a.HeadID='000246'

    "Because Oracle syntactically does not support that type of construct..." Is a correct statement, but not because "It expects only one table in UPDATE statement". The synatax for an updateable join in Oracle requires a "proper" in-line view to be updated.
    As long as the table joined (in my example t1) has a declared unique constraint on the columns used to join by (in my example id), you can do it like:
    SQL> SELECT * FROM t;
            ID DESCR
             1 One
             2 Two
             3 Three
    SQL> SELECT * FROM t1;
            ID DESCR2
             1 Un
             2 Deux
    SQL> UPDATE (SELECT t.descr, t1.descr2
      2          FROM t
      3             JOIN t1 ON t.id = t1.id)
      4  SET descr = descr2;
    2 rows updated.
    SQL> SELECT * FROM t;
            ID DESCR
             1 Un
             2 Deux
             3 ThreeTTFN
    John

  • Using nested Joins in abap prog

    Hi All,
    please help me  out in using nested joins in abap progrmaming. I dont know about joins in abap.specially in case of outer join.
      I have 5 internal tables.. mara ,marc, mvke,mbew,ampl. am using  a  select query with certain fields from all these tables.
      I need to disply  all the materials  of  a mara for  a particular date irrespective of  the values in fields of  other tables.
            Even if that materail is not present in other table for certain condtion ,that material  should get displyed with all other fields  showing null value..

    Hi RK,
    the  code am using is of the same way...but my problem was with the joins..in the  select query  am using nested join combining inner  and outer join.. but i could  not able to display all the materials  of mara of a particular date..
    The code looks like this..
    SELECT <some fields.......>
    INTO  TABLE i_materials
          FROM  ( marc AS b
          INNER JOIN mara AS a ON amatnr = bmatnr
          INNER JOIN mvke AS c ON cmatnr = amatnr
          INNER JOIN ampl AS g ON gbmatn = amatnr
          LEFT OUTER JOIN mbew AS d ON dmatnr = bmatnr
                                   AND dbwkey = bwerks )
      WHERE a~matnr  IN s_matnr AND .................
    Else
    SELECT <some fields.......>
    INTO  TABLE i_materials
          FROM  ( marc AS b
          INNER JOIN mara AS a ON amatnr = bmatnr
          INNER JOIN mvke AS c ON cmatnr = amatnr
          INNER JOIN ampl AS g ON gbmatn = amatnr
          LEFT OUTER JOIN mbew AS d ON dmatnr = bmatnr
                                   AND dbwkey = bwerks )
       FOR ALL ENTRIES IN i_mara
         WHERE a~matnr = i_mara-matnr AND ............

  • Reply to vj (qery on the inner joins v/s performane test)

    this is ravi shiva's friend.
    hi vj,
             u r working for intelli group....and i had met u twice. by the way give u r contact number i want to speak to u personally.
              here is the code... 
    REPORT  rv_sid_purchase_order_status NO STANDARD PAGE HEADING MESSAGE-ID zrv_message_cl LINE-COUNT 65 LINE-SIZE 110 .
    This include contains declarations
    INCLUDE zrv_sid_purchase_order_t.
    This include contains code for the performs
    INCLUDE zrv_sid_purchase_order_f.
                          Initialization
    INITIALIZATION.
    This perform will initialize the values.
      PERFORM f_initilaize.
    This perform will initialize the field catalog.
      PERFORM f_e01_fieldcat_init USING gt_fieldcat[].
                         Start-Of-Selection
    START-OF-SELECTION.
    This perform will read the values from the database.
      PERFORM f_selection.
    This perform will call the function module to display the values on the list.
      PERFORM f_display.
              End-Of-Selection
    END-OF-SELECTION.
    *&  Include           ZRV_SID_PURCHASE_ORDER_T                         *
               T a b l e s   D e c l a r a t i o n s                     *
    TABLES: ekko,ekpo,ekbe,ekkn,mkpf.
               Type Pools  D e c l a r a t i o n s                       *
    TYPE-POOLS: slis.
          Selection Screen Declaration
    SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-100.
    SELECT-OPTIONS: ebeln FOR ekko-ebeln,
                    aedat FOR ekko-aedat.
    SELECTION-SCREEN END OF BLOCK b1.
               V a r i  a b l e s                                        *
    DATA : gt_fieldcat         TYPE  slis_t_fieldcat_alv,
           g_repid             LIKE  sy-repid,
           gs_keyinfo          TYPE  slis_keyinfo_alv,
           g_tabname_header    TYPE  slis_tabname,
           g_tabname_item      TYPE  slis_tabname,
           ls_layout           TYPE  slis_layout_alv,
           gt_list_top_of_page TYPE  slis_t_listheader.
               I n t e r n a l  T a b l e s                               *
    DATA: BEGIN OF itab OCCURS 0,
           ebeln LIKE ekko-ebeln,
           lifnr LIKE ekko-lifnr,
           aedat LIKE ekko-aedat,
           submi LIKE ekko-submi,
           name1 LIKE lfa1-name1,
           netwr LIKE erev-netwr,
          END OF itab.
    DATA: BEGIN OF jtab OCCURS 0,
           ebeln      LIKE  ekpo-ebeln,
           ebelp      LIKE  ekpo-ebelp,
           aedat      LIKE  ekpo-aedat,
           txz01      LIKE  ekpo-txz01,
           menge1     LIKE  ekpo-menge,
           menge2     LIKE  ekbe-menge,
           effwr1     LIKE  ekpo-effwr,
           mwskz1     LIKE  ekpo-mwskz,
           ps_psp_pnr LIKE  ekkn-ps_psp_pnr,
           bewtp1     LIKE  ekbe-bewtp,
           belnr1     LIKE  ekbe-belnr,
           dmbtt      LIKE  ekbe-dmbtr,
           mblnr1     LIKE  mkpf-mblnr,
           bldat1     LIKE  mkpf-bldat,
           xblnr1     LIKE  mkpf-xblnr,
           frbnr      LIKE  mkpf-frbnr,
          END OF jtab.
    *&  Include           ZRV_SID_PURCHASE_ORDER_F                         *
    FORM f_initilaize .
      g_repid = sy-repid.
      g_tabname_header            = 'itab'.
      g_tabname_item              = 'jtab'.
      CLEAR gs_keyinfo.
      gs_keyinfo-header01         = 'EBELN'.
      gs_keyinfo-item01           = 'EBELN'.
      gs_keyinfo-header02         = space.
      gs_keyinfo-item02           = 'EBELP'.
      ls_layout-group_change_edit = 'X'.
      ls_layout-colwidth_optimize = 'X'.
      ls_layout-zebra             = 'X'.
      ls_layout-detail_popup      = 'X'.
      ls_layout-get_selinfos      = 'X'.
      ls_layout-window_titlebar   = 'PURCHASE ORDER STATUS'.
      ls_layout-no_keyfix         = 'X'.
    ENDFORM.                    " f_INITILAIZE
    *&      Form  f_e01_fieldcat_init
          text
         -->E01_LT_FIELtext
    FORM f_e01_fieldcat_init  USING  e01_lt_fieldcat TYPE slis_t_fieldcat_alv.
      DATA: ls_fieldcat TYPE slis_fieldcat_alv.
      CLEAR ls_fieldcat.
      ls_fieldcat-fieldname     = 'SUBMI'.
      ls_fieldcat-tabname       = g_tabname_header.
      ls_fieldcat-ref_fieldname = 'SUBMI'.
      ls_fieldcat-ref_tabname   = 'EKKO'.
      ls_fieldcat-key           = 'X'.
      ls_fieldcat-no_out        = 'X'.
      ls_fieldcat-no_sum        = 'X'.
      ls_fieldcat-sp_group      = 'A'.
      APPEND ls_fieldcat TO e01_lt_fieldcat.
      CLEAR ls_fieldcat.
      ls_fieldcat-fieldname     = 'EBELN'.
      ls_fieldcat-tabname       = g_tabname_header.
      ls_fieldcat-ref_fieldname = 'EBELN'.
      ls_fieldcat-ref_tabname   = 'EKPO'.
      ls_fieldcat-key           = 'X'.
      ls_fieldcat-no_out        = 'X'.
      ls_fieldcat-no_sum        = 'X'.
      ls_fieldcat-sp_group      = 'A'.
      APPEND ls_fieldcat TO e01_lt_fieldcat.
      CLEAR ls_fieldcat.
      ls_fieldcat-fieldname     = 'LIFNR'.
      ls_fieldcat-tabname       = g_tabname_header.
      ls_fieldcat-ref_fieldname = 'LIFNR'.
      ls_fieldcat-ref_tabname   = 'EKKO'.
      ls_fieldcat-key           = 'X'.
      ls_fieldcat-no_out        = 'X'.
      ls_fieldcat-no_sum        = 'X'.
      ls_fieldcat-sp_group      = 'A'.
      APPEND ls_fieldcat TO e01_lt_fieldcat.
      CLEAR ls_fieldcat.
      ls_fieldcat-fieldname     = 'NAME1'.
      ls_fieldcat-tabname       = g_tabname_header.
      ls_fieldcat-ref_fieldname = 'NAME1'.
      ls_fieldcat-ref_tabname   = 'LFA1'.
      ls_fieldcat-key           = 'X'.
      ls_fieldcat-no_out        = 'X'.
      ls_fieldcat-no_sum        = 'X'.
      ls_fieldcat-sp_group      = 'A'.
      APPEND ls_fieldcat TO e01_lt_fieldcat.
      CLEAR ls_fieldcat.
      ls_fieldcat-fieldname     = 'NETWR'.
      ls_fieldcat-tabname       = g_tabname_header.
      ls_fieldcat-ref_fieldname = 'NETWR'.
      ls_fieldcat-ref_tabname   = 'EREV'.
      ls_fieldcat-key           = 'X'.
      ls_fieldcat-no_out        = 'X'.
      ls_fieldcat-do_sum        = 'X'.
      ls_fieldcat-sp_group      = 'A'.
      APPEND ls_fieldcat TO e01_lt_fieldcat.
      CLEAR ls_fieldcat.
      ls_fieldcat-fieldname     = 'EBELP'.
      ls_fieldcat-tabname       = g_tabname_item.
      ls_fieldcat-ref_fieldname = 'EBELP'.
      ls_fieldcat-ref_tabname   = 'EKPO'.
      ls_fieldcat-key           = 'X'.
      ls_fieldcat-no_out        = 'X'.
      ls_fieldcat-no_sum        = 'X'.
      ls_fieldcat-sp_group      = 'A'.
      APPEND ls_fieldcat TO e01_lt_fieldcat.
      CLEAR ls_fieldcat.
      ls_fieldcat-fieldname     = 'TXZ01'.
      ls_fieldcat-tabname       = g_tabname_item.
      ls_fieldcat-ref_fieldname = 'TXZ01'.
      ls_fieldcat-ref_tabname   = 'EKPO'.
      ls_fieldcat-key           = 'X'.
      ls_fieldcat-no_out        = 'X'.
      ls_fieldcat-no_sum        = 'X'.
      ls_fieldcat-sp_group      = 'A'.
      APPEND ls_fieldcat TO e01_lt_fieldcat.
      CLEAR ls_fieldcat.
      ls_fieldcat-just = 'L'.
      ls_fieldcat-fieldname     = 'MWSKZ1'.
      ls_fieldcat-seltext_l     = 'Tax code'.
      ls_fieldcat-tabname       = g_tabname_item.
      ls_fieldcat-ref_fieldname = 'MWSKZ1'.
      ls_fieldcat-ref_tabname   = 'EKPO'.
      ls_fieldcat-key           = 'X'.
      ls_fieldcat-no_out        = 'X'.
      ls_fieldcat-no_sum        = 'X'.
      ls_fieldcat-sp_group      = 'A'.
      APPEND ls_fieldcat TO e01_lt_fieldcat.
      CLEAR ls_fieldcat.
      ls_fieldcat-just          = 'L'.
      ls_fieldcat-fieldname     = 'PS_PSP_PNR'.
      ls_fieldcat-tabname       = g_tabname_item.
      ls_fieldcat-ref_fieldname = 'PS_PSP_PNR'.
      ls_fieldcat-ref_tabname   = 'EKKN'.
      ls_fieldcat-key           = 'X'.
      ls_fieldcat-no_out        = 'X'.
      ls_fieldcat-no_sum        = 'X'.
      ls_fieldcat-sp_group      = 'A'.
      APPEND ls_fieldcat TO e01_lt_fieldcat.
      CLEAR ls_fieldcat.
      ls_fieldcat-fieldname     = 'MENGE1'.
      ls_fieldcat-tabname       = g_tabname_item.
      ls_fieldcat-seltext_l     = 'Po quantity'.
      ls_fieldcat-ref_fieldname = 'MENGE1'.
      ls_fieldcat-ref_tabname   = 'EKPO'.
      ls_fieldcat-key           = 'X'.
      ls_fieldcat-no_out        = 'X'.
      ls_fieldcat-no_sum        = 'MENGE1'.
      ls_fieldcat-sp_group      = 'A'.
      APPEND ls_fieldcat TO e01_lt_fieldcat.
      CLEAR ls_fieldcat.
      ls_fieldcat-fieldname     = 'EFFWR1'.
      ls_fieldcat-tabname       = g_tabname_item.
      ls_fieldcat-seltext_l     = 'Po value'.
      ls_fieldcat-ref_fieldname = 'EFFWR1'.
      ls_fieldcat-ref_tabname   = 'EKPO'.
      ls_fieldcat-key           = 'X'.
      ls_fieldcat-no_out        = 'X'.
      ls_fieldcat-no_sum        = 'X'.
      ls_fieldcat-sp_group      = 'A'.
      APPEND ls_fieldcat TO e01_lt_fieldcat.
      CLEAR ls_fieldcat.
      ls_fieldcat-fieldname     = 'BEWTP1'.
      ls_fieldcat-tabname       = g_tabname_item.
      ls_fieldcat-seltext_l     = 'Cat'.
      ls_fieldcat-ref_fieldname = 'BEWTP1'.
      ls_fieldcat-ref_tabname   = 'EKBE'.
      ls_fieldcat-key           = 'X'.
      ls_fieldcat-no_out        = 'X'.
      ls_fieldcat-no_sum        = 'X'.
      ls_fieldcat-sp_group      = 'A'.
      APPEND ls_fieldcat TO e01_lt_fieldcat.
      CLEAR ls_fieldcat.
      ls_fieldcat-fieldname     = 'BELNR1'.
      ls_fieldcat-tabname       = g_tabname_item.
      ls_fieldcat-seltext_l     = 'GR/IR MDoc'.
      ls_fieldcat-ref_fieldname = 'BELNR1'.
      ls_fieldcat-ref_tabname   = 'EKBE'.
      ls_fieldcat-key           = 'X'.
      ls_fieldcat-no_out        = 'X'.
      ls_fieldcat-no_sum        = 'X'.
      ls_fieldcat-sp_group      = 'A'.
      APPEND ls_fieldcat TO e01_lt_fieldcat.
      CLEAR ls_fieldcat.
      ls_fieldcat-fieldname     = 'MENGE2'.
      ls_fieldcat-seltext_l     = 'GR/IR quantity'.
      ls_fieldcat-tabname       = g_tabname_item.
      ls_fieldcat-ref_fieldname = 'MENGE2'.
      ls_fieldcat-ref_tabname   = 'EKBE'.
      ls_fieldcat-key           = 'X'.
      ls_fieldcat-no_out        = 'X'.
      ls_fieldcat-no_sum        = 'X'.
      ls_fieldcat-sp_group      = 'A'.
      APPEND ls_fieldcat TO e01_lt_fieldcat.
      CLEAR ls_fieldcat.
      CLEAR ls_fieldcat.
      ls_fieldcat-fieldname     = 'MBLNR1'.
      ls_fieldcat-tabname       = g_tabname_item.
      ls_fieldcat-seltext_l     = 'GR No'.
      ls_fieldcat-ref_fieldname = 'MBLNR1'.
      ls_fieldcat-ref_tabname   = 'MKPF'.
      ls_fieldcat-key           = 'X'.
      ls_fieldcat-no_out        = 'X'.
      ls_fieldcat-no_sum        = 'X'.
      ls_fieldcat-sp_group      = 'A'.
      APPEND ls_fieldcat TO e01_lt_fieldcat.
      CLEAR ls_fieldcat.
      ls_fieldcat-fieldname     = 'BLDAT1'.
      ls_fieldcat-tabname       = g_tabname_item.
      ls_fieldcat-seltext_l     = 'GR Date'.
      ls_fieldcat-ref_fieldname = 'BLDAT1'.
      ls_fieldcat-ref_tabname   = 'MKPF'.
      ls_fieldcat-key           = 'X'.
      ls_fieldcat-no_out        = 'X'.
      ls_fieldcat-no_sum        = 'X'.
      ls_fieldcat-sp_group      = 'A'.
      APPEND ls_fieldcat TO e01_lt_fieldcat.
      CLEAR ls_fieldcat.
      ls_fieldcat-fieldname     = 'FRBNR'.
      ls_fieldcat-tabname       = g_tabname_item.
      ls_fieldcat-ref_fieldname = 'FRBNR'.
      ls_fieldcat-ref_tabname   = 'MKPF'.
      ls_fieldcat-key           = 'X'.
      ls_fieldcat-no_out        = 'X'.
      ls_fieldcat-no_sum        = 'X'.
      ls_fieldcat-sp_group      = 'A'.
      APPEND ls_fieldcat TO e01_lt_fieldcat.
      CLEAR ls_fieldcat.
      ls_fieldcat-fieldname     = 'XBLNR1'.
      ls_fieldcat-tabname       = g_tabname_item.
      ls_fieldcat-seltext_l     = 'Invoice No in GR'.
      ls_fieldcat-ref_fieldname = 'XBLNR1'.
      ls_fieldcat-ref_tabname   = 'MKPF'.
      ls_fieldcat-key           = 'X'.
      ls_fieldcat-no_out        = 'X'.
      ls_fieldcat-no_sum        = 'X'.
      ls_fieldcat-sp_group      = 'A'.
      APPEND ls_fieldcat TO e01_lt_fieldcat.
      CLEAR ls_fieldcat.
      ls_fieldcat-fieldname     = 'DMBTT'.
      ls_fieldcat-seltext_l     = 'Invoice value W/O tax'.
      ls_fieldcat-tabname       = g_tabname_item.
      ls_fieldcat-ref_fieldname = 'DMBTT'.
      ls_fieldcat-ref_tabname   = 'EKBE'.
      ls_fieldcat-key           = 'X'.
      ls_fieldcat-no_out        = 'X'.
      ls_fieldcat-no_sum        = 'X'.
      ls_fieldcat-sp_group      = 'A'.
      APPEND ls_fieldcat TO e01_lt_fieldcat.
    ENDFORM.                    " f_e01_fieldcat_init
    *&      Form  f_selection
          text
    FORM f_selection .
      SELECT   ekko~ebeln
               ekko~lifnr
               ekko~aedat
               ekko~submi
               lfa1~name1
               erev~netwr
                               FROM ekko  INNER JOIN lfa1 ON ( ekkolifnr = lfa1lifnr )
                                          INNER JOIN erev ON ( ekkoebeln = erevedokn )
                                          INTO TABLE itab WHERE ekko~ebeln IN ebeln AND
                                                                ekko~aedat IN aedat AND
                                                                bsart <> 'AN'.
      SELECT
             ekpo~ebeln
             ekpo~ebelp
             ekpo~aedat
             ekpo~txz01
             ekpo~menge
             ekbe~menge
             ekpo~effwr
             ekpo~mwskz
             ekkn~ps_psp_pnr
             ekbe~bewtp
             ekbe~belnr
             ekbe~dmbtr
             mkpf~mblnr
             mkpf~bldat
             mkpf~xblnr
             mkpf~frbnr
                            FROM  ekpo INNER JOIN ekkn      ON ( ekpoebeln = ekknebeln
                                                                           AND
                                                                 ekknebelp = ekpoebelp )
                                       INNER JOIN ekbe      ON ( ekknebeln = ekbeebeln
                                                                           AND
                                                                 ekknebelp = ekbeebelp )
                                       LEFT OUTER JOIN mkpf ON ( ekbebelnr = mkpfmblnr )
                                       INTO TABLE jtab FOR ALL ENTRIES IN itab WHERE ekpo~ebeln = itab-ebeln AND
                                                                                    ekpo~aedat = itab-aedat.
    ENDFORM.                    " f_selection
    *&      Form  f_display
          text
    FORM f_display .
      CALL FUNCTION 'REUSE_ALV_HIERSEQ_LIST_DISPLAY'
        EXPORTING
          i_callback_program = g_repid
          it_fieldcat        = gt_fieldcat[]
          i_tabname_header   = g_tabname_header
          i_tabname_item     = g_tabname_item
          is_keyinfo         = gs_keyinfo
          is_layout          = ls_layout
        TABLES
          t_outtab_header    = itab
          t_outtab_item      = jtab.
    ENDFORM.                    " f_display

    Hi Ravi,
    1. To check performance of a report we use the perfromance trace. The transaction code is ST05.
    You can also refer the link :
         http://help.sap.com/saphelp_erp2005/helpdata/en/8a/3b834014d26f1de10000000a1550b0/content.htm
    2.  Also we can do the run time analysis of the code uising transaction code SE30.
    3. To do a general check on the code , you can use the SAP Code Inspector. The transaction code for this is SCI. This will defentely give you a detailed analysis of the program.
    4 . To have a general idea about the performance tuning of a report , you should refer the link :
       http://www.sapgenie.com/abap/performance.htm.
    Hope this solves yopur query.
    Regards,
    Kunal.

  • Avoiding inner joins????

    Hi all,
    I was just thinking of ways to improve the perfomance of my report. Its fetching data in to two different tables using two innerjoins and these two internal tables are again looped for some other manipulation. Can anyone tell me the ways i can avoid innerjoin or is there other ways to improve psrfomance by avoiding innejoins in general?
    Rakesh

    hi sir i was able to find out that
    Using several nested INNER JOIN statements can be inefficient and cause time out if the tables become too big in the future."
    Joins here (in ABAP) are not those Native SQL Joins.  If you are talking about the Core RDBMS, which mean Oracle or SQL Server, then Undoubtedly Joins are the best.
    In ABAP, these joins are first split by the ABAP processor and then sent to the database, with the increase in DATA in production system, these joins tend to give way if your database keeps growing larger and larger.
    You should rather used "FOR ALL ENTRIES IN" (Tabular conditions), which is a much effecient way as far as performance is concerned.
    For example :
    DATA: BEGIN OF LINE,
            CARRID   TYPE SPFLI-CARRID,
            CONNID   TYPE SPFLI-CONNID,
            CITYFROM TYPE SPFLI-CITYFROM,
            CITYTO   TYPE SPFLI-CITYTO,
          END OF LINE,
          ITAB LIKE TABLE OF LINE.
    LINE-CITYFROM = 'FRANKFURT'.
    LINE-CITYTO   = 'BERLIN'.
    APPEND LINE TO ITAB.
    LINE-CITYFROM = 'NEW YORK'.
    LINE-CITYTO   = 'SAN FRANCISCO'.
    APPEND LINE TO ITAB.
    SELECT CARRID CONNID CITYFROM CITYTO
    INTO   CORRESPONDING FIELDS OF LINE
    FROM   SPFLI
    FOR ALL ENTRIES IN ITAB
    WHERE  CITYFROM = ITAB-CITYFROM AND CITYTO = ITAB-CITYTO.
      WRITE: / LINE-CARRID, LINE-CONNID, LINE-CITYFROM, LINE-CITYTO.
    ENDSELECT.
    Do you have a ABAP Question?
    Best regards,
    SAP Basis, ABAP Programming and Other IMG Stuff

  • Inner Joins vs For All Entries - performance query

    Hi All,
    I'm a bit confused here...  I see lots and lots (and lots...) of postings from people asking how to get data from multiple tables.
    To me the immediate answer is to use joins in my select statement to reduce the database load but more and more I see people suggesting FOR ALL ENTRIES is better from a performance perspective.
    Now, simple question time, which is more efficient in the real world when doing something like the following:- (this is a basic example but I'm sure you know what I mean.)
    Select  *
      into  table lt_sales_data
      from  vbap as vbap
    inner  join vbak as vbak
         on vbak~vbeln eq vbap~vbeln
      where  vbak~vbeln in so_vbeln.
    or
    Select  *
      into  table lt_vbak_data
      from  vbak
    where  vbeln in so_vbeln.
    if lt_vbak_data[] is not initial.
    select  *
      into  table lt_vbap_data
      from  vbap
      for all entries in lt_vbak_data
    where  vbeln eq lt_vbak_data-vbeln.
    endif.
    Basically I want to know whether joins or for all entries is better from a database performance perspective.
    I want to know why as well so please don't just post links, random cut and paste answers or one liners.  I'm convinced for all entries is slower but am willing to be persuaded otherwise if someone can show me proof.
    Thanks,
    Gareth.

    Thanks to all the opinions so far...  You've backed up what I suspected although I maybe wasn't clear enough with my question and desired result.  I was hoping someone could produce some hard and fast guidelines from SAP themselves dictating which is the better method.  I know 10 years ago I was taught to use joins and to keep my database access to minimal levels, using keyed reads where applicable and using internal tables to filter data where I couldn't use key fields.
    Gautham, I am aware of SM30 but that doesn't answer the general question I was asking.  I've obviously used SM30 to run some comparisons but I was really hoping someone could give me a definitive answer based on hard facts or from attending some training at SAP recently.  And no points for asking for them
    Tamás, I agree with what you are saying about runing many comparisons - it appears to be dependant on any number of criteria which means each case may require different code.  I've not managed to find a consistent comparison of the two methods that would lead me to use one method or the other...
    Karan, thanks for your feelings but it doesn't really help me!  Why/how does it retrieve the data faster than a join?  Have you got testing/proof to back this up?
    Raam, thanks for those links - they are interesting reads and seem to go through the same arguments I'm currently considering.  Although I still don't have a definitie answer!
    Amit, I understand exactly what yuo are saying about myths and urban legends   That was my motivation for this post.  To bo honest, it seems to me that a lot of the "newer" ABAP coders always go for FOR ALL ENTRIES but I wanted to know - is there a reason or do they all just cut and paste off SDN?!  Are they all just scared of complex inner joins?!  What would you all make of this Select statement for example? -   
    select  afvc~arbid
                afko~aufnr
                aufk~objnr
                afko~plnnr
                afko~plnal
                afko~aufpl
                afko~zaehl
                afpo~matnr
                makt~maktx
                afvc~vornr
                afvc~ltxa1
                afvu~aplzl
                afvu~usr10
                afvv~meinh
                afvv~bmsch
                afvv~vge02
                afvv~vgw02
                afvv~mgvrg
                afab~aplzl_vor
          into  table lt_recipe_orders
          from  afko as afko
         inner  join aufk as aufk
            on  aufk~aufnr eq afko~aufnr
         inner  join afpo as afpo
            on  afpo~aufnr eq afko~aufnr
         inner  join makt as makt
            on  makt~matnr eq afpo~matnr
         inner  join afvc as afvc
            on  afvc~aufpl eq afko~aufpl
         inner  join afvu as afvu
            on  afvu~aufpl eq afvc~aufpl
           and  afvu~aplzl eq afvc~aplzl
         inner  join afvv as afvv
            on  afvv~aufpl eq afvu~aufpl
           and  afvv~aplzl eq afvu~aplzl
          left  outer join afab as afab
            on  afab~aufpl_nch eq afvu~aufpl
           and  afab~aplzl_nch eq afvu~aplzl
           for  all entries in t_resources
         where  afko~gltrs ge v_start_date
           and  afko~gstrs le v_start_date
           and  afko~plnty eq gc_task_list_type_2
           and  afpo~dwerk eq v_werks
           and  makt~spras eq sy-langu
           and  afvc~arbid eq t_resources-objid.
    Twinkal, I've always thought less DB hits is a better performing program too - the above example compares 2 db hits to 1...  I don't have issues with complex joins because I've used them so long so can discount that problem but do agree that less DB hits is the ultimate goal.  Providing of course the Selects you write are actually efficient in themselves.
    Murthy, if you build your select statement correctly duplicate records can be avoided in most cases.  How can you say a join statement will hit the database more when in my example there is 1 DB hit compared to 2 for a for all entries?  And I'd love to know the reasoning behind never using a join on more than 2 tables?!  Is that just an urban myth?!
    Thomas, I've just been looking at some of Siegfried's posts and like what I am reading.  As you say, using full keys via joins is essential.
    Gareth.

  • 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.

  • For All Entries is NOT better than INNER JOIN in most cases

    I quote from Siegfried Boes' excellent post here: Will writing an inner join be better or creating a view?
    For all the FOR ALL ENTRIES lovers ... there is no proof for these reappearing recommendation.
    There is nearly nobody who receives forum points, who recommends FOR ALL ENTRIES instead of Joins. What is the reason ???
    It is easier to prove the opposite. A Join is a nested loop inside the database, a FOR ALL ENTRIES is partly outside of the database. FOR ALL ENTRIES works in blocks, joins on totals.
    FOR ALL ENTRIES are not recommded on really large tables, because the chances are too high that
    too many records are transferred.
    People prefer FOR ALL ENTRIES, because JOINs are not so easy to understand. Joins can go wrong, but with a bit of understanding they can be fixed.
    Some Joins are slow and can not be fixed, but then the FOR ALL ENTRIES would be extremely slow.
    There are several kinds of views:
    - projection views, i.e. only one table involved just fields reduced
    - join views, several tables, joins conditions stored in dictionary
    - materialized views, here the joined data are actually stored in the database. Storing and synchronisation has to be done manually.
    Only the last one creates real overhead. It should be the exception.
    Join Views and Joins are nearly identical. The view is better for reuse. The join is better in complicated, becuase if the access goes wrong, it can often be fixed by adding a hint. Hints can not be added to views.
    Abraham Bukit  points out:
    If it is cluster table, (you can't use join). If it is buffered table, I would also say avoid join.
    If they all are transaction table which are not buffered and are not cluster tables.  
    He further supports Siegfried's statement that FAE is easier to undestand than INNER JOINs.
    Thomas Zloch says, regarding buffered tables:
    At least think twice, maybe compare runtimes if in doubt. 
    So, unless someone has some EVIDENCE that FOR ALL ENTRIES is better, I don't think we want to see this discussed further.
    Kind regards
    Matt

    To give food for thought here's an example I  gave in a thread:
    If you have a statement like
    SELECT ... FOR ALL ENTRIES IN FAE_itab WHERE f = FAE_itab-f.
    SAP sends it to the database depending how the parameter rsdb/prefer_union_all is set:
    rsdb/prefer_union_all = 0 =>
    SELECT ... WHERE f = FAE_itab[1]-f
              OR    f = FAE_itab[2]-f
              OR    f = FAE_itab[N]-f
    You have some influence  of the generated statement type: Instead of OR'ed fields an IN list can be used
    if you have only a single coulmn N to compare:
    rsdb/prefer_in_itab_opt parameter:
    SELECT ... WHERE f IN (itab[1]-f, itab[2]-f, ..., itab[N]-f)
    rsdb/prefer_union_all = 1 =>
    SELECT ... WHERE f = FAE_itab[1]-f
    UNION ALL SELECT ... WHERE f = FAE_itab[2]-f
    UNION ALL SELECT ... WHERE f = FAE_itab[N]-f
    see: Note 48230 - Parameters for the SELECT ... FOR ALL ENTRIES statement
    As you can see for the 2nd parameter several statements are generated and combined with a UNION ALL,
    the first setting generates statements with OR's (or uses IN  if possible) for the entries in FAE_itab.
    I give you a little example here (my parameters are set in a way that the OR's are translated to IN lists; i traced the execution in ST05)
    Select myid into table t_tabcount from mydbtable
      for all entries in t_table    " 484 entries
        where myid = t_table-myid .
    ST05 trace:
    |Transaction SEU_INT|Work process no 0|Proc.type  DIA|Client  200|User |
    |Duration |Obj. name |Op.    |Recs.|RC    |Statement|
    | 640|mydbtable |PREPARE|   |  0|SELECT WHERE "myid" IN ( :A0 , :A1 , :A2 , :A3 , :A4 ) AND "myid" = :A5|
    | 2|mydbtable |OPEN   |   |  0|SELECT WHERE "myid" IN ( 1 , 2 , 3 , 4 , 5 ) AND "myid" = 72 |
    | 2.536|mydbtable |FETCH  |    0|  1403|   |
    | 3|mydbtable |REOPEN |   |  0|SELECT WHERE "myid" IN ( 6 , 7 , 8 , 9 , 10 ) AND "myid" = 72 |
    | 118|mydbtable |FETCH  |  0|  |
    | 2|mydbtable |REOPEN |  |  0|SELECT WHERE "myid" IN ( 11 , 12 , 13 , 14 , 15 ) AND "myid" = 72     |
    | 3|mydbtable |REOPEN |  |  0|SELECT WHERE "myid" IN ( 475 , 476 , 477 , 478 , 479 ) AND "myid" = 72  |
    | 94|mydbtable |FETCH  | 0| 1403|   |
    | 2|mydbtable |REOPEN |   |  0|SELECT WHERE "myid" IN ( 480 , 481 , 482 , 483 , 484 ) AND "myid" = 72 |
    You see the IN list contained 5 entries each , wich made up about 97 statements for all 484 entries.
    For every statment you have a single fetch operation wich means a separate access to the database.
    If you would replace the FAE with a join you would only have one fetch to the database.
    With the example above we can derive these observations:
    1. From database point of view these settings kill performance when you access a big table and/or have a lot of entries or columns in your FAE_itab. Furthermore, you hide information what data you will access
    at all and thus you block the database from creating a more efficient execution plan because it DOESN'T KNOW wich data you will select in the next step. I.e. it may be more efficient to scan the table in one shot instead of having many index accesses - but the database can make this decision only if it can examine ONE statement that has ALL the information of what data to retrieve.
    2. A second impact is that with every statement execution you trigger the allocation of database resources
    wich will contribute to the overhead described above.
    Said that, FAE  can never be a replacement for joining big tables (think of having a table with thousands of records in a FAE table )
    Edited by: kishan P on Nov 2, 2010 2:16 PM - Format Fixed

  • Help with Inner Join query in SQL

    Hope someone can help with this, as this is quite an involved project for me, and I'm just about there with it.
    My table structure is :
    table_packages
    packageID
    package
    packageDetails
    etc
    table_destinations
    destinationID
    destination
    destinationDetails
    etc
    table_packagedestinations
    packageID
    destinationID
    ..so nothing that complicated.
    So the idea is that I can have a package details page which shows the details of the package, along any destinations linked to that package via the packagedestinations table.
    So this is the last part really - to get the page to display the destinations, but I'm missing something along the way....
    This is the PHP from the header, including my INNER JOIN query....
    PHP Code:
    <?php
    $ParampackageID_WADApackages = "-1";
    if (isset($_GET['packageID'])) {
      $ParampackageID_WADApackages = (get_magic_quotes_gpc()) ? $_GET['packageID'] : addslashes($_GET['packageID']);
    $ParamSessionpackageID_WADApackages = "-1";
    if (isset($_SESSION['WADA_Insert_packages'])) {
      $ParamSessionpackageID_WADApackages = (get_magic_quotes_gpc()) ? $_SESSION['WADA_Insert_packages'] : addslashes($_SESSION['WADA_Insert_packages']);
    $ParampackageID2_WADApackages = "-1";
    if (isset($_GET['packageID'])) {
      $ParampackageID2_WADApackages = (get_magic_quotes_gpc()) ? $_GET['packageID'] : addslashes($_GET['packageID']);
    mysql_select_db($database_connPackages, $connPackages);
    $query_WADApackages = sprintf("SELECT packageID, package, costperpax, duration, baselocation, category, dateadded, agerange, hotel, educational_tours, field_trips, corporate_outings, plant_visits, budget_package, rollingtours, teambuilding, description, offer FROM packages WHERE packageID = %s OR ( -1= %s AND packageID= %s)", GetSQLValueString($ParampackageID_WADApackages, "int"),GetSQLValueString($ParampackageID2_WADApackages, "int"),GetSQLValueString($ParamSessionpackageID_WADApackages, "int"));
    $WADApackages = mysql_query($query_WADApackages, $connPackages) or die(mysql_error());
    $row_WADApackages = mysql_fetch_assoc($WADApackages);
    $totalRows_WADApackages = mysql_num_rows($WADApackages);
    $colname_educationalDestinations = "1";
    if (isset($_GET['PackageID'])) {
      $colname_educationalDestinations = (get_magic_quotes_gpc()) ? packageID : addslashes(packageID);
    mysql_select_db($database_connPackages, $connPackages);
    $query_educationalDestinations = sprintf("SELECT * FROM destinations INNER JOIN (packages INNER JOIN packagedestinations ON packages.packageID = packagedestinations.packageID) ON destinations.destinationID = packagedestinations.destinationID WHERE packages.packageID = %s ORDER BY destination ASC", GetSQLValueString($colname_educationalDestinations, "int"));
    $educationalDestinations = mysql_query($query_educationalDestinations, $connPackages) or die(mysql_error());
    $row_educationalDestinations = mysql_fetch_assoc($educationalDestinations);
    $totalRows_educationalDestinations = mysql_num_rows($educationalDestinations);
    ?>
    And where I'm trying to display the destinations themselves, I have : 
    <table>
            <tr>
                     <td>Destinations :</td>
                </tr>
               <?php do { ?>
            <tr>
                 <td><?php echo $row_educationalDestinations['destination']; ?></td>
            </tr>
            <?php } while ($row_educationalDestinations = mysql_fetch_assoc($educationalDestinations)); ?>
    </table>
    If anyone could have a quick look and help me out that would be much appreciated - not sure if its my SQL at the top, or the PHP in the page, but either way it would be good to get it working. 
    Thanks.

    First off, you need to get the database tables so that there is a relationship between them.
    In fact, if there is a one to one relationship, then it may be better to store all of your information in one table such as
    table_packages
    packageID
    package
    packageDetails
    destination
    destinationDetails
    etc
    If there is a one to many relationship, then the following would be true
    packages
    packageID
    package
    packageDetails
    etc
    destinations
    destinationID
    packageID
    destination
    destinationDetails
    etc
    The above assumes that there are many destinations to one package with the relationship coloured orange.
    Once you have the above correct you can apply your query as follows
    SELECT *
    FROM packages
    INNER JOIN destinations
    ON packages.packageID = destinations.packageID
    WHERE packages.packageID = %s
    ORDER BY destination ASC
    The above query will show all packages with relevant destinations

  • Select SUM( ) in inner join - error in code

    Hi All,
    The following code is using ABAP OO and I get the following error
    E:The addition "FOR ALL ENTRIES" excludes all aggregate functions with
    the exception of "COUNT( * )", as the single element of the SELECT
    clause.
    Here is the Code:
    select a/bic/ZEDM_ENTP amaterial a~/bic/zedm_stid
    a/bic/ZEDM_SDT a/bic/ZEDM_MINH a~/bic/ZEDM_EHD
    SUM( b~/bic/ZEDM_QPLN )
    c~/bic/ZDEMQTY
    from /bic/azdrp_1900 as a inner join /bic/azdrp_0400 as b
    on
    a/bic/ZEDM_ENTP = b/bic/ZEDM_ENTP and
    amaterial = bmaterial and
    a/bic/zedm_stid = bplant and
    a/bic/ZEDM_SDT = b/bic/zedm_pshp
    inner join /bic/azrp_0800 as C
    on
    amaterial = cmaterial and
    a/bic/zedm_stid = c/bic/zedm_stid and
    a/bic/ZEDM_SDT = c/bic/ZEDM_ESDT
    into table z_it_inv for all entries in
    RESULT_PACKAGE where
    a~/bic/ZEDM_ENTP = RESULT_PACKAGE-/bic/ZEDM_ENTP
    and a~material = RESULT_PACKAGE-material
    and a~/bic/ZEDM_SDT = RESULT_PACKAGE-/BIC/OIZEDM_EDT
    and a~/bic/zedm_stid = RESULT_PACKAGE-/BIC/OIZEDM_TOST
    group by b/bic/ZEDM_ENTP bmaterial b~plant
    b~/bic/zedm_pshp
    Can you please tell me how to correct this?
    Thanks

    Hi,
    You can get all records first and then LOOP AT Internal table and use COLLECT statement to sum up required column.
    This will be a better idea than trying to use SUM in SELECT with JOINS.
    ashish

Maybe you are looking for

  • Accordion Tab without  Submenu

    Hello, my Problem: I need a menu with and without submenu. Exapmle: (just a example) Button "Home" without submenu, but "company" there are 2 submenus: "about" and "where to buy" Now i make a new accordion menu and the first ("Home") button have to w

  • Windows 8.1 Audio

    Since upgrading too windows 8.1  window media player keeps cutting in and out  never happened be the update .........any advice would be appriated

  • BUG in visual studio 13

    shit visual Studio destroyed my hole c Project  it was so big and nearly everything got deleted you shit loads better repeair your shit , i couldnt even submit a bug Report so i write this here ,,, i can tell you Change your IDE immediatly , i wont t

  • Extraction through master data attribute not working

    Hi All, In my ODS, i have a field Sales Document Item, with attributes ship-to-party, sold-to-party, etc. Now, ship-to-party and sold-to-party are extracted using the update method master data attribute of Sales Document Item. For some of the Items,

  • Opening files using their associatons

    Hi, My program is a FileBrowser and i display in a jTable the contents of folders (files and directories). I want to double-click to files and open them with the program the O.S. uses to open it. How can i do this? note: I am interested in both Unix