Bind variables in inner join queries

Hi all,
can we use bind variables in inner join queries?
eg:
INNER JOIN PRTY_LOC_CODE_T plc ON (ppt.PRTY_REC_ID = plc.PRTY_REC_ID and plc.HIST_CTRL_IND = *0*_ and plc.DEL_IND = *'N'*_)
regards
sunil

Dear,
can we use bind variables in inner join queries?Where are you using this join? if in a stored procedure or stored function than you don't have to care about your variables. It will be automatically considered as a bind variable
within your static SQL (i.e in your stored procedure)
Hope this helps
Mohamed Houri

Similar Messages

  • Binding variable to inner query in a VO

    Hi All,
    I am using ADF 11g. How do I bind the variables for :1,:2,:3 in the Query below:
    select max(trim_qty),max(vhead_qty),max(cill_qty),max(coupler_qty),max(wboard_qty),max(baycill_qty),max(baypole_qty)
    from +(select pd.production_date as production_date ,pd.load_no as load_no,pdi.reference_id as reference_id,pdi.item_type,pdi.piece_qty,pd.dispatch_id,pdi.package_type,pdi.type_seq,+
    decode(pdi.type_seq,0,(DECODE(pdi.item_type, 'TRIM' , pdi.piece_qty, 0)),
    +(DECODE(pdi.package_type , 'TRIM',pdi.type_seq,0))) trim_qty,+
    decode(pdi.type_seq,0,(DECODE(pdi.item_type, 'VHEAD' , pdi.piece_qty, 0)),
    +(DECODE(pdi.package_type , 'VHEAD',pdi.type_seq,0))) vhead_qty,+
    decode(pdi.type_seq,0,(DECODE(pdi.item_type, 'CILL' , pdi.piece_qty, 0)),
    +(DECODE(pdi.package_type , 'CILL',pdi.type_seq,0))) cill_qty,+
    decode(pdi.type_seq,0,(DECODE(pdi.item_type, 'COUPLER' , pdi.piece_qty, 0)),
    +(DECODE(pdi.package_type , 'COUPLER',pdi.type_seq,0))) coupler_qty,+
    decode(pdi.type_seq,0,(DECODE(pdi.item_type, 'WBOARD' , pdi.piece_qty, 0)),
    +(DECODE(pdi.package_type , 'WBOARD',pdi.type_seq,0))) wboard_qty,+
    decode(pdi.type_seq,0,(DECODE(pdi.item_type, 'BAYCILL' , pdi.piece_qty, 0)),
    +(DECODE(pdi.package_type , 'BAYCILL',pdi.type_seq,0))) baycill_qty,+
    decode(pdi.type_seq,0,(DECODE(pdi.item_type, 'BAYPOLE' , pdi.piece_qty, 0)),
    +(DECODE(pdi.package_type , 'BAYPOLE',pdi.type_seq,0))) baypole_qty+
    from pt_dispatch pd, pt_dispatch_item pdi
    where pdi.dispatch_id = pd.dispatch_id
    and production_date = :1 and load_no = :2 and reference_id = :3+
    and ((pdi.item_type in ('TRIM','VHEAD','CILL','COUPLER','WBOARD','BAYCILL','BAYPOLE') and pdi.type_seq = 0)
    or (pdi.package_type  in ('TRIM','VHEAD','CILL','COUPLER','WBOARD','BAYCILL','BAYPOLE') and pdi.type_seq > 0)))
    Thanks and Regards,
    Senthil

    You can drag the executeWithParams over to a page to create parameter form and fill out the values.
    http://www.oracle.com/technology/products/jdev/tips/muench/screencasts/threesearchpages/threesearchforms_partthree.html?_template=/ocom/technology/content/print

  • Bind Variable Values in SQL Queries

    When I want to test a query in Raptor, say something like this:
    select first_name, last_name from people
    where first_name like :P1_SEARCH or last_name = :P1_SEARCHI am prompted to provide a value for :P1_SEARCH two times.
    It would make more sense if I were only required to provide the value one time, as that's how it will be executed anyways.
    Thanks,
    - Scott -

    thanks i have bugged it.
    Mike

  • Dynamic Inner Join in 4.6c

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

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

  • How to Dene a Data Link Between Queries: Bind Variables

    This is an interesting topic and I cannot get it to work using Bind Variables.
    I have 2 queries: Q1 and Q2. Q2 needs c_id, account_code and account_type from Q1.
    Whe I run the data template below, I get only the data for Q1.
    Now people may argue that there is no data in Q2 for the relevant clause. So if I even remove the where clause in Q2 I still get no joy i.e Data appears for Q1 but not for Q2
    <dataTemplate name="FLCMR519_DATA_SET" description="Termination Quote Report">
         <parameters>
              <parameter name="cid" dataType="number" defaultValue="1"/>
              <parameter name="p_cln_id" dataType="number" defaultValue="62412"/>
         </parameters>
         <dataQuery>
              <sqlStatement name="Q1">
                   <![CDATA[SELECT qm.qmd_id,
    qm.contract_period,
    qm.quo_quo_id||'/'||qm.quote_no||'/'||qm.revision_no reference_no,
    qm.contract_distance,
    qm.mdl_mdl_id,
    q.qpr_qpr_id,
    q.quo_id,
    q.drv_drv_id,
    qm.revision_user username,
    pb.first_name||' '||pb.last_name op_name,
    pb.telephone_no,
    pb.facsimile_no,
    pb.email,
    q.c_id c_id,
    q.account_type account_type,
    q.account_code account_code,
    m.model_desc,
    ph.payment_description payment_head_desc,
    cl.fms_fms_id,
    cl.start_date,
    cl.end_date,
    cl.actual_end_date,
    cl.con_con_id,
    cl.cln_id,
    cl.term_qmd_id term_qmd_id,
    qm2.contract_period term_period,
    qm2.contract_distance term_distance
    FROM quotations q,
               quotation_models qm,
               contract_lines cl,
               personnel_base pb,
               models m,
               model_types mt,
               payment_headers ph,
               quotation_models qm2
    WHERE q.quo_id = qm.quo_quo_id
           AND cl.cln_id = :p_cln_id
           AND qm.qmd_id = cl.qmd_qmd_id
           AND qm2.revision_user = pb.employee_no (+)
           AND qm.mdl_mdl_id = m.mdl_id
           AND m.mtp_mtp_id = mt.mtp_id
           AND qm.payment_id = ph.payment_header_id
           AND qm2.qmd_id (+) = cl.term_qmd_id
    ]]>
              </sqlStatement>
              <sqlStatement name="Q2">
                   <![CDATA[SELECT ea.c_id,                  ea.account_type,ea.account_code,ea.account_name
    FROM external_accounts ea
                 WHERE ea.c_id = :c_id
                   AND ea.account_type = :account_type
                   AND ea.account_code = :account_code
    ]]>
              </sqlStatement>
         </dataQuery>
    </dataTemplate>

    Defining dataStructure section is mandatory for multiple queries.

  • How to querie with bind variable in findMode?

    Hallo,
    is it possible to use a querie with bind variable in findMode? And when how is it possible to initialize the bind variable?
    Any help is appreciated.

    Hi,
    bind variables can be linked from teh ADF binding to e.g. a managed bean, the sessionScope or other binding attributes via EL. So when you go into findMode and execute the query, the EL will grab the bindVariable values automatically.
    Frank

  • Bind Variables in SPARQL Queries

    Hi,
    I am interested in bind variables and their use between queries, however while I see the concept behind the example given in the documentation (http://docs.oracle.com/cd/E11882_01/appdev.112/e25609/sem_jena.htm#autoId15) I am not able to grasp how to exactly pass the results of a query_1 for an ?x variable to another query query_2.
    Would it be possible to offer a more detailed explanation and a working simple code about how to do this using Jena Adapater.
    Thank you.

    Hi,
    I am using the Java API to run SPARQL update queries, this is an example of what I am trying to achieve :
    public static void runTestUpdateBinding() throws SQLException {
        String[] modelNames = new String[] { };
        String[] rulebases = new String[] { };
        OracleDataSource ods = new OracleDataSource();
        ods.setURL("ORACLE CONNECTION STRING");
        OracleConnection oc = (OracleConnection)ods.getConnection();
        Oracle oracle = new Oracle(oc);
        Attachment attachment =
            Attachment.createInstance(modelNames, rulebases, InferenceMaintenanceMode.NO_UPDATE, QueryOptions.ALLOW_QUERY_INVALID_AND_DUP);
        GraphOracleSem graph = new GraphOracleSem(oracle, "in_oracle", attachment, true);
        ModelOracleSem model = new ModelOracleSem(graph);
        //Insert few triples
        String updateQuery = "INSERT DATA {                                        " +
                             "  <http://sub/a>  <http://pred/a>  <http://obj/a> .\n" +
                             "  <http://sub/b>  <http://pred/b>  <http://obj/b> .\n" +
                             "  <http://sub/c>  <http://pred/c>  <http://obj/c>    " +
        UpdateAction.parseExecute(updateQuery, model);
        //Run the update query
        updateQuery = "PREFIX    ORACLE_SEM_UEAP_NS:    <http://oracle.com/semtech#s$RDFVID%20IN(ORACLE_ORARDF_RES2VID(?),ORACLE_ORARDF_RES2VID(?))> \n" +
                      "PREFIX    ORACLE_SEM_UEPJ_NS:    <http://oracle.com/semtech#s$RDFVID> \n" +
                      "PREFIX    ORACLE_SEM_UEBV_NS:    <http://oracle.com/semtech#http%3A%2F%2Fsub%2Fa,http%3A%2F%2Fsub%2Fc> \n" +
                      "INSERT { <http://sub/UPDATED_SUBJECT>    ?p    ?o } \n" +
                      "WHERE  { ?s    ?p    ?o }";
        UpdateAction.parseExecute(updateQuery, model);
        model.close();
    Basically, I am expecting only "<http://sub/a>  <http://pred/a>  <http://obj/a>" and "<http://sub/c>  <http://pred/c>  <http://obj/c>" to match, however, "<http://sub/b>  <http://pred/b>  <http://obj/b>" also matches as you can see from the following results
    | s                            | p               | o              |
    ===================================================================
    | <http://sub/c>               | <http://pred/c> | <http://obj/c> |
    | <http://sub/UPDATED_SUBJECT> | <http://pred/c> | <http://obj/c> |
    | <http://sub/b>               | <http://pred/b> | <http://obj/b> |
    | <http://sub/UPDATED_SUBJECT> | <http://pred/b> | <http://obj/b> |
    | <http://sub/a>               | <http://pred/a> | <http://obj/a> |
    | <http://sub/UPDATED_SUBJECT> | <http://pred/a> | <http://obj/a> |
    Also, in the underlying generated SQL, there is no restriction on s$RDFVID as in SELECT queries (i.e: ...where (s$RDFVID IN(ORACLE_ORARDF_RES2VID(?),ORACLE_ORARDF_RES2VID(?))) )

  • Bind Variable reuse in GROUP BY queries

    We have several queries that are rather large (in are opinion, that is) and they each have 10 '?' place holders for binding JDBC parameters. These queries also use bind variables in the WHERE and GROUP BY clauses. Eventhough there are 10 bind variable place holders ('?'), there are only 3 distinct values needed.
    So...in TOAD or SQL*Plus, we run the queries and "reuse" the same three bind variables and the query works fine. If we use 10 different bind variables, filled with the 3 values, we get a an error, "not a GROUP BY expression."
    We would like to make these calls as JDBC PreparedStatements and bind the parameters at run time, so that we could take advantage of the statement cache and increase performance. But...since JDBC parameter binding seems to be positional, we seem to be getting 10 different bind variables at runtime in the PreparedStatement call. Is there a way to "reuse" the bind variables that JDBC is binding at runtime?
    Regards,

    Yep...that is what we are doing. We have a work around that is to manually replace the ? with string data and then pass the query in complete. It will work fine for us. I was just checking the alternatives. The query is large, but the offending code is:
    ...( select distinct T3.ptcpt_cd,trunc(new_time(T1.start_dt_gmt, 'GMT', ?)) trade_date,
    sum(decode(T1.sttl_item_num, 10, T1.sttl_item_qnty, 0)) DA_CHARGE_MW,
    sum(decode(T1.sttl_item_num, 10, T1.sttl_item_amt, 0)) DA_CHARGE_AMT,
    sum(decode(T1.sttl_item_num, 30, T1.sttl_item_qnty, 0)) BAL_CHARGE_MW,
    sum(decode(T1.sttl_item_num, 30, T1.sttl_item_amt, 0)) BAL_CHARGE_AMT,
    sum(decode(T1.sttl_item_num, 20, T1.sttl_item_qnty, 0)) DA_CREDIT_MW,
    sum(decode(T1.sttl_item_num, 20, T1.sttl_item_amt, 0)) DA_CREDIT_AMT,
    sum(decode(T1.sttl_item_num, 40, T1.sttl_item_qnty, 0)) BAL_CREDIT_MW,
    sum(decode(T1.sttl_item_num, 40, T1.sttl_item_amt, 0)) BAL_CREDIT_AMT,
    T3.source_cd Source
    from nm_sttl_item_dtl T1, nm_settlement T2, nm_sttl_statement T3
    where trunc(new_time(T1.start_dt_gmt, 'GMT', ?)) between to_date(?,'mm/dd/rrrr') and to_date(?,'mm/dd/rrrr')
    and sttl_item_num in (10, 20, 30, 40)
    and (sttl_item_qnty <> 0 and sttl_item_amt <> 0)
    and T1.sttl_id = T2.sttl_id
    and T2.statement_id = T3.statement_id
    and T3.ptcpt_cd = 'FAC'
    and T3.source_cd = AREA'
    group by T3.ptcpt_cd,trunc(new_time(T1.start_dt_gmt, 'GMT', ?)), T3.source_cd)...

  • Bind variables in jena WLS SPARQL Queries

    Dear all,
    We have read about the possibilities of the jena support for bind variables in the documentation (http://docs.oracle.com/cd/E11882_01/appdev.112/e25609/sem_jena.htm#RDFRM248). In the following topic of jun 14 2014 (Bind Variables in SPARQL Queries) the problem was already addressed. However we are facing some other problems.
    We are using:
    * WLS 12.1.3.0.0
    * jena adapter 2.11.1.
    * Joseki 3.4.4.
    * ARQ 2.9.2.
    We try to run the following query on the joseki end-point.
    PREFIX foaf: <http://xmlns.com/foaf/0.1/>
    PREFIX vcard: <http://www.w3.org/2001/vcard-rdf/3.0#>
    PREFIX ORACLE_SEM_FS_NS: <http://oracle.com/semtech#no_fall_back,ALLOW_DUP=T,ODS=6,s2s>
    PREFIX ORACLE_SEM_HT_NS: <http://oracle.com/semtech#monitor>
    PREFIX ORACLE_SEM_UEAP_NS: <http://oracle.com/semtech#f$RDFVID%20in(?)>
    PREFIX ORACLE_SEM_UEPJ_NS: <http://oracle.com/semtech#f$RDFVID>
    PREFIX ORACLE_SEM_UEBV_NS: <http://oracle.com/semtech#1264839720472151591>
    SELECT ?f ?g
    WHERE
    { graph ?g { ?p vcard:N ?vn .
                  ?vn vcard:Family ?f .
                   ?p foaf:title "Sen." .}
    The result we get back is however not using the bind variable. It returns the whole list without UEAP/UEPJ/UEBV.
    Is there something I missed in the documentation or do I need to set some variables for the use of bind variables?
    Kind regards,
    Max

    Dear Zhe,
    The solution provided works! However setting this property was not straight forward for me (but this is more related to WLS).
    Setting this JVM property in the arguments of the weblogic server (Server Start) does not work. I've looked through the files for any sign of the property but did not find any. Manually adding this line in setDomainEnv.sh
    (adding the variable JAVA_PROFILE = "-Doracle.spatial.rdf.client.jena.allowAP=true") does work though.
    Kind regards,
    Max

  • Outer join - inner joins at the level of the microcube  between 2 queries

    I have a very simple question.
    If i build 2 queries in webi on the top of the same BW query
    Query 1: Country and Revenue and we do put a filter on the query base of country = US
    Query 2: Country and Revenue and we do not have any filter on this one
    so in webi here is what happen you will get 2 tables
    one table for query 1 where you will see only data for US and then Revenue
    the second table query 2 will only retrieve data for all the countries and their revenue
    Now if i do some merging .. it sounds like it is doing an inner join
    is there a way to get the outer join or the left outer part of it or even the right out part ?
    Thanks in advance
    Philippe

    Hi Philippe,
    Yes you can.  Make sure that the Country coming from Query 2 is the one on the report. Then make sure the Revenue on the report is coming from Query 1. This should give you what you want.
    Hope that helps!
    Thanks

  • Report queries and bind variables - only header printing to PDF

    Hi,
    I created a simple report query for printing to PDF with 2 bind variables. I created a link to this report like this
    Print - the header information prints but none of the data.
    What am i doing wrong? I'm pretty sure it has s/t to do with the bind variables.
    IF a/o can please help, i'd really appreciate it.
    Thanks,
    Hindy

    is it possible to export your application page to apex server and you shall also create a userid as demo/demo and post the url so that we shall try the debug

  • Select quer with inner join

    table
    can any please modify the query
    thanking in advance
    BEGIN OF t_initord OCCURS 0,
    vbeln LIKE vbak-vbeln, " Sales Order
    posnr LIKE vbap-posnr, " Sales Order Line Item
    auart LIKE vbak-auart, " Sales Order Type
    bezei LIKE tvakt-bezei, " Sales Order Type Text
    billdo Like vbrk-vbeln, "billing document number
    matnr LIKE vbfa-matnr, " Material
    maktx LIKE makt-maktx, " Material Description
    bstnk LIKE vbak-bstnk, " Customer PO number
    bukrs LIKE vbak-bukrs_vf, " Company Code..
    vkorg LIKE vbak-vkorg, " Sales Org
    vtweg LIKE vbak-vtweg, " Distribution Channel
    spart LIKE vbak-spart, " Division
    vkgrp LIKE vbak-vkgrp, " Sales Group
    augru LIKE vbak-augru, " Order Reason
    abgru LIKE vbap-abgru, " Reson for rejection
    kwmeng LIKE vbap-kwmeng, " Order Line quantit
    deliv LIKE likp-vbeln, " Delivery Number
    delit LIKE lips-posnr, " Delivery Number
    rfmng LIKE vbfa-rfmng, " Delivery Qty..
    vbtyp_n LIKE vbfa-vbtyp_n, " R12 Defect 8938.
    mrnkz LIKE vbkd-mrnkz, " Subsequent Invoicing
    docurr LIKE vbak-waerk, " Document Currency
    netwr LIKE vbap-netwr, " Line Item Amt in Doc curr
    ocdate LIKE vbak-aedat, " Order change date
    objnr LIKE vbap-objnr, " Object number
    rad LIKE sy-datum, " Requested Arrival Date
    submi LIKE ekko-submi, " Collective number
    plant1 LIKE vbap-werks, " Supplying Plant
    ernam LIKE vbak-ernam, " Order Created by
    erdat LIKE vbak-erdat, " Order Created on
    lifnr LIKE ekko-lifnr, " Vendor
    soldto LIKE vbak-kunnr, " Sold-to Party
    shipto LIKE vbak-kunnr, " Ship-to Party
    etenr LIKE vbep-etenr, " Sales Order schedule line
    bmeng LIKE vbep-bmeng, " Order Sch Line quantity
    vrkme LIKE vbap-zieme, " Sales Order UOM
    cad LIKE sy-datum, " Confirmed Arrival Date
    ktokk LIKE lfa1-ktokk, " Vendor account group
    docurramt LIKE vbap-netwr, " Document Currency Amount
    locurr LIKE vbak-waerk, " Local Currency
    locurramt LIKE vbap-netwr, " Local Currency Amount
    werks1 LIKE vbap-werks, " Supplying Plant
    werks_name1 LIKE t001w-name1, " Plant description
    lifnr_name1 LIKE lfa1-name1, " Name of the Vendor
    stat TYPE g_stat_typ, " Status Code
    lstatus TYPE g_stext_typ, " Last Status
    soappr TYPE tj30t-txt30, " Sales Order Approval
    bdnum LIKE vbfa-vbeln, " Billing doc number
    bdlin LIKE vbrp-posnr, " Billing Item
    uecha_b LIKE vbrp-uecha, " Item of Batch split
    uecha_d LIKE lips-uecha, " Item of Batch split
    END OF t_initord.
    This is the internal table
    to get the details wrote a select query
    can any one please correct the select query
    SELECT t1vbeln t2posnr t1auart t4bezei
    t2matnr t5maktx
    t1bstnk t1bukrs_vf t1vkorg t1vtweg t1spart t1vkgrp
    t1augru t2abgru t2kwmeng t8vbeln
    t8posnn t8rfmng t8vbtyp_n t7mrnkz t2waerk t2netwr
    t1aedat t1objnr t1vdatu t1submi t2werks t1ernam t1~erdat
    t6lifnr t1kunnr t9~kunnr
    INTO TABLE t_initord
    FROM vbak AS t1
    INNER JOIN vbap AS t2
    ON t1vbeln EQ t2vbeln
    LEFT OUTER JOIN tvakt AS t4
    ON t1auart EQ t4auart
    AND t4~spras EQ c_en
    LEFT OUTER JOIN makt AS t5
    ON t2matnr EQ t5matnr
    AND t5~spras EQ c_en
    LEFT OUTER JOIN vbpa AS t9
    ON t1vbeln EQ t9vbeln
    AND t9~parvw EQ c_we
    LEFT OUTER JOIN ekko AS t6
    ON t1submi EQ t6ebeln
    LEFT OUTER JOIN vbkd AS t7
    ON t1vbeln EQ t7vbeln AND
    t7~posnr EQ c_initposnr
    LEFT OUTER JOIN vbfa AS t8
    ON t2vbeln EQ t8vbelv AND
    t2posnr EQ t8posnv
    WHERE t1~vbeln IN s_slord
    AND t1~vkbur IN s_sloff
    AND t1~vkgrp IN s_slgrp
    AND t1~kunnr IN s_custag
    AND t1~auart IN s_ortyp
    AND t1~vkorg IN s_slorg
    AND t1~vtweg IN s_disch
    AND t1~spart IN s_divi
    AND t1~erdat IN s_date
    AND t1~bukrs_vf IN s_ccode
    AND t2~ernam IN s_slcre.
    i need to modify the above query to get the additional information into the above table
    billing doument number
    document currency
    document currency amount
    billed quantity
    sold to country
    ship to country

    You can also refer to this code... for making your code better..
    SELECT MATNR
           WERKS
           DISMM
           DISPO
           BESKZ INTO TABLE I_MARC FROM MARC
                 WHERE WERKS IN S_WERKS  AND BESKZ = 'F' AND DISMM <> 'ND'.
      IF NOT I_MARC IS INITIAL.
      SELECT MATNR
             MAKTX INTO TABLE I_MAKT FROM MAKT
                   FOR ALL ENTRIES IN I_MARC
                   WHERE MATNR = I_MARC-MATNR.
      ENDIF.
    REFRESH I_MDPS.
    REFRESH I_MDEZ.
    REFRESH I_MT61D.
    REFRESH I_MDPS2.
    REFRESH I_MDEZ2.
    LOOP AT I_MARC INTO WA_MARC.
    CALL FUNCTION 'MD_STOCK_REQUIREMENTS_LIST_API'
      EXPORTING
        MATNR                          = WA_MARC-MATNR
        WERKS                          = WA_MARC-WERKS
    TABLES
       MDEZX                           = I_MDEZ
    EXCEPTIONS
       MATERIAL_PLANT_NOT_FOUND       = 1
       PLANT_NOT_FOUND                = 2
       OTHERS                         = 3
    LOOP AT I_MDEZ.
       I_MDEZ2-MATNR = WA_MARC-MATNR.
       I_MDEZ2-WERKS = WA_MARC-WERKS.
       MOVE-CORRESPONDING I_MDEZ TO I_MDEZ2.
       APPEND I_MDEZ2.
    ENDLOOP.
    CLEAR I_MDEZ.
    CLEAR I_MDEZ2.
      ENDLOOP.
    Deleting teh records from the internal table which are
    nither purchase order nor purchase requisition.
    if pur_ord = 'X' and Pur_req = 'X'.
      delete i_mdez2 where delkz <> 'BA' and delkz <> 'BE'.
    endif.
    if pur_ord = 'X' and Pur_req <> 'X'.
      delete i_mdez2 where delkz <> 'BE'.
    endif.
    if pur_req = 'X' and pur_ord <> 'X'.
      delete i_mdez2 where delkz <> 'BA'.
    endif.
    Populating the final internal table to be displayed.
    Sort i_mdez2 by matnr werks.
    SORT I_MAKT BY MATNR.
      LOOP AT I_MDEZ2 WHERE LIFNR IN S_LIFNR.
              wa_final-werks = i_mdez2-werks.
              WA_FINAL-LIFNR = I_MDEZ2-LIFNR.
              WA_FINAL-EXTRA = I_MDEZ2-EXTRA.
              WA_FINAL-MNG01 = I_MDEZ2-MNG01.
              WA_FINAL-AUSKT = I_MDEZ2-AUSKT.
              WA_FINAL-UMDAT = I_MDEZ2-UMDAT.
              WA_FINAL-WERKS = I_MDEZ2-WERKS.
              WA_FINAL-MATNR = I_MDEZ2-MATNR.
              wa_final-delkz = i_mdez2-delkz.
    For Message to be displayed with the Purchase Order and Purchase Requisition.
              PERFORM TEXT_EXCEPTION.
              READ TABLE I_MAKT INTO WA_MAKT WITH KEY MATNR = WA_FINAL-MATNR BINARY SEARCH.
              IF SY-SUBRC = 0.
                WA_FINAL-MAKTX = WA_MAKT-MAKTX.
              ENDIF.
           APPEND WA_FINAL TO I_FINAL .
      ENDLOOP.
        IF SY-SUBRC <> 0.
           MESSAGE I058.
           leave program.
        ENDIF.
    Selecting the Purchase Organisation from the EKKO table.
    if not i_final is initial.
      SELECT EBELN EKORG LIFNR INTO TABLE I_EKKO FROM EKKO
             FOR ALL ENTRIES IN I_FINAL
             WHERE LIFNR = I_FINAL-LIFNR.
    Selecting the name of the vendor from the LFA1 table.
      select lifnr name1 into table i_lfa1 from lfa1
             for all entries in i_final
             where lifnr = i_final-lifnr.
    Selecting the current date from the eban table.
       select matnr lfdat into table i_eban from eban
            for all entries in i_final
            where matnr = i_final-matnr." and bnfpo = i_ekpo-bnfpo.
    endif.
    if not i_ekko is initial.
    Selecting the Unit Price from EKPO for finding the Extended amount.
      SELECT EBELN ebelp NETPR MATNR  banfn bnfpo INTO TABLE I_EKPO FROM EKPO
             FOR ALL ENTRIES IN I_EKKO
             WHERE EBELN = I_EKKO-EBELN.
    endif.
    if not i_ekpo is initial.
    Selecting the current date from the Eket table.
    select ebeln ebelp eindt into table i_eket from eket
           for all entries in i_ekpo
           where ebeln = i_ekpo-ebeln and ebelp = i_ekpo-ebelp.
    endif.
    *Sorting the internal tables.
    SORT I_EKKO BY LIFNR.
    sort i_lfa1 by lifnr.
    SORT I_EKPO BY MATNR.
    sort i_eket by ebeln ebelp.
    sort i_eban by matnr.
      LOOP AT I_FINAL INTO WA_FINAL.
        READ TABLE I_EKKO INTO WA_EKKO WITH KEY LIFNR = WA_FINAL-LIFNR.
           WA_FINAL-EKORG = WA_EKKO-EKORG.
          wa_final-ebeln = wa_ekko-ebeln.
         read table i_lfa1 into wa_lfa1 with key lifnr = wa_final-lifnr.
           wa_final-name1 = wa_lfa1-name1.
           READ TABLE I_EKPO INTO WA_EKPO WITH KEY MATNR = WA_FINAL-MATNR.
             wa_final-ebelp = wa_ekpo-ebelp.
             WA_FINAL-NETPR = WA_EKPO-NETPR.
           if wa_final-delkz = 'BA'.
             read table i_eban into wa_eban with key matnr = wa_final-matnr.
             wa_final-dat00 = wa_eban-lfdat.
           endif.
           if wa_final-delkz = 'BE'.
             read table i_eket into wa_eket with key ebeln = wa_final-ebeln ebelp = wa_final-ebelp.
              wa_final-dat00 = wa_eket-eindt.
           endif.
           WA_FINAL-EXTND_AMOUNT = WA_FINAL-MNG01 * WA_FINAL-NETPR.
        MODIFY I_FINAL FROM WA_FINAL TRANSPORTING EKORG name1 dat00 EXTND_AMOUNT.
      ENDLOOP.
    In this I have taken many internal tables... according to the database table I am extracting from .. then I am bringing all the record in the final internal table which will be containing teh records from all the internal table that i have used..
    Regards,
    Jayant
    <b>Please award if helpful</b>

  • Query contain inner join to external DB

    Hi every body,
    I have created a new sql query that contain inner join to external db of the production software. The query also uses parameters for filter data by date .
    I succeeded to create a qurey that will work including inner join to the external DB and parameters,
    Here is the query:
    SELECT T0.DocNum, T0.DocDate, T0.CardCode, T0.CardName, T1.ItemCode, T1.Dscription, T1.Quantity, T1.TotalSumSy, T1.LineTotal, T0.Canceled, T2.Family
       FROM  [XXX].dbo.AllItems T2
         RIGHT OUTER JOIN INV1 T1 ON T1.ItemCode=          T2.ItemPN collate SQL_Latin1_General_CP1_CI_AS
         INNER JOIN OINV T0 ON T1.DocEntry = T0.DocEntry
         INNER JOIN OITM T3 ON T1.ItemCode = T3.ItemCode
         INNER JOIN OITB T4 ON T3.ItmsGrpCod = T4.ItmsGrpCod
         INNER JOIN OCRD T5 ON T0.CardCode = T5.CardCode
         INNER JOIN OACT T6 ON T1.AcctCode = T6.AcctCode
    Where T0.DocDate BETWEEN [%0] AND [%1]
    but when I add a union statement the query does not work again.
    If I remove the parameters every thing is working fine.
    what is the problem with my query?
    Thank you all very much.

    SBO does not manage correctly variables in complicated query.  There is a note about it:
    Note 730960 - SAP Business One does not identify variables in long queries
    https://websmp130.sap-ag.de/sap/bc/bsp/spn/sapnotes/index2.htm?numm=730960
    This note describe the method to get the parameters in variables and their usage.

  • Report Performance with Bind Variable

    Getting some very odd behaviour with a report in APEX v 3.2.1.00.10
    I have a complex query that takes 5 seconds to return via TOAD, but takes from 5 to 10 minutes in an APEX report.
    I've narrowed it down to one particular bind. If I hard code the date in it returns in 6 seconds, but if I let the date be passed in from a parameter it takes 5+ minutes again.
    Relevant part of the query (an inline view) is:
    ,(select rglr_lect lect
    ,sum(tpm) mtr_tpm
    ,sum(enrols) mtr_enrols
    from ops_dash_meetings_report
    where meet_ev_date between to_date(:P35_END_DATE,'DD/MM/YYYY') - 363 and to_date(:P35_END_DATE,'DD/MM/YYYY')
    group by rglr_lect) RPV
    I've tried replacing the "to_date(:P35_END_DATE,'DD/MM/YYYY') - 363" with another item which is populated with the date required (and verified by checking session state). If I replace the :P35_END_DATE with an actual date the performance is fine again.
    The weird thing is that a trace file shows me exactly the same Explain Plan as the TOAD Explain where it runs in 5 seconds.
    Another odd thing is that another page in my application has the same inline view and doesn't hit the performance problem.
    The trace file did show some control characters (circumflex M) after each line of this report's query where these weren't anywhere else on the trace queries. I wondered if there was some sort of corruption in the source?
    No problems due to pagination as the result set is only 31 records and all being displayed.
    Really stumped here. Any advice or pointers would be most welcome.
    Jon.

    Don't worry about the Time column, the cost and cardinality are more important to see whther the CBO is making different decisions for whatever reason.
    Remember that the explain plan shows the expected execution plan and a trace shows the actual execution plan. So what you want to do is compare the query with bind variables from an APEX page trace to a trace from TOAD (or sqlplus or whatever). You can do this outside APEX like this...
    ALTER SESSION SET EVENTS '10046 trace name context forever, level 1';Enter and run your SQL statement...;
    ALTER SESSION SET sql_trace=FALSE;This will create a a trace file in the directory returned by...
    SELECT value FROM v$parameter WHERE name = 'user_dump_dest' Which you can use tkprof to format.
    I am assuming that your not going over DB links or anything else slightly unusual?
    Cheers
    Ben

  • Problem with Join Queries using PHP and an Orcale Database

    Ok, I am trying to build a simple php querying tool for my oracle database and for the most part it is working however I am having a problem getting data from my join queries. If I run the following query :
    QUERY:
    SELECT lastfirst,EnteredBy,Debit FROM students sts JOIN GLDetail gl ON gl.studentid=sts.id
    RESULT SET:
    Lastfirst     EnteredBy     Debit
    caiu, test      204     1
    But when I run the query correctly I get no results
    QUERY:
    SELECT sts.lastfirst,gl.EnteredBy,gl.Debit FROM students sts JOIN GLDetail gl ON gl.studentid=sts.id
    RESULT SET:
    sts.lastfirst     gl.EnteredBy     gl.Debit
    and if I run the query combining the two above methods and adding a field (schoolid) that has the same name on both table I get the following result sets
    QUERY:
    SELECT lastfirst,EnteredBy,Debit,sts.schoolid FROM students sts JOIN GLDetail gl ON gl.studentid=sts.id
    RESULT SET:
    lastfirst     EnteredBy     Debit     sts.schoolid
    caiu, test      204     1     
    QUERY:
    SELECT lastfirst,EnteredBy,Debit,schoolid FROM students sts JOIN GLDetail gl ON gl.studentid=sts.id
    RESULT SET:
    NONE
    Therefore, I have to have something written incorrectly in my php code and I just can not figure it out. My entire code is pasted below please provide me with an assistance you might have to offer. I have change the odbc_connec line so I could post it to this forum. In addition, I had to phrase out the column headers there for when you write the column headers you have to use ~ instead of , as the separator and then I turn back into the correct format for sql.
    //These scripts just open help windows if somone clicks on the icon
    <script>
    function submit()
    {document.sqlform.submit();}
    </script>
    <script>
    function colwin(){
    window.open("colnames.php",null,"height=300,width=400,scrollbars=1");}
    </script>
    <script>
    function tabwin(){
    window.open("tablenames.php",null,"height=300,width=400,scrollbars=1");}
    </script>
    <script>
    function help(){
    window.open("http://www.w3schools.com/sql/default.asp",null,"height=500,width=700,scrollbars=1");}
    </script>
    <form method="post" action="<?php echo $PHP_SELF;?>" name="sqlform">
    <?php
    //Cookie to check for authorization to the site
    if($_COOKIE['cookie']=="CheckCookieForAuth")
    //These get the values of the textareas after the form has been submitted
    $sqlSELECT = $_POST["SELECT"];
    $sqlFROM = $_POST["FROM"];
    $sqlJOIN = $_POST["JOIN"];
    $sqlWHERE = $_POST["WHERE"];
    $sqlOTHER = $_POST["OTHER"];
    $sqlSELECTTYPE = $_POST["SELECTTYPE"];
    //This is the variable used to parse out my headers the user entered
    $sqlColNames = split('~',$sqlSELECT);
    //This converts the ~ separator to , so I can actually use it as part of my sql string
    $search = array('~');
    $replace = array(',');
    $mystring = $sqlSELECT;
    $sqlString = str_replace($search, $replace, $mystring);
    //These are the textareas and the drop down options that the end users has to create queries
    echo "<table border=0>";
    echo "<tr><td valign='top'>";
    echo "<B>SELECT TYPE</B> <BR><SELECT NAME=SELECTTYPE>
    <OPTION VALUE='SELECT' SELECTED>SELECT</OPTION>
    <OPTION VALUE='SELECT DISTINCT'>SELECT DISTINCT</OPTION>
    <OPTION VALUE='INSERT'>INSERT</OPTION>
    <OPTION VALUE='UPDATE'>UPDATE</OPTION>
    <OPTION VALUE='DELETE'>DELETE</OPTION>
    </SELECT>";
    echo "</td><td>";
    echo "<textarea rows=2 cols=75 name=SELECT wrap=physical>$sqlSELECT</textarea>";
    echo "</td><td valign='top'>";
    echo "<img src='images/sqlC.jpg' width='25' height='25' onclick='colwin()'>";
    echo "</td></tr>";
    echo "<tr><td valign='top'>";
    echo "<b>FROM</b>";
    echo "</td><td>";
    echo "<textarea rows=2 cols=75 name=FROM wrap=physical>$sqlFROM</textarea>";
    echo "</td><td valign='top'>";
    echo "<img src='images/sqlT.jpg' width='25' height='25' border=0 onclick='tabwin()'>";
    echo "</td></tr>";
    echo "<tr><td valign='top'>";
    echo "<b>JOIN</b>";
    echo "</td><td>";
    echo "<textarea rows=2 cols=75 name=JOIN wrap=physical>$sqlJOIN</textarea>";
    echo "</td></tr>";
    echo "<tr><td valign='top'>";
    echo "<b>WHERE</b>";
    echo "</td><td>";
    echo "<textarea rows=2 cols=75 name=WHERE wrap=physical>$sqlWHERE</textarea>";
    echo "</td></tr>";
    //This is where the end user would enter group by, having, order by, etc..
    echo "<tr><td valign='top'>";
    echo "<b>OTHER</b>";
    echo "</td><td>";
    echo "<textarea rows=2 cols=75 name=OTHER wrap=physical>$sqlOTHER</textarea>";
    echo "</td></tr>";
    This is a run query icon and a help icon
    echo "<tr><td colspan=2 align=right>";
    echo "<img src='images/RunQuery.jpg' width='30' height='28' onclick='submit()'> <img src='images/qm.jpg' border=0 width='25' height='25' onclick='help()'>";
    echo "</td></tr></table>";
    echo "<br>";
    echo "<br>";
    //This is where I connect to my remote oracle database
         $conn=odbc_connect('ODBC_ConnectionName','USERNAME','PASSWORD');
    //This is the sql string created by the end users
         $sql="$sqlSELECTTYPE $sqlString FROM $sqlFROM $sqlJOIN $sqlWHERE $sqlOTHER";
    //This executes the connection string and the sql string
         $rs=odbc_exec($conn,$sql);
    //This will display the query or a message if the query is empty
         if($rs!=NULL){
         echo "<table border=1>";
         echo "<tr>";
    //This loops through the string array the end user enter the field name text area to get column headers
         for($i=0; $i<count($sqlColNames); $i++)
         echo "<td>";
         print_r($sqlColNames[$i]);
         echo "</td>";
         echo "</tr><tr>";
    //This actually fetchs the rows from the statement and then display the data based on the column names the end user speificed
         while (odbc_fetch_row($rs))
              for($i=0; $i<count($sqlColNames); $i++)
                   $results=odbc_result($rs,$sqlColNames[$i]);
                   echo "<td>$results</td>";
              echo "</tr>";
         odbc_close($conn);
         echo "</table>";}else{echo "Results will be displayed here";}
    echo "<br><br>";
    echo $sql;
    else
    echo "Not logged in";
    ?>
    </form>

    This looks more like a SQL question than a PHP issue. There are a couple of JOIN examples at http://download.oracle.com/docs/cd/B28359_01/server.111/b28286/statements_10002.htm#i2066611 that might you work through the problem.

Maybe you are looking for

  • New voice memos not syncing from iphone to itunes

    My voice memos are not syncing from my iPhone4 to iTunes.  Everything has been restarted.  Everything is up-to-date.  The voice memo box is checked.  What is going on?  Thanks.

  • ITunes not opening.  NO ERROR MESSAGE

    I cannot get iTunes to open. When I double click on it, the "hour glass" shows up, and I give it a minute or more, but the program does not open? I have the updated verision, but cannot get it to open. No error message when I try to open it...no prog

  • Is it possible to create a spatial index on a view?

    Hi Is it possible to create a spatial index on a view? We would like to link our spatial tables to each other (using only one of the SDO_GEOMETRY fields) in a view & make it very easy so that anybody can work with the data. Thanks Caroline.

  • I'm new on discussions;what are points?

    it says you get points for answering peoples questions or something????

  • I just installed flashplugin from multilib and it doesn't work...

    I have an x86_64 system and i tried installing flashplugin from [multilib] but it won't work in any browsers.  I check my browsers (epiphany, chromium, firefox) and all show that "NPAPI Plugins Wrapper 1.3.0" is active. How do I get flashplugin worki