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.

Similar Messages

  • 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

  • Data Federator not fetching data USING Netweaver BI Connector

    Hi Gurus,
    We have upgraded the BW system to use the Data federator.
    callback ID that SAP NetWeaver BI uses to contact Data Federator has been configured as mentioned in guide.
    we have already configured the CONNECTOR and we are able to test the connection in DF Designer and the connection is successful. i am able to see the list of fact tables and i am saving the data source and making it final and deployying my project .
    i am using the jdbc connection and  data federator strategy and  the strategy is also creating the joins and classed automatically. when i export my universe and try to create the webintelligence report i am unable to see the data .even when i execute with one  object  and one keyfigure it is same .
    even when i test my data source in designer to view the data using query tester tool it is also not able show the data it takes huge time and no data getting retrieved .
    i would appreciate if you could help me with this issue
    Regards and thanks
    Abid

    Hi,
    Which version of Data Federator are you using ? Direct access to ECC table is not yet supported using Data Federator.
    Jean-Pierre

  • Sales and Billing data is not fetching in case of STO

    Hi
    We have  tables VBAK and VBAP - sale oder 
                                    VBRK and VBRP - Billing data
    Now problem is that I want to make a BW datasource in ECC in which i create view from which we need to populate data for order and billing together but we are facing problem in case of STO where billing doc canu2019t be create against with Sale order doc
    Suppose, If I create a view from which all record regarding order and Billing are coming from table VBAK,VBAP,VBRK and VBAP then we have got record  but in case of STO where billing doc canu2019t be created with against of Sale order then we have failed to find the record against sales doc because view fetch data depend upon intersection functionality.
    We need sales data in case of STO also. please give the helpful for the same.
    Thanks & Regards,
    Gourav Sekhri

    Hi Krishanan
    I am facing the same problem which have been mentioned by you (i am not getting sales doc data for normal sales orders if billing document is not yet created, which might not be desirable in my scenario).
    I have also created generic extractor based on view(all data only for sales order) and also creating append structure for all field based on billing data.
    but now i am facing the problem in which i need to take VBRK table data based on sales doc but in VBRK table sale doc is not defined.
    kindly look into the matter and give the helpful reply.
    Thanks & Regards,
    Gourav Sekhri

  • Replacing a inner join with for all entries

    Hi Team,
       In a already developed program I am replacing a inner join with select query follow up with for-all-entris and passing the data to final internal table but in both the case the result should be same then only my replacement will be correct. But my no records in both cases differs. This happening because when i am selecting data from first data base table is 32 lines. then I am doing fo-all-entries moving all the duplicate entries then the no records are four. but in final internal table i am looping the first internal table. So in final internal table the no of records are 32. But in inner join query the records are 16.So please let me know how resolve this issue?
    Thanks and REgards
    Deepa

    Hi Thomas,
      Thanks for ur suggestion.
    The solved that in below.
    In select query I did not change anything The way I had written the code was correct.
    I think many of us know how to write that how to make the performance better in that way.
    I made the change when I transfered the to final internal table.
    The original Inner join code:
    select a~field1 a~field2 a~field3 b~field2 b~field3 b~field4
               from dbtab1 as a  inner join dbtab2 as b
              on a~field1 = b~field1 into it_final where
              a~field1 in s_field1. [Field1  in both the table are key field]
    Before code:
    Sort itab1 by key-fields.
    sort itab2 by keyfields.
    loop at itab1 into wa1.
    move: wa1-field1 to wa_final-field1,
               wa1-field2 to wa_final-field2,
               wa1-field3 to wa_final-field3.
    read table itab2 into wa2 witk key field1 = wa1-field1 binary search.
      if sy-subrc = 0.
      move : wa2-field2 to wa_final-field4,
                 wa2-field3 to wa_final-field5,
                 wa2-field4 to wa_final-field6.
    append wa_final to it_final.
    endif.
    Clear : wa1, wa2, wa_final.
    endloop.
    In this case if the one key fieild value is not present there in second internal table but its there in first internal table still it will read that row with 2nd internal values having zeroes. Normally what does not happen in inner join case if the key field value will same in both the case ,then that will fetch only those rows.
    Changed Code
    loop at itab1 into wa1.
    read table itab2 into wa2 witk key field1 = wa1-field1 binary search.
      if sy-subrc = 0.
    move: wa1-field1 to wa_final-field1,
               wa1-field2 to wa_final-field2,
               wa1-field3 to wa_final-field3.
      move : wa2-field2 to wa_final-field4,
                 wa2-field3 to wa_final-field5,
                 wa2-field4 to wa_final-field6.
    append wa_final to it_final.
    endif.
    Clear : wa1, wa2, wa_final.
    endloop.
    In this case the values will read to final internal table if both key field matches.
    With Regards
    Deepa

  • Inner join query

    Hi all,
    I want to query a inner join via some tools in sap GUI. till now, i could not query a inner join between two tables via SE11. can someone tell are there some other ways to achieve this?
    any response will be awarded!
    thanks and regards,
    samson

    hi samson,
    Proper use of Inner Join
    When multiple SAP tables are logically joined, it is always advisable to use inner join to read the data from them. This certainly reduces the load on the network.
    Let us take an example of 2 tables, zairln and zflight. The table zairln has the field airln, which is the airline code and the field lnnam, which is the name of the airline. The table zflight has the field airln, the airline code and other fields which hold the details of the flights that an airline operates.
    Since these 2 tables a re logically joined by the airln field, it is advisable to use the inner join.
                 Select aairln alnnam bfligh bcntry into table int_airdet
    example 2:--
    Inner join: If you have common fields between 2 or more tables, its betterto use Inner join.
    Check the below example:
    VBAK & VBAP table has common fields, hence we can use inner join.
    SELECT akunnr avbeln anetwr abnddt a~knumv
    avkbur aerdat avdatu aaugru
    aktext bmatnr barktx bkwmeng b~kzwi6
    bvolum bposnr b~kdmat
    INTO CORRESPONDING FIELDS OF TABLE g_t_quot
    FROM vbak AS a INNER JOIN vbap AS b
    ON avbeln = bvbeln
    WHERE a~vbeln IN so_vbeln
    AND a~trvog ='2'
    AND a~vkorg IN so_vkorg
    AND a~vtweg IN so_vtweg
    AND a~vkbur IN so_vkbur
    AND a~audat IN so_audat
    AND a~kunnr IN so_kunag.
    FOR ALL ENTRIES:
    If you get some data into one internal table and if you want to fetch data from other table based on it, use FOR ALL ENTRIES.
    g_t_quot is an internal table.
    SELECT spras augru bezei FROM tvaut INTO TABLE g_t_tvaut
    FOR ALL ENTRIES IN g_t_quot
    WHERE augru = g_t_quot-augru AND spras = sy-langu.
                From zairln as a inner join zflight as b on aairln = bairln.
    In order to restrict the data as per the selection criteria, a where clause can be added to the above inner join.

  • 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

  • Short Dump on Inner Join

    Hello Experts,
    I'm trying to write a Inner join on VBAK and VBAP because i need to get data from both tables.  When I try to execute the following code I'm getting a short dump "Error in module RSQL of the database Interface". Can anybody see what's wrong with this select.
           begin of t_sales_order,
             vbeln  type vbak-vbeln,    "Sales Order
             auart  type vbak-auart,     "Order Type
             audat  type vbak-audat,     "Shipment Creation date field
             posnr  type vbap-posnr,    "Items
             kdmat  type vbap-matnr,    "Lead Pin
             cuobj  type vbap-cuobj,    "Configuration Object ID
             end of t_sales_order,
    data: lwa_sales_order           type t_Sales_Order.
          select single avbeln aaudat a~auart
                        bposnr bkdmat b~cuobj
                          into lwa_sales_order
                             from vbak as a inner join vbap as b
                                  on avbeln = bvbeln
                                     where b~kdmat = pv_pin_number.
    Many thanks in advance.

    Hi
    Your internal table fields sequences are not followed in Inner Join.
    begin of t_sales_order,
    vbeln type vbak-vbeln, "Sales Order
    auart type vbak-auart, "Order Type
    audat type vbak-audat, "Shipment Creation date field
    posnr type vbap-posnr, "Items
    kdmat type vbap-matnr, "Lead Pin
    cuobj type vbap-cuobj, "Configuration Object ID
    end of t_sales_order,
    select single a~vbeln *a~auart* a~audat
    b~posnr b~kdmat b~cuobj
    into lwa_sales_order
    from vbak as a inner join vbap as b
    on a~vbeln = b~vbeln
    where b~kdmat = pv_pin_number.
    Please check the above code
    Shiva

  • Dynamic table name in an inner join - select statement

    Hi,
    Please can you let me know if is possible to use a Dynamic table name in an inner join?
    Something like the statement below? (It works in a simple select statement but not in an inner join)
    SELECT  *
         INTO CORRESPONDING FIELDS OF <t_itab>
          FROM <Dynamic table name> INNER JOIN pa0050 ON
          ( <Dynamic table name>pernr =  pa0050pernr )
           WHERE <Dynamic table name>~pernr = it_pernr-l_pernr
           AND pa0050~bdegr = f_bdegr.
    Any help would be apprecited very much.
    Thanks & Regards.

    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

  • Using MAX on an INNER JOIN

    Is there any way to use MAX on an INNER JOIN???
    I am getting the MAX Date row on a previous INNER JOIN and then I want to use that result row to get an Account Balance. I know it's hard to explain without the SQL but I'll try...
    So I want the MAX(BILLHDR.dt_bill)'s Account Balance...
    SELECT PYMTADJ.ky_payment_adjustment,
    PYMTADJ.ky_enroll,
    PYMTADJ.dt_payment_adjustment,
    PYMTADJ.at_payment_adjustment,
    MAX(BILLHDR.dt_bill) Last_Bill_Date,
    MAX(BILLHDR.dt_reading_from) "Last Bill Period From Date",
    MAX(BILLHDR.dt_reading_to) "Last Bill Period To Date",
    BILLHDR2.at_bill_account_balance
    FROM PVIEW.PAYMENT_ADJUSTMENT PYMTADJ
    LEFT OUTER JOIN PVIEW.BILL_HDR BILLHDR
    ON PYMTADJ.ky_enroll = BILLHDR.ky_enroll
    AND BILLHDR.dt_bill <= '15-Jun-2009'
    INNER JOIN PVIEW.BILL_HDR BILLHDR2
    ON BILLHDR.ky_enroll = BILLHDR2.ky_enroll
    AND MAX(BILLHDR.dt_bill) = BILLHDR2.dt_bill
    Any help would be GREATLY appreciated.
    Thanks.
    PSULionRP

    [email protected] wrote:
    But now the next riddle is this. I have another table I have to query against using those MAX Dates. Is there any way to use those MAX Dates as my Join criteria for another table???Sure, it is called in-line view:
    SELECT whatever-you-need
      FROM (
    SELECT   pymtadj.ky_payment_adjustment, pymtadj.ky_enroll,
             pymtadj.dt_payment_adjustment, pymtadj.at_payment_adjustment,
             MAX (billhdr.dt_bill) last_bill_date,
             MAX (billhdr.dt_reading_from) "Last Bill Period From Date",
             MAX (billhdr.dt_reading_to) "Last Bill Period To Date",
             MAX (billhdr2.at_bill_account_balance)KEEP (DENSE_RANK FIRST ORDER BY billhdr.dt_bill DESC) some_alis
        FROM pview.payment_adjustment pymtadj LEFT OUTER JOIN pview.bill_hdr billhdr
             ON pymtadj.ky_enroll = billhdr.ky_enroll
           AND billhdr.dt_bill <= TO_DATE ('15-Jun-2009', 'DD-Mon-YYYY')
             LEFT OUTER JOIN pview.bill_hdr billhdr2
             ON billhdr.ky_enroll = billhdr2.ky_enroll
    GROUP BY pymtadj.ky_payment_adjustment,
             pymtadj.ky_enroll,
             pymtadj.dt_payment_adjustment,
             pymtadj.at_payment_adjustment
    ) inline_view JOIN another_table ON(inline_view."Last Bill Period From Date" = another_table.some_column1)SY.

  • Performance difference between left outer join / inner join

    Hi,
    I've got a complex query which among other things accesses quite a large table. If I use inner join to join this table, the response is quite fast and execution plan shows it uses nested loops to gather the data.
    If I change inner join to left outer join, I get a big performance drop. Cost of query goes from 1441 to 28544.
    I don't uderstand why there's such a difference. For inner join, database has to remove all the rows that don't have match in inner-joined table. For left join it can keep all records and just return NULL values for records that don't have a match. In my mind left join should be faster, as it seems simpler. And the access plan could be the same, couldn't it?
    Execution plan for inner join:
    | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
    | 0 | SELECT STATEMENT | | 1 | 288 | 1441 (1)| 00:00:18 |
    | 1 | HASH GROUP BY | | 1 | 288 | 1441 (1)| 00:00:18 |
    | 2 | NESTED LOOPS OUTER | | 1 | 288 | 1440 (1)| 00:00:18 |
    | 3 | NESTED LOOPS | | 1 | 261 | 1438 (1)| 00:00:18 |
    | 4 | NESTED LOOPS | | 318 | 74412 | 508 (1)| 00:00:07 |
    | 5 | NESTED LOOPS | | 318 | 51834 | 189 (0)| 00:00:03 |
    | 6 | TABLE ACCESS BY INDEX ROWID| RESURCE | 1 | 106 | 1 (0)| 00:00:01 |
    |* 7 | INDEX UNIQUE SCAN | RESURCE_PRINCIPAL_NAME_INDEX | 1 | | 0 (0)| 00:00:01 |
    | 8 | TABLE ACCESS BY INDEX ROWID| TASK_USES_RESURCE | 318 | 18126 | 188 (0)| 00:00:03 |
    |* 9 | INDEX RANGE SCAN | TASK_USES_RESUR_IDX$$_0CDC0002 | 318 | | 3 (0)| 00:00:01 |
    | 10 | TABLE ACCESS BY INDEX ROWID | TASK | 1 | 71 | 1 (0)| 00:00:01 |
    |* 11 | INDEX UNIQUE SCAN | TASK_PK | 1 | | 0 (0)| 00:00:01 |
    | 12 | TABLE ACCESS BY INDEX ROWID | TASK_WORK_HISTORY | 1 | 27 | 3 (0)| 00:00:01 |
    |* 13 | INDEX RANGE SCAN | TASK_WORK_HISTORY_INDEX1 | 1 | | 2 (0)| 00:00:01 |
    | 14 | TABLE ACCESS BY INDEX ROWID | TASK_USES_RESURCE | 1 | 27 | 2 (0)| 00:00:01 |
    |* 15 | INDEX UNIQUE SCAN | TASK_USES_RESURCE_UK1 | 1 | | 1 (0)| 00:00:01 |
    For left outer join:
    | Id | Operation | Name | Rows | Bytes |TempSpc| Cost (%CPU)| Time |
    | 0 | SELECT STATEMENT | | 318 | 1596K| | 28544 (2)| 00:05:43 |
    |* 1 | HASH JOIN OUTER | | 318 | 1596K| 1584K| 28544 (2)| 00:05:43 |
    | 2 | VIEW | | 318 | 1580K| | 508 (1)| 00:00:07 |
    | 3 | NESTED LOOPS | | 318 | 74412 | | 508 (1)| 00:00:07 |
    | 4 | NESTED LOOPS | | 318 | 51834 | | 189 (0)| 00:00:03 |
    | 5 | TABLE ACCESS BY INDEX ROWID| RESURCE | 1 | 106 | | 1 (0)| 00:00:01 |
    |* 6 | INDEX UNIQUE SCAN | RESURCE_PRINCIPAL_NAME_INDEX | 1 | | | 0 (0)| 00:00:01 |
    | 7 | TABLE ACCESS BY INDEX ROWID| TASK_USES_RESURCE | 318 | 18126 | | 188 (0)| 00:00:03 |
    |* 8 | INDEX RANGE SCAN | TASK_USES_RESUR_IDX$$_0CDC0002 | 318 | | | 3 (0)| 00:00:01 |
    | 9 | TABLE ACCESS BY INDEX ROWID | TASK | 1 | 71 | | 1 (0)| 00:00:01 |
    |* 10 | INDEX UNIQUE SCAN | TASK_PK | 1 | | | 0 (0)| 00:00:01 |
    | 11 | VIEW | | 1480K| 73M| | 23431 (2)| 00:04:42 |
    |* 12 | HASH JOIN RIGHT OUTER | | 1480K| 76M| 38M| 23431 (2)| 00:04:42 |
    | 13 | TABLE ACCESS FULL | TASK_USES_RESURCE | 1486K| 21M| | 2938 (2)| 00:00:36 |
    | 14 | VIEW | | 1445K| 53M| | 15031 (2)| 00:03:01 |
    | 15 | HASH GROUP BY | | 1445K| 37M| 110M| 15031 (2)| 00:03:01 |
    | 16 | TABLE ACCESS FULL | TASK_WORK_HISTORY | 1445K| 37M| | 3897 (2)| 00:00:47 |
    --------------------------------------------------------------------------------------------------------------------------

    ...continued
    Complete execution plan for left join:
    | Id  | Operation                       | Name                           | Rows  | Bytes |TempSpc| Cost (%CPU)| Time     |                                                                                                                                                                                  
    |   0 | SELECT STATEMENT                |                                |   318 |  1594K|       | 28544   (2)| 00:05:43 |                                                                                                                                                                                  
    |*  1 |  HASH JOIN OUTER                |                                |   318 |  1594K|  1584K| 28544   (2)| 00:05:43 |                                                                                                                                                                                  
    |   2 |   VIEW                          |                                |   318 |  1578K|       |   508   (1)| 00:00:07 |                                                                                                                                                                                  
    |   3 |    NESTED LOOPS                 |                                |   318 | 74412 |       |   508   (1)| 00:00:07 |                                                                                                                                                                                  
    |   4 |     NESTED LOOPS                |                                |   318 | 51834 |       |   189   (0)| 00:00:03 |                                                                                                                                                                                  
    |   5 |      TABLE ACCESS BY INDEX ROWID| RESURCE                        |     1 |   106 |       |     1   (0)| 00:00:01 |                                                                                                                                                                                  
    |*  6 |       INDEX UNIQUE SCAN         | RESURCE_PRINCIPAL_NAME_INDEX   |     1 |       |       |     0   (0)| 00:00:01 |                                                                                                                                                                                  
    |   7 |      TABLE ACCESS BY INDEX ROWID| TASK_USES_RESURCE              |   318 | 18126 |       |   188   (0)| 00:00:03 |                                                                                                                                                                                  
    |*  8 |       INDEX RANGE SCAN          | TASK_USES_RESUR_IDX$$_0CDC0002 |   318 |       |       |     3   (0)| 00:00:01 |                                                                                                                                                                                  
    |   9 |     TABLE ACCESS BY INDEX ROWID | TASK                           |     1 |    71 |       |     1   (0)| 00:00:01 |                                                                                                                                                                                  
    |* 10 |      INDEX UNIQUE SCAN          | TASK_PK                        |     1 |       |       |     0   (0)| 00:00:01 |                                                                                                                                                                                  
    |  11 |   VIEW                          |                                |  1480K|    73M|       | 23431   (2)| 00:04:42 |                                                                                                                                                                                  
    |* 12 |    HASH JOIN RIGHT OUTER        |                                |  1480K|    76M|    38M| 23431   (2)| 00:04:42 |                                                                                                                                                                                  
    |  13 |     TABLE ACCESS FULL           | TASK_USES_RESURCE              |  1486K|    21M|       |  2938   (2)| 00:00:36 |                                                                                                                                                                                  
    |  14 |     VIEW                        |                                |  1445K|    53M|       | 15031   (2)| 00:03:01 |                                                                                                                                                                                  
    |  15 |      HASH GROUP BY              |                                |  1445K|    37M|   110M| 15031   (2)| 00:03:01 |                                                                                                                                                                                  
    |  16 |       TABLE ACCESS FULL         | TASK_WORK_HISTORY              |  1445K|    37M|       |  3897   (2)| 00:00:47 |                                                                                                                                                                                  
    Query Block Name / Object Alias (identified by operation id):                                                                                                                                                                                                                                               
       1 - SEL$1AFB0324                                                                                                                                                                                                                                                                                         
       2 - SEL$58A6D7F6 / from$_subquery$_005@SEL$8                                                                                                                                                                                                                                                             
       3 - SEL$58A6D7F6                                                                                                                                                                                                                                                                                         
       5 - SEL$58A6D7F6 / RESURCEWORKER@SEL$2                                                                                                                                                                                                                                                                   
       6 - SEL$58A6D7F6 / RESURCEWORKER@SEL$2                                                                                                                                                                                                                                                                   
       7 - SEL$58A6D7F6 / TASKUSESRESURCE@SEL$1                                                                                                                                                                                                                                                                 
       8 - SEL$58A6D7F6 / TASKUSESRESURCE@SEL$1                                                                                                                                                                                                                                                                 
       9 - SEL$58A6D7F6 / TASK@SEL$1                                                                                                                                                                                                                                                                            
      10 - SEL$58A6D7F6 / TASK@SEL$1                                                                                                                                                                                                                                                                            
      11 - SEL$7EBCC247 / TRW@SEL$3                                                                                                                                                                                                                                                                             
      12 - SEL$7EBCC247                                                                                                                                                                                                                                                                                         
      13 - SEL$7EBCC247 / TUR@SEL$4                                                                                                                                                                                                                                                                             
      14 - SEL$6        / TRW_IN@SEL$5                                                                                                                                                                                                                                                                          
      15 - SEL$6                                                                                                                                                                                                                                                                                                
      16 - SEL$6        / TWH@SEL$6                                                                                                                                                                                                                                                                             
    Predicate Information (identified by operation id):                                                                                                                                                                                                                                                         
       1 - access("TRW"."RESURCE_ID"(+)="TASKUSESRESURCE"."RESURCE_ID" AND "TRW"."TASK_ID"(+)="TASK"."ID")                                                                                                                                                                                                      
       6 - access("RESURCEWORKER"."USER_PRINCIPAL_NAME"=U'jernej')                                                                                                                                                                                                                                              
       8 - access("TASKUSESRESURCE"."RESURCE_ID"="RESURCEWORKER"."ID")                                                                                                                                                                                                                                          
      10 - access("TASKUSESRESURCE"."TASK_ID"="TASK"."ID")                                                                                                                                                                                                                                                      
      12 - access("TUR"."RESURCE_ID"(+)="TRW_IN"."RESURCE_ID" AND "TUR"."TASK_ID"(+)="TRW_IN"."TASK_ID")                                                                                                                                                                                                         Jonathan, I've been to one of your workshops in Ljubljana. I'm still trying to understand everything you explained and use it, but there's much I have to learn and understand.
    The way I see this query it should fist join and filter the first three tables and only then join the trw subquery. The problem with this subqrey is task_work_history table, which is accessed in very different ways in different places, so there will always be many reads to gather required data. For now, however, I'd be hapy to just bring the performance of inner join to left join...

  • Edit form with an Inner Join - Can not update/delete data?!

    Hi all,
    I have an Edit form which shows me data from 2 tables (through an Inner Join SQL-Statement). I just realized that I can not edit data anymore, the following error msg appears:
    Error in mru internal routine: ORA-20001: no data found in tabular form
         Error     Unable to process update.
    OK     
    Can someone please help me?

    The ringed in red are from the second table, but the first table has some more data. Here is the SQL Statement I have (D1 and D2 are from the second table - Whereas the DOBJ_NR1 and the DOBJ_NR2 are both primary keys and foreign keys in table one, but the user selects the key from table two...):
    SELECT
    D1.DOBJ_NR DOBJ_NR1,
    D1.NAMSP NAMSP1,
    D1.DOBJ_NAME DOBJ_NAME1,
    D2.DOBJ_NR DOBJ_NR2,
    D2.NAMSP NAMSP2,
    D2.DOBJ_NAME DOBJ_NAME2,
    R.RS_NAME,
    R.ROLE1TO2,
    R.CARDMIN1TO2,
    R.CARDMAX1TO2,
    R.ROLE2TO1,
    R.CARDMIN2TO1,
    R.CARDMAX2TO1,
    R.ON_DELETE,
    R.ON_UPDATE,
    R.O_RS_COMMENT,
    R.INS_BY REL_INS_BY
    FROM
    DO_RELATIONSHIP R
    INNER JOIN DATAOBJECT D1 ON R.DOBJ1_NR = D1.DOBJ_NR
    INNER JOIN DATAOBJECT D2 ON R.DOBJ2_NR = D2.DOBJ_NR
    Edited by: user12067949 on Dec 5, 2009 3:18 AM

  • Vrkme field is not fetching data

    Hello friends,
    I am fetching the data from vbrk table and vbrp table using join on vbeln field.
    but in vrkme field only 'CS' is coming but I had checked in vbrp table there is other data also based on join conditions.
    i used query:
    select amatnr abukrs avbeln bvrkme from ( vbrk as a inner join vbrp as b
    on avbeln = bvbeln ) into corresponding fields of table itab
    where  a~bukrs in s_bukrs.
    here s_bukrs is selection screen field.
    when I am checking vrkme field details in debugger then only 'CS' is coming but I had checked in database table
    other data also exists.
    why it is so? Please help me.

    It could be that the non-u201CCSu201D entries that you see in VBRP are for documents that are not in the sales organization of your selection.
    Recommend adding vbeln to your selection screen and logic.  Then get the vbeln of a VBRP record that you found (where VRKME <> CS) and run your query for that vbeln.  Should give you an idea of whatu2019s going on.
    By the way, u201Camatnru201D should be u201Cbmatnru201D in your select statement.  u201Cvbrk as au201D  does not contain the field matnr.  It must be correct in your code otherwise you would get a syntax error or no data at all.
    Regards,
    Ken

  • Link for BUT000 table and ADRC in CRM and inner join is not working in PCUI

    Hi Gurus,
       Please tell me the link btween BUT000 and ADRC table. and i wrote one inner join between BUT000 and BUT0id table but it not working. I m in CRM 4.0 version working with PCUI.
    select but000partner but000name_org1 but000name_org2 but000bus_sort1 but0id~parnter1
          but0ididnumber from but000 inner join but0id on but0idpartner = but000~parnter
    into corresponding fields of table it_result where partner in s_partner.
    It is giving error as partner unknown from but000 table. I delcared everything and tried with alias names also.
    please clarify me.
    regards,
    Ramakrishna.

    Hi Frederic,
       thanks a lot. But is inner join between BUT000 and BUT0ID will work. for me it is not working. plesae see this code.
    tables : but000,
             but0id,
             crmm_but_custno,
             adrc.
    types : begin of typ_but000,
            partner type bu_partner,
            name_org1 type BU_NAMEOR1,
            name_org2 type BU_NAMEOR2,
            bu_sort1  type BU_SORT1,
            idnumber type BU_ID_NUMBER,
            partner1 type bu_partner,
            end of typ_but000.
    data: lt_but000 type table of typ_but000,
          ls_but000 like line of lt_but000.
    *select-options : s_partnr for but000-partner.
    start-of-selection.
          select but000partner but000name_org1 but000name_org2 but000bu_sort1 but0id~parnter1
                    but0id~idnumber into corresponding fields of table lt_but000 from  but000
                    inner join but0id on but0idpartner = but000parnter. " where partner in s_partner.
    it is giving error as but000-partner is not know or but0id-partner not known.
    So, i think if it not works then i should write two select stmts.
    please clarify me.
    i gave u rating.
    thanks
    ramakrishna.

  • Inner Join of 3 tables is correct or not?

    Hi Guys ,
                 I have a requirement where i have to join 3 tables i  dont know whether the inner Join which i wrote for 3 tables is correct or not.I am not getting any Syntax error but whether the logci below which i wrote gets all the records or not.
    The Requirement is
    "c.     Select the BOL Number entered in the screen and query the table LIKP with the BOL number in the field LIKP-BOLNR.  Gather the list of ALL delivery documents (LIKP-VBELN) that is outputted.
    d.     Query the list of the delivery documents obtained into the table VBFA in the field VBFA- VBELV.  From the output that is displayed, select the Follow-On Document Field (VBFA-VBELN) for that item whose Subsequent Document Category (VBFA- VBTYP_N) is R and the Movement Type (VBFA- BWART) is 641.  Get the Follow-On document number for each of the above Delivery Document number.
    e.     Query the table EKBE with the Follow On document obtained above in the field Material Document (EKBE- BELNR).  Perform this activity for each of the follow on document obtained above.  Get the resultant Purchase Order (EKBE-EBELN) and Item Number (EKBE-EBELP) from the query.  After querying will all the Follow-On Documents, get the unique list of PO number and Item Number.
    The logic which i wrote is
                    Begin of t_PoolSTO_out,
                  BOLNR type LIKP-BOLNR,
                  EBELN type EKBE-EBELN,
                  EBELP type EKBE-EBELP,
                  VBELN type LIKP-VBELN,
                  VBELNV type VBFA-VBELN,
             End of t_PoolSTO_out.
          Data: i_PoolSTO type Standard table of t_PoolSTO_out.
      Select
            a~BOLNR
            c~EBELN
            c~EBELP
            a~VBELN
            b~VBELN
            from LIKP as a
            Inner Join VBFA as b on aVBELN = bVBELV
            Inner Join EKBE as c on bVBELN = cBELNR
            into Table i_PoolSTO
            Where a~BOLNR in S_LBLNE and
                  b~VBTYP_N = 'R' and
                  b~BWART = '641'.
              My doubt is whether the logic works or not i Mean does i getall the rrecords based on the requirement.?
                      If not please tell any alternative logic?
    Thanks,
    Gopi Anne.

    Hi Gopi,
    Your code is Good.
    But try to avoid Inner join with more number of Tables ...because this is a performance issue..
    try to use..
    select (primary key fields mainly,other fields) from LIKP into itab where bolnr in p_bolnr(paramater).
    next try to use for all entries option..
    select (primary key fields mainly,other fields) from VBFA for all entries in itab where (give the condition)....
    simillarly do for the other select ....ok this will try to reduce the performance issue....
    <b><REMOVED BY MODERATOR></b>
    Message was edited by:
            Alvaro Tejada Galindo

Maybe you are looking for