Merging a collection into a table

I have a table with some blank columns.
I take all the data from the table in a collection and then process the data to fill those empty columns.
Now i have the collection with all the valid data.
Is it possible to cast this same collection into a table and merge it again into the original table?
I am trying to do so, but there is an error saying "cant use local collection"...
Any help on this would be appreciated.

Thanks a lot for your suggestion.
I would like to give you an elaborate process.
I have a table ABC. Some columns of that table are empty. I need to get those filled using some other tables.
Firstly, using a cursor I fetch the records in a collection say V_ABC.
Now in a FOR loop, I am fetching the missing data from other tables for every record in the collection and setting it in the empty places in the collection V_ABC itself.
So finally i have the collection V_ABC which has complete data.
The FOR loop is now ended.
Now i try to merge this V_ABC into tale ABC like this:
MERGE INTO ABC abc
USING TABLE(CAST(V_ABC AS TT_ABC)) z
ON (abc.random_column_name = z.random_column_name)
WHEN MATCHED THEN
UPDATE
SET abc.initially_empty_column = z.initially_empty_column
The exact error is "Error: PLS-00642: local collection types not allowed in SQL statements".
I am forced to use PL-SQL because of performance issues.
Could you provide an alternate way?
I guess one way would be to create another empty collection and EXTENDing it and creating a replica of V_ABC. Then probably it will allow me to merge. But i m not sure.

Similar Messages

  • Error in bulk collect into nested table

    I keep getting an error while trying to compile this line:
    fetch c_juros bulk collect into wrk_juros_plano(p_ind_segreg);
    LINE/COL ERROR
    0/0      PLS-00801: internal error [74306]When i put that single line into comments it goes fine. Sure it doesn't do what I want.
    The data structure i use is as follows:
      cursor c_juros(p_ind_segreg in varchar2) is
        select (((power(1 + (i.prc_juros_atuari_ano / 100), 1 / 12) - 1) * 100) / 100) prc_juros_efetiv_mes,
               i.dat_inic_vigenc,
               (nvl(i.dat_fim_vigenc, sysdate) + 1) dat_fim_vigenc,
               i.ind_segreg
          from v_indexador_taxa_atuarial i
         where i.ind_segreg = p_ind_segreg
         order by i.dat_inic_vigenc;
      type t_juros_plano     is table of c_juros%rowtype;
      type t_tab_juros_plano is table of t_juros_plano index by binary_integer;
      wrk_juros_plano t_tab_juros_plano;the code goes like this:
      begin
        if not(wrk_juros_plano.exists(p_ind_segreg))
        then
          if c_juros%isopen
          then
            close c_juros;
          end if;
          open c_juros(p_ind_segreg);
          wrk_juros_plano(p_ind_segreg) := t_juros_plano();
          fetch c_juros bulk collect into wrk_juros_plano(p_ind_segreg);
        end if;
      ...p_ind_segreg is my input parameter, that should be the index of the array.
    The purpose is to create the parameter indexed element if it doesn't already exist, fetching it
    from the cursor, that defines a nested table.
    I tried removing the initialization line to no effect, among other things.

    Ok, I just found out a way around it. It works, but that error is probably a bug, cause workarounds are not really cute.
    I declared a nested table compatible with the element from the associative array:
    wrk_juros t_juros_plano;and chaged that line that was causing the error
    fetch c_juros bulk collect into wrk_juros_plano(p_ind_segreg);for
    fetch c_juros bulk collect into wrk_juros;
    wrk_juros_plano(p_ind_segreg) := wrk_juros;Awesome =\

  • Problem in collecting Spool data into internal table

    Hi ,
    i need to download  spool request data into internal table,
    after collecting i need to loop it and delete some records,
    for this i am using  Fm  RSPO_RETURN_ABAP_SPOOLJOB
    but getting some extra spaces and lines,unable to get right format.
    please help me in this issue to prepare internal table like normal internal table with spool id.
    Regards
    sarath

    Hi ,
    Thanks for the reply,
    My requirement is like i need to collect all the records from the spool to Internal table and
    after that based on one field in the internal table i have to separate error records by deleting sucess records from that internal table(from spool),
    for that i have to loop the internal table and need to count the error records, after that download to excel and mail functionalities
    required for that .
    so please help me in this.
    Regards
    sarath

  • Collect message into internal table

    Hi,
    does any one knows how BAPIs or CALL TRANSACTIONs collect messages into internal table.
    My problem is that some BI with CALL TRANSACTION doesn't collect right message into return table and I would like to collect this last message after CALL TRANSACTION and therefore be sure that everything went OK.....
    thx
    mario

    hi
    good
    check this
    Call Transaction p_trans using ZBDC_Table
                                   Mode p_mode
                                 Update p_update
                          Messages into p_messages.
         Move sy-subrc to w__subrc.
       Scan the messages in YDCRAISES to see if we need to
       change the message class.
         Loop at p_messages.
              Select single msgtyp
                into w__msgtp
                from zdcraise
               where tcode  = p_messages-tcode  and
                     msgid  = p_messages-msgid  and
                     msgnr  = p_messages-msgnr.
              If sy-subrc = 0.
                 Move w__msgtp to p_messages-msgtyp.
                 Modify p_messages.
              EndIf.
         EndLoop.
       Dump the message table ?
         If w__ydcset-dumpmsg = True.
    thanks
    mrutyun^

  • "table of" collection into cursor

    Let say i have a collection-variable called "emps":
    TYPE emp_table IS TABLE OF employee%ROWTYPE;
    emps emp_table;Now i'm inserting data into it. And then i want to put all data from "emps" to variable
    "o_annuity_payments out SYS_REFCURSOR"
    soemthing like this:
    open o_annuity_payments for
    bulk collect from emps;
    how should i do?

    CharlesRoos wrote:
    Maybe such syntacts is allowed:
    1. declare cursor type variable.Yes.
    2. insert a row into cursor type variableNo.
    Re: "table of" collection into cursor
    A cursor is a pointer to a compiled SQL statement
    http://download.oracle.com/docs/cd/E11882_01/server.112/e10713/sqllangu.htm#CHDFCAGA
    When an application issues a SQL statement, the application makes a parse call to the database to prepare the statement for execution. The parse call opens or creates a cursor, which is a handle for the session-specific private SQL area that holds a parsed SQL statement and other processing information. It is not a result set.
    You cannot insert a row into a cursor because you cannot insert a row into a compiled SQL statement.
    maybe if you explain what you are trying to do more help can be given.

  • Selecting the contents of a table(collection) into a strong REF Cursor

    I'm trying to roll some data into a table collection and return it as a strong named cursor.
    I have not been able to do this successfully yet.
    I have tried casting the table and I couldn't get that to work either.
    I have included the whole procedure but here is the line I am getting errors on:
    SELECT * bulk collect into o_response_data_cur from table (response_data_tbl);
    Any help on this would be great.
    P.S. - As this is being picked up by BizTalk I can't return a table.
    Thanks,
    Todd M
    PROCEDURE create_customer (
    i_interface_hdr IN BizTalk_TestCustomer.interface_hdr_rec,
    i_customer_rec IN BizTalk_TestCustomer.customer_rec,
    i_address_cur IN BizTalk_TestCustomer.CUR_Addresses,
    i_contact_cur IN BizTalk_TestCustomer.CUR_Contact,
    o_interface_status OUT varchar2,
    o_response_data_cur OUT BizTalk_TestCustomer.CUR_CreateCustResponse)
    IS
    l_response_rec create_cust_response_rec;
    response_data_tbl create_cust_response_tbl;
    BEGIN
    FOR i IN 1 .. 10
    LOOP
    l_response_rec.ERROR_TYPE := 'Pre-Validation Error';
    l_response_rec.ERROR_CODE := 'DUMMY-' || i;
    l_response_rec.error_message := 'Test Error Message-' || i;
    response_data_tbl (i) := l_response_rec;
    END LOOP;
    SELECT * bulk collect into o_response_data_cur from table (response_data_tbl);
    o_interface_status := 'FAILURE';
    END create_customer;
    END BizTalk_TestCustomer;
    Here is the important Spec info:
    TYPE create_cust_response_rec
    IS
    RECORD (
    orig_system_party_ref varchar2 (240),
    orig_system_cust_acct_ref varchar2 (240),
    orig_system_site_ref varchar2 (240),
    oracle_party_id number,
    oracle_customer_id number,
    oracle_site_id number,
    ERROR_TYPE strar_cust_intf_err.ERROR_TYPE%TYPE,
    ERROR_CODE strar_cust_intf_err.ERROR_CODE%TYPE,
    error_message strar_cust_intf_err.error_message%TYPE
    TYPE CUR_Addresses IS REF CURSOR RETURN BizTalk_TestCustomer.address_rec;
    TYPE CUR_Contact IS REF CURSOR RETURN BizTalk_TestCustomer.contact_rec;
    TYPE CUR_CreateCustResponse IS REF CURSOR RETURN BizTalk_TestCustomer.create_cust_response_rec;
    TYPE create_cust_response_tbl
    IS
    TABLE OF create_cust_response_rec
    INDEX BY binary_integer;

    I think this is one of the most complicated one to develop and execute perfectly. ;)
    Here is one such case ->
    satyaki>
    satyaki>select * from v$version;
    BANNER
    Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - Prod
    PL/SQL Release 10.2.0.3.0 - Production
    CORE    10.2.0.3.0      Production
    TNS for 32-bit Windows: Version 10.2.0.3.0 - Production
    NLSRTL Version 10.2.0.3.0 - Production
    Elapsed: 00:00:00.55
    satyaki>
    satyaki>
    satyaki>create or replace type d_obj as object
      2    (
      3      buff    varchar2(310)
      4    );
      5  /
    Type created.
    Elapsed: 00:00:00.05
    satyaki>
    satyaki>
    satyaki>create or replace type d_rec as table of d_obj;
      2  /
    Type created.
    Elapsed: 00:00:01.14
    satyaki>
    satyaki>
    satyaki>
    satyaki>
    satyaki>create or replace function pipe_buff(e_sal in number)
      2  return d_rec
      3  pipelined
      4  is
      5    cursor c1
      6    is
      7      select d_obj(
      8                    ename||' Joined On '||to_char(hiredate,'DD-MON-YYYY hh24:mi:ss')
      9                  ) str
    10      from emp
    11      where sal > e_sal;
    12     
    13   r1 c1%rowtype;
    14  begin
    15    for r1 in c1
    16    loop
    17      pipe row(r1.str);
    18    end loop;
    19    return;
    20  end;
    21  /
    Function created.
    Elapsed: 00:00:01.69
    satyaki>
    satyaki>
    satyaki>
    satyaki>create or replace procedure gen_cur_pipe(
      2                                            s_sal in number,
      3                                            rc in out sys_refcursor
      4                                          )
      5  is  
      6    str1  varchar2(500);
      7  begin  
      8    str1 := 'select *           
      9             from table(cast(pipe_buff('||s_sal||') as d_rec))';           
    10  
    11   open rc for str1;  
    12  exception  
    13    when others then    
    14      dbms_output.put_line(sqlerrm);
    15  end;
    16  /
    Procedure created.
    Elapsed: 00:00:00.05
    satyaki>
    satyaki>
    satyaki>
    satyaki>create table test_dual
      2    (
      3      dummy    varchar2(310)
      4    );
    Table created.
    Elapsed: 00:00:00.10
    satyaki>
    satyaki>
    satyaki>
    satyaki>declare   
      2    rec_x test_dual%rowtype;   
      3    w sys_refcursor;
      4  begin  
      5    dbms_output.enable(1000000);  
      6    gen_cur_pipe(&num,w);  
      7    loop    
      8      fetch w into rec_x;     
      9       exit when w%notfound;             
    10         dbms_output.put_line('Employee Special Deatils: '||rec_x.dummy);
    11    end loop;  
    12    close w;
    13  exception  
    14    when others then    
    15      dbms_output.put_line(sqlerrm);
    16  end;
    17  /
    Enter value for num: 1000
    old   6:   gen_cur_pipe(&num,w);
    new   6:   gen_cur_pipe(1000,w);
    Employee Special Deatils: SATYAKI Joined On 02-NOV-2008 12:07:30
    Employee Special Deatils: SOURAV Joined On 14-SEP-2008 00:07:21
    Employee Special Deatils: WARD Joined On 22-FEB-1981 00:00:00
    Employee Special Deatils: JONES Joined On 02-APR-1981 00:00:00
    Employee Special Deatils: MARTIN Joined On 28-SEP-1981 00:00:00
    Employee Special Deatils: BLAKE Joined On 01-MAY-1981 00:00:00
    Employee Special Deatils: CLARK Joined On 09-JUN-1981 00:00:00
    Employee Special Deatils: SCOTT Joined On 19-APR-1987 00:00:00
    Employee Special Deatils: KING Joined On 17-NOV-1981 00:00:00
    Employee Special Deatils: TURNER Joined On 08-SEP-1981 00:00:00
    Employee Special Deatils: ADAMS Joined On 23-MAY-1987 00:00:00
    Employee Special Deatils: FORD Joined On 03-DEC-1981 00:00:00
    PL/SQL procedure successfully completed.
    Elapsed: 00:00:00.30
    satyaki>
    satyaki>
    satyaki>/
    Enter value for num: 4000
    old   6:   gen_cur_pipe(&num,w);
    new   6:   gen_cur_pipe(4000,w);
    Employee Special Deatils: SATYAKI Joined On 02-NOV-2008 12:07:30
    Employee Special Deatils: SOURAV Joined On 14-SEP-2008 00:07:21
    Employee Special Deatils: CLARK Joined On 09-JUN-1981 00:00:00
    Employee Special Deatils: KING Joined On 17-NOV-1981 00:00:00
    PL/SQL procedure successfully completed.
    Elapsed: 00:00:00.13
    satyaki>I'm not so sure about the performance.
    Regards.
    Satyaki De.

  • Loading data into multiple tables - Bulk collect or regular Fetch

    I have a procedure to load data from one source table into eight different destination tables. The 8 tables have some of the columns of the source table with a common key.
    I have run into a couple of problems and have a few questions where I would like to seek advice:
    1.) Procedure with and without the BULK COLLECT clause took the same time for 100,000 records. I thought I would see improvement in performance when I include BULK COLLECT with LIMIT.
    2.) Updating the Load_Flag in source_table happens only for few records and not all. I had expected all records to be updated
    3.) Are there other suggestions to improve the performance? or could you provide links to other posts or articles on the web that will help me improve the code?
    Notes:
    1.) 8 Destination tables have at least 2 Million records each, have multiple indexes and are accessed by application in Production
    2.) There is an initial load of 1 Million rows with a subsequent daily load of 10,000 rows. Daily load will have updates for existing rows (not shown in code structure below)
    The structure of the procedure is as follows
    Declare
    dest_type is table of source_table%ROWTYPE;
    dest_tab dest_type ;
    iCount NUMBER;
    cursor source_cur is select * from source_table FOR UPDATE OF load_flag;
    BEGIN
    OPEN source_cur;
    LOOP
    FETCH source_cur -- BULK COLLECT
    INTO dest_tab -- LIMIT 1000
    EXIT WHEN source_cur%NOTFOUND;
    FOR i in dest_tab.FIRST .. dest_tab.LAST LOOP
    <Insert into app_tab1 values key, col12, col23, col34 ;>
    <Insert into app_tab2 values key, col15, col29, col31 ;>
    <Insert into app_tab3 values key, col52, col93, col56 ;>
    UPDATE source_table SET load_flag = 'Y' WHERE CURRENT OF source_cur ;
    iCount := iCount + 1 ;
    IF iCount = 1000 THEN
    COMMIT ;
    iCount := 0 ;
    END IF;
    END LOOP;
    END LOOP ;
         COMMIT ;
    END ;
    Edited by: user11368240 on Jul 14, 2009 11:08 AM

    Assuming you are on 10g or later, the PL/SQL compiler generates the bulk fetch for you automatically, so your code is the same as (untested):
    DECLARE
        iCount NUMBER;
        CURSOR source_cur is select * from source_table FOR UPDATE OF load_flag;
    BEGIN
        OPEN source_cur;
        FOR r IN source_cur
        LOOP
            <Insert into app_tab1 values key, col12, col23, col34 ;>
            <Insert into app_tab2 values key, col15, col29, col31 ;>
            <Insert into app_tab3 values key, col52, col93, col56 ;>
            UPDATE source_table SET load_flag = 'Y' WHERE CURRENT OF source_cur ;
            iCount := iCount + 1 ;
            IF iCount = 1000 THEN
                COMMIT ;
                iCount := 0 ;
            END IF;
            END LOOP;
        COMMIT ;
    END ;However most of the benefit of bulk fetching would come from using the array with a FORALL expression, which the PL/SQL compiler can't automate for you.
    If you are fetching 1000 rows at a time, purely from a code simplification point of view you could lose iCount and the IF...COMMIT...END IF and just commit each time after looping through the 1000-row array.
    However I'm not sure how committing every 1000 rows helps restartability, even if your real code has a WHERE clause in the cursor so that it only selects rows with load_flag = 'N' or whatever. If you are worried that it will roll back all your hard work on failure, why not just commit in your exception handler?

  • Want to merge data into a table containing 10 million rows

    Can somebody suggest me a fast and optimized way to merge data into the table.The source table contains 1 million data.

    Hi,
    use merge!
    Another option, create a new table as CTAS from target and source.
    Herald ten Dam
    http://htendam.wordpress.com

  • COLLECT into table of VARCHAR2 giving ORA-22814 error

    Hello,
    I am trying to collect a VARCHAR2(5 CHAR) column into a table type of VARCHAR2(5 CHAR) but it gives me the ORA-22814: attribute or element value is larger than specified in type.
    Even if I cast my string to this data type.
    SQL> CREATE OR REPLACE TYPE T_VARCHAR2_5_TAB AS TABLE OF VARCHAR2(5 CHAR);
      2  /
    Type created.
    SQL>
    SQL> DESC site_section_cours;
    Name                                      Null?    Type
    SEQ_SITE_COURS                            NOT NULL NUMBER
    CODE_SESSION                              NOT NULL VARCHAR2(6 CHAR)
    NUMERO_REFERENCE_SECTION_COURS            NOT NULL VARCHAR2(5 CHAR)
    CODE_STATUT_PUBLICATION_PDF               NOT NULL VARCHAR2(2 CHAR)
    CONTROLE_MODIFICATION                     NOT NULL NUMBER
    SEQ_BAREME_NOTES                                   NUMBER
    SQL>
    SQL> SELECT CAST(
      2              COLLECT(
      3              sisc.numero_reference_section_cours
      4              ORDER BY sisc.code_session, sisc.numero_reference_section_cours
      5              )
      6              AS t_varchar2_5_tab
      7           ) AS lov
      8  FROM   site_section_cours sisc;
              COLLECT(
    ERROR at line 2:
    ORA-22814: attribute or element value is larger than specified in type
    SQL>
    SQL> SELECT CAST(
      2              COLLECT(
      3              CAST(
      4                sisc.numero_reference_section_cours AS VARCHAR2 (5 CHAR)
      5              )
      6              ORDER BY sisc.code_session, sisc.numero_reference_section_cours
      7              )
      8              AS t_varchar2_5_tab
      9           ) AS lov
    10  FROM   site_section_cours sisc;
              COLLECT(
    ERROR at line 2:
    ORA-22814: attribute or element value is larger than specified in type What am I missing?
    Thanks
    Bruno

    A new test: try to collect into 10 and 20 char table type.
    Not working with 10 but working with 20.
    SQL> SELECT CAST(
      2              COLLECT(
      3              sisc.numero_reference_section_cours
      4              ORDER BY sisc.code_session, sisc.numero_reference_section_cours
      5              )
      6              AS t_varchar2_10_tab
      7           ) AS lov
      8  FROM   site_section_cours sisc;
              COLLECT(
    ERROR at line 2:
    ORA-22814: attribute or element value is larger than specified in type
    SQL>
    SQL> SELECT CAST(
      2              COLLECT(
      3              sisc.numero_reference_section_cours
      4              ORDER BY sisc.code_session, sisc.numero_reference_section_cours
      5              )
      6              AS t_varchar2_20_tab
      7           ) AS lov
      8  FROM   site_section_cours sisc;
    LOV                                                                            
    T_VARCHAR2_20_TAB('10001', '10003', '10004', '10016', '10018', '10019', '10020',
    '10022', '10025', '10028', '10029', '10030', '10031', '10032', '10039', '10040'
    , '10041', '10003', '21000', '21001', '21002', '21004', '21005', '21006', '21007
    ', '21008', '21009', '21010', '82001', '11972', '11986', '10018', '10019')      Bruno

  • I have and existing collection.  How can I merge images in a Quick Collection into the existing one?

    I wish to add images to an existing collection.  Currently I want to add images in a Quick Collection into an already named collection.  I am using LR3.  How do I do that?

    Select and then right-click the collection that you want the images added into. Select <Set as Target Collection>. A "+" sign appears besides this collection.
    Then select your Quick Collection (or whatever images you want to add to this collection) in the Grid Mode. Click Ctrl/Cmd + A to select all images in this collection. Then press letter "B" on your keyboard. That will add all these images to your target selection.
    WW

  • Merge Two Rows of a table to One row but into two columns

    Hi
    I Am struck in writing a query to merge two rows into two columns of one row.
    Here is the Sample data i am working with,
    Col 1     Col 2     Col3 Col4 Col Col6
    5000     573-3000 2     0     Phone      
    5000     573-3036 1     0          Fax
    5000     893-5703 3     0     WOrk      
    3000     232-5656     1     0     Phone     
    3000     353-5656     2     0          FAx
    Here Col,Col3,Col4 form the Key.
    now wht i am trying to do is to Merge these type of rows put them into Columns P,F,W,E respectively to achive a Structure as below
    Col1      P     F     W
    5000     573-3000      573-3036      893-5703
    3000     232-5656     353-5656     
    Can you please help me how could i do this.
    I am pretty ordinary at writing SQL's.
    Thanks a Lot in Advance
    Message was edited by:
    Sreebhushan

    Search the forum for PIVOT and you'll find plenty of examples.

  • Using Bulk operations for INSERT into destination table and delete from src

    Hi,
    Is there any way to expediate the process of data movement?
    I have a source set of tables (with its pk-fk relations) and a destination set of tables.
    Currently my code as of now, is pickin up the single record in cursor from the parentmost table, and then moving the data from other respecitve tables. But this is happening one by one... Is there any way I can make this take less time?
    If I use bulk insert and collections, i will not be able to use the DELETE in the same block for same source record.
    Thanks
    Regards
    Abhivyakti

    Abhivyakti
    I'm not 100% sure how your code flows from what you've stated, but generally you should try and avoid cursor FOR LOOPS and possibly BULK COLLECTING.
    I always follow the sequence in terms of design:
    1. Attempt to use bulk INSERTS, UPDATES and/or DELETES first and foremost. (include MERGE as well!)
    2. If one cannot possibly do the above then USE BULK COLLECTIONS using a combination of RETURNING INTO's and
    FORALL's.
    However, before you follow this method and if you relatively new to Oracle PL/SQL,
    share the reason you cannot follow the first method on this forum, and you're bound to find some
    help with sticking to method one!
    3. If method two is impossible, and there would have to be a seriously good reason for this, then follow the cursor FOR LOOP
    method.
    You can combine BULK COLLECTS with UPDATES and DELETES, but not with INSERTS
    bulk collect into after insert ?
    Another simple example of BULK COLLECTING
    Re: Reading multiple table type objects returned
    P;

  • I have to insert lookup values into parent table remaining items in chiled table can you please any one explain the logic

    CREATE OR REPLACE
    PACKAGE BODY xxcsi_ib_data_ob_ecs_pkg
      v_update_date DATE := SYSDATE;
    PROCEDURE print_log(
        i_message IN VARCHAR2)
    IS
    BEGIN
      -- dbms_output.put_line('Log '||TO_CHAR(sysdate,'DD-MON-YYYY HH24:MI:SS :')||i_message);
      fnd_file.put_line(fnd_file.LOG,'Log '||TO_CHAR(SYSDATE,'DD-MON-YYYY HH24:MI:SS :')||i_message);
    EXCEPTION
    WHEN no_data_found THEN
      NULL;
    WHEN OTHERS THEN
      NULL;
    END;
    PROCEDURE main_prc(
        o_chr_errbuff OUT VARCHAR2 ,
        o_num_retcode OUT NUMBER ,
        i_org_id IN NUMBER)
    IS
      CURSOR cur_get_parent_ib_rec(c_from DATE ,c_to DATE)
      IS
        SELECT
          /*+ index(a CSI_ITEM_INSTANCES_X3)*/
          ---CREATE MODE ITEM
          A.creation_date ,
          A.last_update_date ,
          A.last_oe_order_line_id line_id ,
          A.inventory_item_id ,
          A.instance_id ,
          A.instance_type_code ,
          msib.segment1
        FROM csi_item_instances A ,
          mtl_system_items_b msib
        WHERE 1=1
          --      AND a.instance_id = 33371916
          --AND a.instance_id in (33371920,33371921,33371922,33371923,33371924,33371925,33371926,33371927,33371928,33371929,33371930)
        AND msib.inventory_item_id=A.inventory_item_id
        AND msib.organization_id  =
          (SELECT mp.organization_id
          FROM mtl_parameters mp
          WHERE mp.organization_code = 'IMO'
        -- AND msib.organization_id = 85
        -- and msib.segment1 like '475%'
        --AND msib.segment1 like 'TREX%'
      AND EXISTS
        (SELECT 1
        FROM fnd_lookup_values
        WHERE lookup_type = 'EMR CSI OUTBOUND INTERFACE PSG'
        AND language      = 'US'
        AND lookup_code   = msib.segment1
        --and DESCRIPTION = 'Items to be Interfaced from Oracle EBS to ECS'
      AND A.last_update_date BETWEEN NVL(c_from ,to_date('07-AUG-2014 00:00:00','DD-MON-YYYY HH24:MI:SS')) AND NVL(c_to ,to_date('22-AUG-2014 00:00:00','DD-MON-YYYY HH24:MI:SS'))
      UNION
      SELECT
        /*+ index(a CSI_ITEM_INSTANCES_X3)*/
        ---CREATE MODE SEARCH
        A.creation_date ,
        A.last_update_date ,
        A.last_oe_order_line_id line_id ,
        A.inventory_item_id ,
        A.instance_id ,
        A.instance_type_code ,
        msib.segment1
      FROM csi_item_instances A ,
        mtl_system_items_b msib
      WHERE 1=1
        --AND a.instance_id = 33371916
        --AND a.instance_id in (33371920,33371921,33371922,33371923,33371924,33371925,33371926,33371927,33371928,33371929,33371930)
      AND msib.inventory_item_id=A.inventory_item_id
      AND msib.organization_id  =
        (SELECT mp.organization_id
        FROM mtl_parameters mp
        WHERE mp.organization_code = 'IMO'
        -- AND msib.organization_id = 85
        -- and msib.segment1 like '475%'
        --AND msib.segment1 like 'TREX%'
      AND EXISTS
        (SELECT 1
        FROM fnd_lookup_values
        WHERE lookup_type           = 'EMR CSI OUTBOUND INTERFACE PSG'
        AND language                = 'US'
        AND tag                     ='ALL TREX ITEMS'
        AND SUBSTR(lookup_code,1,4) = SUBSTR(msib.segment1,1,4)
        --and DESCRIPTION = 'Items to be Interfaced from Oracle EBS to ECS'
      AND A.last_update_date BETWEEN NVL(c_from ,to_date('07-AUG-2014 00:00:00','DD-MON-YYYY HH24:MI:SS')) AND NVL(c_to ,to_date('22-AUG-2014 00:00:00','DD-MON-YYYY HH24:MI:SS'))
      UNION
      SELECT
        /*+ index(a CSI_ITEM_INSTANCES_X3)*/
        ---UPDATE MODE ITEM
        A.creation_date ,
        A.last_update_date ,
        A.last_oe_order_line_id line_id ,
        A.inventory_item_id ,
        A.instance_id ,
        A.instance_type_code ,
        msib.segment1
      FROM csi_item_instances A ,
        mtl_system_items_b msib
      WHERE 1=1
        --AND a.instance_id = 33371916
        --AND a.instance_id in (33371920,33371921,33371922,33371923,33371924,33371925,33371926,33371927,33371928,33371929,33371930)
      AND msib.inventory_item_id=A.inventory_item_id
      AND msib.organization_id  =
        (SELECT mp.organization_id
        FROM mtl_parameters mp
        WHERE mp.organization_code = 'IMO'
        -- AND msib.organization_id = 85
        -- and msib.segment1 like '475%'
        --AND msib.segment1 like 'TREX%'
      AND EXISTS
        (SELECT 1
        FROM fnd_lookup_values
        WHERE lookup_type = 'EMR CSI OUTBOUND INTERFACE PSG'
        AND language      = 'US'
        AND lookup_code   = msib.segment1
        --and DESCRIPTION = 'Items to be Interfaced from Oracle EBS to ECS'
      AND A.last_update_date BETWEEN NVL(c_from ,to_date('07-AUG-2014 00:00:00','DD-MON-YYYY HH24:MI:SS')) AND NVL(c_to ,to_date('22-AUG-2014 00:00:00','DD-MON-YYYY HH24:MI:SS'))
      AND EXISTS
        (SELECT
          /*+ index(ct CSI_TRANSACTIONS_U01)*/
          1
        FROM csi_item_instances_h h ,
          csi_transactions ct
        WHERE 1                     =1
        AND ct.transaction_type_id IN (1)
        AND ct.transaction_id       = h.transaction_id
        AND ct.last_update_date BETWEEN NVL(c_from ,to_date('07-AUG-2014 00:00:00','DD-MON-YYYY HH24:MI:SS')) AND NVL(c_to ,to_date('22-AUG-2014 00:00:00','DD-MON-YYYY HH24:MI:SS'))
        AND A.instance_id =h.instance_id
      UNION
      SELECT
        /*+ index(a CSI_ITEM_INSTANCES_X3)*/
        ---UPDATE MODE SEARCH
        A.creation_date ,
        A.last_update_date ,
        A.last_oe_order_line_id line_id ,
        A.inventory_item_id ,
        A.instance_id ,
        A.instance_type_code ,
        msib.segment1
      FROM csi_item_instances A ,
        mtl_system_items_b msib
      WHERE 1=1
        --AND a.instance_id = 33371916
        --AND a.instance_id in (33371920,33371921,33371922,33371923,33371924,33371925,33371926,33371927,33371928,33371929,33371930)
      AND msib.inventory_item_id=A.inventory_item_id
      AND msib.organization_id  =
        (SELECT mp.organization_id
        FROM mtl_parameters mp
        WHERE mp.organization_code = 'IMO'
        -- AND msib.organization_id = 85
        -- and msib.segment1 like '475%'
        --AND msib.segment1 like 'TREX%'
      AND EXISTS
        (SELECT 1
        FROM fnd_lookup_values
        WHERE lookup_type           = 'EMR CSI OUTBOUND INTERFACE PSG'
        AND language                = 'US'
        AND tag                     ='ALL TREX ITEMS'
        AND SUBSTR(lookup_code,1,4) = SUBSTR(msib.segment1,1,4)
        --and DESCRIPTION = 'Items to be Interfaced from Oracle EBS to ECS'
      AND A.last_update_date BETWEEN NVL(c_from ,to_date('07-AUG-2014 00:00:00','DD-MON-YYYY HH24:MI:SS')) AND NVL(c_to ,to_date('22-AUG-2014 00:00:00','DD-MON-YYYY HH24:MI:SS'))
      AND EXISTS
        (SELECT
          /*+ index(ct CSI_TRANSACTIONS_U01)*/
          1
        FROM csi_item_instances_h h ,
          csi_transactions ct
        WHERE 1                     =1
        AND ct.transaction_type_id IN (1)
        AND ct.transaction_id       = h.transaction_id
        AND ct.last_update_date BETWEEN NVL(c_from ,to_date('07-AUG-2014 00:00:00','DD-MON-YYYY HH24:MI:SS')) AND NVL(c_to ,to_date('22-AUG-2014 00:00:00','DD-MON-YYYY HH24:MI:SS'))
        AND A.instance_id =h.instance_id
      ORDER BY 1 DESC,
        2 ;
      CURSOR cur_get_child_ib_rec(c_instance_id NUMBER)
      IS
        SELECT cir.subject_id
        FROM csi.csi_ii_relationships cir
        WHERE cir.object_id = c_instance_id;
      CURSOR cur_get_outbound_data(c_instance_id NUMBER)
      IS
        SELECT cii.instance_id instance_id,
          cii.instance_number instance_number,
          cii.inventory_item_id inventory_item_id,
          msi.segment1 segment1,       --CONCATENATED_SEGMENTS,
          msi.description description, --DESCRIPTION,
          cii.inv_master_organization_id master_organization_id,
          cii.serial_number serial_number,
          cii.system_id system_id,
          cst.NAME system_name,
          cii.quantity quantity,
          cii.unit_of_measure uom,
          cii.active_start_date active_start_date,
          cii.active_end_date active_end_date,
          cii.install_date install_date,
          cii.object_version_number object_version_number,
          cii.last_vld_organization_id,
          hou.NAME pre_registration_location,
          looh.header_id last_header_id,
          looh.order_number emerson_order_number,
          cii.last_oe_order_line_id order_line_id,
          NVL(lool.actual_shipment_date, lool.fulfillment_date) actual_shipment_date,
          (SELECT DISTINCT pap.email_address
          FROM fnd_user fu ,
            per_all_people_f pap
          WHERE fu.employee_id = pap.person_id
          and sysdate between pap.effective_start_date and nvl(pap.effective_end_date, sysdate)
          AND fu.user_id       = NVL(wdd.created_by,lool.created_by)
          ) email_address,
        (SELECT DISTINCT hp.party_name
        FROM hz_parties hp,
          hz_party_sites hps ,
          hz_party_site_uses hpsu ,
          hz_locations hl
        WHERE hp.party_id     = hps.party_id
        AND hps.location_id   = hl.location_id
        AND hps.party_site_id = hpsu.party_site_id(+)
        AND hps.party_site_id =
          (SELECT hcasa.party_site_id
          FROM apps.hz_cust_acct_sites hcasa
          WHERE hcasa.cust_acct_site_id =
            (SELECT hcsua.cust_acct_site_id
            FROM apps.hz_cust_site_uses hcsua
            WHERE cia.bill_to_address = hcsua.site_use_id
        ) AS "Bill_To_company_name",--------------------------CH-ID-1.1 STARTS-----------
        (SELECT DISTINCT hps.party_site_id
        FROM hz_parties hp,
          hz_party_sites hps ,
          hz_party_site_uses hpsu ,
          hz_locations hl
        WHERE hp.party_id     = hps.party_id
        AND hps.location_id   = hl.location_id
        AND hps.party_site_id = hpsu.party_site_id(+)
        AND hps.party_site_id =
          (SELECT hcasa.party_site_id
          FROM apps.hz_cust_acct_sites hcasa
          WHERE hcasa.cust_acct_site_id =
            (SELECT hcsua.cust_acct_site_id
            FROM apps.hz_cust_site_uses hcsua
            WHERE cia.bill_to_address = hcsua.site_use_id
        ) AS "BILL_TO_party_SITE_ID",
        (SELECT DISTINCT hl.state
        FROM hz_parties hp,
          hz_party_sites hps ,
          hz_party_site_uses hpsu ,
          hz_locations hl
        WHERE hp.party_id     = hps.party_id
        AND hps.location_id   = hl.location_id
        AND hps.party_site_id = hpsu.party_site_id(+)
        AND hps.party_site_id =
          (SELECT hcasa.party_site_id
          FROM apps.hz_cust_acct_sites hcasa
          WHERE hcasa.cust_acct_site_id =
            (SELECT hcsua.cust_acct_site_id
            FROM apps.hz_cust_site_uses hcsua
            WHERE cia.bill_to_address = hcsua.site_use_id
        ) AS "BILL_TO_STATE",
        (SELECT DISTINCT hl.country
        FROM hz_parties hp,
          hz_party_sites hps ,
          hz_party_site_uses hpsu ,
          hz_locations hl
        WHERE hp.party_id     = hps.party_id
        AND hps.location_id   = hl.location_id
        AND hps.party_site_id = hpsu.party_site_id(+)
        AND hps.party_site_id =
          (SELECT hcasa.party_site_id
          FROM apps.hz_cust_acct_sites hcasa
          WHERE hcasa.cust_acct_site_id =
            (SELECT hcsua.cust_acct_site_id
            FROM apps.hz_cust_site_uses hcsua
            WHERE cia.bill_to_address = hcsua.site_use_id
        ) AS "BILL_TO_COUNTRY",
        (SELECT DISTINCT hl.city
        FROM hz_parties hp,
          hz_party_sites hps ,
          hz_party_site_uses hpsu ,
          hz_locations hl
        WHERE hp.party_id     = hps.party_id
        AND hps.location_id   = hl.location_id
        AND hps.party_site_id = hpsu.party_site_id(+)
        AND hps.party_site_id =
          (SELECT hcasa.party_site_id
          FROM apps.hz_cust_acct_sites hcasa
          WHERE hcasa.cust_acct_site_id =
            (SELECT hcsua.cust_acct_site_id
            FROM apps.hz_cust_site_uses hcsua
            WHERE cia.bill_to_address = hcsua.site_use_id
        ) AS "BILL_TO_CITY",
        (SELECT DISTINCT hl.address1
        FROM hz_parties hp,
          hz_party_sites hps ,
          hz_party_site_uses hpsu ,
          hz_locations hl
        WHERE hp.party_id     = hps.party_id
        AND hps.location_id   = hl.location_id
        AND hps.party_site_id = hpsu.party_site_id(+)
        AND hps.party_site_id =
          (SELECT hcasa.party_site_id
          FROM apps.hz_cust_acct_sites hcasa
          WHERE hcasa.cust_acct_site_id =
            (SELECT hcsua.cust_acct_site_id
            FROM apps.hz_cust_site_uses hcsua
            WHERE cia.bill_to_address = hcsua.site_use_id
        ) AS "BILL_TO_LOCATION",
        (SELECT DISTINCT hp.party_name
        FROM hz_parties hp,
          hz_party_sites hps,
          hz_party_site_uses hpsu,
          hz_locations hl
        WHERE hp.party_id     = hps.party_id
        AND hps.location_id   = hl.location_id
        AND hps.party_site_id = hpsu.party_site_id(+)
        AND hps.party_site_id =
          (SELECT hcasa.party_site_id
          FROM apps.hz_cust_acct_sites hcasa
          WHERE hcasa.cust_acct_site_id =
            (SELECT hcsua.cust_acct_site_id
            FROM apps.hz_cust_site_uses hcsua
            WHERE cia.ship_to_address = hcsua.site_use_id
        ) AS "Ship_to_company_name",
        (SELECT DISTINCT hps.party_site_id
        FROM hz_parties hp,
          hz_party_sites hps ,
          hz_party_site_uses hpsu ,
          hz_locations hl
        WHERE hp.party_id     = hps.party_id
        AND hps.location_id   = hl.location_id
        AND hps.party_site_id = hpsu.party_site_id(+)
        AND hps.party_site_id =
          (SELECT hcasa.party_site_id
          FROM apps.hz_cust_acct_sites hcasa
          WHERE hcasa.cust_acct_site_id =
            (SELECT hcsua.cust_acct_site_id
            FROM apps.hz_cust_site_uses hcsua
            WHERE cia.bill_to_address = hcsua.site_use_id
        ) AS "SHIP_TO_party_SITE_ID",
        (SELECT DISTINCT hl.state
        FROM hz_parties hp,
          hz_party_sites hps ,
          hz_party_site_uses hpsu ,
          hz_locations hl
        WHERE hp.party_id     = hps.party_id
        AND hps.location_id   = hl.location_id
        AND hps.party_site_id = hpsu.party_site_id(+)
        AND hps.party_site_id =
          (SELECT hcasa.party_site_id
          FROM apps.hz_cust_acct_sites hcasa
          WHERE hcasa.cust_acct_site_id =
            (SELECT hcsua.cust_acct_site_id
            FROM apps.hz_cust_site_uses hcsua
            WHERE cia.bill_to_address = hcsua.site_use_id
        ) AS "SHIP_TO_STATE",
        (SELECT DISTINCT hl.country
        FROM hz_parties hp,
          hz_party_sites hps ,
          hz_party_site_uses hpsu ,
          hz_locations hl
        WHERE hp.party_id     = hps.party_id
        AND hps.location_id   = hl.location_id
        AND hps.party_site_id = hpsu.party_site_id(+)
        AND hps.party_site_id =
          (SELECT hcasa.party_site_id
          FROM apps.hz_cust_acct_sites hcasa
          WHERE hcasa.cust_acct_site_id =
            (SELECT hcsua.cust_acct_site_id
            FROM apps.hz_cust_site_uses hcsua
            WHERE cia.bill_to_address = hcsua.site_use_id
        ) AS "SHIP_TO_COUNTRY",
        (SELECT DISTINCT hl.city
        FROM hz_parties hp,
          hz_party_sites hps ,
          hz_party_site_uses hpsu ,
          hz_locations hl
        WHERE hp.party_id     = hps.party_id
        AND hps.location_id   = hl.location_id
        AND hps.party_site_id = hpsu.party_site_id(+)
        AND hps.party_site_id =
          (SELECT hcasa.party_site_id
          FROM apps.hz_cust_acct_sites hcasa
          WHERE hcasa.cust_acct_site_id =
            (SELECT hcsua.cust_acct_site_id
            FROM apps.hz_cust_site_uses hcsua
            WHERE cia.bill_to_address = hcsua.site_use_id
        ) AS "SHIP_TO_CITY",
        (SELECT DISTINCT hl.address1
        FROM hz_parties hp,
          hz_party_sites hps ,
          hz_party_site_uses hpsu ,
          hz_locations hl
        WHERE hp.party_id     = hps.party_id
        AND hps.location_id   = hl.location_id
        AND hps.party_site_id = hpsu.party_site_id(+)
        AND hps.party_site_id =
          (SELECT hcasa.party_site_id
          FROM apps.hz_cust_acct_sites hcasa
          WHERE hcasa.cust_acct_site_id =
            (SELECT hcsua.cust_acct_site_id
            FROM apps.hz_cust_site_uses hcsua
            WHERE cia.bill_to_address = hcsua.site_use_id
        ) AS "SHIP_TO_LOCATION",
        (SELECT DISTINCT hl.postal_code
        FROM hz_parties hp,
          hz_party_sites hps ,
          hz_party_site_uses hpsu ,
          hz_locations hl
        WHERE hp.party_id     = hps.party_id
        AND hps.location_id   = hl.location_id
        AND hps.party_site_id = hpsu.party_site_id(+)
        AND hps.party_site_id =
          (SELECT hcasa.party_site_id
          FROM apps.hz_cust_acct_sites hcasa
          WHERE hcasa.cust_acct_site_id =
            (SELECT hcsua.cust_acct_site_id
            FROM apps.hz_cust_site_uses hcsua
            WHERE cia.bill_to_address = hcsua.site_use_id
        ) AS "SHIP_TO_PIN_CODE",
        (SELECT DISTINCT hl.postal_code
        FROM hz_parties hp,
          hz_party_sites hps ,
          hz_party_site_uses hpsu ,
          hz_locations hl
        WHERE hp.party_id     = hps.party_id
        AND hps.location_id   = hl.location_id
        AND hps.party_site_id = hpsu.party_site_id(+)
        AND hps.party_site_id =
          (SELECT hcasa.party_site_id
          FROM apps.hz_cust_acct_sites hcasa
          WHERE hcasa.cust_acct_site_id =
            (SELECT hcsua.cust_acct_site_id
            FROM apps.hz_cust_site_uses hcsua
            WHERE cia.bill_to_address = hcsua.site_use_id
        ) AS "BILL_TO_PIN_CODE",
        (SELECT hcsua.LOCATION
        FROM apps.hz_cust_site_uses_all hcsua
        WHERE cia.ship_to_address = hcsua.site_use_id
        ) "SHIP_TO_NUMBER",
        (SELECT hcsua.LOCATION
        FROM apps.hz_cust_site_uses_all hcsua
        WHERE cia.bill_to_address = hcsua.site_use_id
        ) "BILL_TO_NUMBER",
        (SELECT DISTINCT hca.account_number
        FROM hz_cust_accounts hca
        WHERE hca.cust_account_id =
          (SELECT hcasa.cust_account_id
          FROM apps.hz_cust_acct_sites hcasa
          WHERE hcasa.cust_acct_site_id =
            (SELECT hcsua.cust_acct_site_id
            FROM apps.hz_cust_site_uses hcsua
            WHERE cia.bill_to_address = hcsua.site_use_id
        )AS "CUSTOMER_NUMBER", --------------------------CH-ID-1.1 ENDS -----------
        (SELECT civ.attribute_value
        FROM csi_iea_values civ,
          csi_i_extended_attribs ciea
        WHERE civ.attribute_id  = ciea.attribute_id
        AND ciea.attribute_code = '011 LICENSE NUMBER'
        AND civ.instance_id     = cii.instance_id
        ) AS "EA_LICENSE_NUMBER",
        (SELECT civ.attribute_value
        FROM csi_iea_values civ,
          csi_i_extended_attribs ciea
        WHERE civ.attribute_id  = ciea.attribute_id
        AND ciea.attribute_code = 'VA_SALES_ORDER_NUMBER'
        AND civ.instance_id     = cii.instance_id
        ) AS "EA_VA_SALES_ORDER_NUM",
        (SELECT NAME
        FROM hr_all_organization_units
        WHERE organization_id = cii.inv_master_organization_id
        ) master_organization_name
      FROM csi_item_instances cii,
        csi_systems_tl cst,
        --    MTL_SYSTEM_ITEMS_VL MSIKFV,
        --    MTL_SYSTEM_ITEMS MSI,
        mtl_system_items_b msi,
        hr_all_organization_units hou,
        oe_order_lines lool,
        oe_order_headers looh,
        wsh_delivery_details wdd,
        csi_i_parties cip,
        csi_ip_accounts cia
      WHERE cii.last_vld_organization_id = msi.organization_id
      AND cii.inventory_item_id          = msi.inventory_item_id
        --  AND CII.LAST_VLD_ORGANIZATION_ID   = MSIKFV.ORGANIZATION_ID
        --  AND CII.INVENTORY_ITEM_ID          = MSIKFV.INVENTORY_ITEM_ID
      AND hou.organization_id(+)    = cii.last_vld_organization_id
      AND cii.last_oe_order_line_id = lool.line_id
      AND lool.header_id            = looh.header_id
      AND cii.last_oe_order_line_id = wdd.source_line_id
        --      AND WDD.SOURCE_LINE_ID             = LOOL.LINE_ID
        --      AND WDD.SOURCE_HEADER_ID           = LOOH.HEADER_ID
      AND cii.instance_id               = cip.instance_id
      AND cii.system_id                 = cst.system_id(+)
      AND cip.party_source_table        = 'HZ_PARTIES'
      AND cip.relationship_type_code    = 'OWNER'
      AND cip.instance_party_id         = cia.instance_party_id
      AND cia.relationship_type_code(+) = 'OWNER'
      AND cii.instance_status_id        = 1052
      AND cst.language(+)               = 'US'
      AND cii.instance_id               = c_instance_id;
      CURSOR cur_get_ib_warranty (c_instance_id NUMBER)
      IS
        SELECT kh.contract_number,
          kh.scs_code,
          kh.start_date,
          kh.end_date,
          (kh.end_date-kh.start_date) duration,
          clet.NAME coverage_name,
          clet.item_description coverage_desc,
          b.segment1 service_name,
          t.description service_desc
        FROM okc_k_headers_b kh,
          okc_k_lines_b kl,
          okc_k_items ki,
          csi_item_instances c,
          mtl_system_items_b i,
          okc_k_lines_b cleb,
          okc_k_lines_tl clet,
          okc_k_items ki1,
          mtl_system_items_b_kfv b,
          mtl_system_items_tl t
        WHERE kh.contract_number_modifier IS NULL
        AND kh.ID                          = kl.dnz_chr_id
        AND kh.ID                          = ki.dnz_chr_id
        AND kl.ID                          = ki.cle_id
        AND ki.jtot_object1_code          IN ('OKX_CUSTPROD')
        AND c.last_vld_organization_id     = i.organization_id
        AND ki.object1_id1                 = TO_CHAR(c.instance_id)
        AND c.inventory_item_id            = i.inventory_item_id
        AND kl.cle_id                      = cleb.cle_id
        AND cleb.ID                        = clet.ID
        AND clet.language               = userenv('LANG')
        AND cleb.lse_id                   IN (2,15,20)
        AND cleb.cle_id                    = ki1.cle_id
        AND b.inventory_item_id            = t.inventory_item_id
        AND b.organization_id              = t.organization_id
        AND t.language                     = userenv('LANG')
        AND to_number(ki1.object1_id1)     = b.inventory_item_id
        AND to_number(ki1.object1_id2)     = b.organization_id
        AND c.instance_id                  = c_instance_id;
      --v1.2 comment ends
      CURSOR cur_get_to_date( c_req_id NUMBER,c_conc_prog_id NUMBER)
      IS
        SELECT requested_start_date
        FROM fnd_concurrent_requests
        WHERE request_id          = c_req_id
        AND concurrent_program_id = c_conc_prog_id;
      /*Record Type Declaration*/
    TYPE ib_ecs_dat_record
    IS
      record
        instance_id csi_item_instances.instance_id%TYPE,
        instance_number csi_item_instances.instance_number%TYPE,
        inventory_item_id csi_item_instances.inventory_item_id%TYPE,
        segment1 mtl_system_items_b.segment1%TYPE,
        description mtl_system_items_b.description%TYPE,
        master_organization_id csi_item_instances.inv_master_organization_id%TYPE,
        serial_number csi_item_instances.serial_number%TYPE,
        system_id csi_item_instances.system_id%TYPE,
        system_name csi_systems_tl.NAME%TYPE,
        quantity csi_item_instances.quantity%TYPE,
        uom csi_item_instances.unit_of_measure%TYPE,
        active_start_date csi_item_instances.active_start_date%TYPE,
        active_end_date csi_item_instances.active_end_date%TYPE,
        install_date csi_item_instances.install_date%TYPE,
        obj_version_num csi_item_instances.object_version_number%TYPE,
        last_vld_organization_id csi_item_instances.last_vld_organization_id%TYPE,
        pre_registration_location VARCHAR2(500),
        order_header_id oe_order_headers_all.header_id%TYPE,
        order_number oe_order_headers_all.order_number%TYPE,
        order_line_id csi_item_instances.last_oe_order_line_id%TYPE,
        actual_shipment_date oe_order_lines_all.actual_shipment_date%TYPE,
        email_address per_all_people_f.email_address%TYPE,
        bill_to_company_name hz_parties.party_name%TYPE,
        bill_to_site_id hz_party_sites.party_site_id%TYPE,
        bill_to_state hz_locations.state%TYPE,
        bill_to_country hz_locations.country%TYPE,
        bill_to_city hz_locations.city%TYPE,
        bill_to_location hz_locations.address1%TYPE,
        ship_to_company_name hz_parties.party_name%TYPE,
        ship_to_site_id hz_party_sites.party_site_id%TYPE,
        ship_to_state hz_locations.state%TYPE,
        ship_to_country hz_locations.country%TYPE,
        ship_to_city hz_locations.city%TYPE,
        ship_to_location hz_locations.address1%TYPE,
        ship_to_pin_code hz_locations.postal_code%TYPE,
        bill_to_pin_code hz_locations.postal_code%TYPE,
        ship_to_number hz_cust_site_uses_all.LOCATION%TYPE,
        bill_to_number hz_cust_site_uses_all.LOCATION%TYPE,
        customer_number hz_cust_accounts.account_number%TYPE,
        ea_license_number csi_iea_values.attribute_value%TYPE,
        ea_va_sales_order_num csi_iea_values.attribute_value%TYPE,
        master_organization_name hr_all_organization_units.NAME%TYPE );
    TYPE tab_typ_ib_ecs_dat
    IS
      TABLE OF ib_ecs_dat_record INDEX BY binary_integer;
    TYPE ib_parent_dat_record
    IS
      record
        creation_date DATE,
        last_update_date DATE,
        order_line_id csi_item_instances.last_oe_order_line_id%TYPE,
        inventory_item_id csi_item_instances.inventory_item_id%TYPE,
        instance_id csi_item_instances.instance_id%TYPE,
        instance_type_code csi_item_instances.instance_type_code%TYPE,
        segment1 mtl_system_items_b.segment1%TYPE );
    TYPE tab_typ_ib_parent_dat
    IS
      TABLE OF ib_parent_dat_record INDEX BY binary_integer;
      --/*Record Type Declaration*/
      --      TYPE parent_ib_record IS RECORD (
      --         creation_date           csi_item_instances.creation_date%TYPE,
      --         last_update_date        csi_item_instances.last_update_date%TYPE,
      --         inventory_item_id       csi_item_instances.inventory_item_id%TYPE,
      --         instance_id             csi_item_instances.instance_id%TYPE,
      --         instance_type_code      csi_item_instances.instance_type_code%TYPE,
      --         segment1                mtl_system_items_b.segment1%type
      --      TYPE tab_typ_par_ib_collection IS TABLE OF parent_ib_record
      --         INDEX BY BINARY_INTEGER;
      --      tab_par_ib_rec                   tab_typ_par_ib_collection;
      v_segment1 mtl_system_items_b.segment1%TYPE;
      v_request_id        NUMBER := fnd_global.conc_request_id;
      v_conc_prog_id      NUMBER := fnd_global.conc_program_id;
      v_created_by        NUMBER := fnd_profile.VALUE('USER_ID');
      v_last_update_login NUMBER := fnd_global.login_id;
      v_to DATE                  := SYSDATE;
      v_from DATE                := SYSDATE-100;
      v_count NUMBER             := NULL;
      --       v_header_id                        NUMBER := NULL;
      --       v_line_id                          NUMBER := NULL;
      --       v_org_id                           NUMBER := NULL;
      --       v_ship_from_org_id                 NUMBER := NULL;
      --v1.2 begin
      --       v_master_org_id                    NUMBER := NULL;
      --       v_item_type                        VARCHAR2(100) := null;
      --       v_top_model_line_id                NUMBER := NULL;
      --       v_serial_tag_number                VARCHAR2(100) := null;
    TYPE tbl_req_start_date_type
    IS
      TABLE OF DATE INDEX BY pls_integer;
      tbl_req_start_date tbl_req_start_date_type;
      --v1.2 ends
      --v1.3 starts
      --      v_flow_status_code                  VARCHAR2(100) := null;
      --      v_line_number                       NUMBER        := NULL;
      --      v_shipment_number                   NUMBER        := NULL;
      --      v_option_number                     NUMBER        := NULL;
      --      v_component_number                  NUMBER        := NULL;
      --      v_service_number                    NUMBER       := NULL;
      --v1.3 ends
      --      v_model_string                      VARCHAR2(100) := NULL;
      --      v_end_cust                          NUMBER := NULL;
      --      v_end_cust_site_id                  NUMBER := NULL;
      --      v_location_type_code                VARCHAR2(100) := null;
      --      v_location_id                       NUMBER := NULL;
      --      v_tag                               VARCHAR2(100) := NULL;
      --      v_inventory_item_status             VARCHAR2(100) := NULL;
      --      v_serial_number                     VARCHAR2(100) := NULL;
      --      v_serial_return                     VARCHAR2(200) := NULL;
      --rec_ext_attr      Rec_Ext_Attr_type ;
      v_ret_error_message VARCHAR2(2000):= NULL;
      v_ret_error_flag    VARCHAR2(1)   := NULL;
      v_error_message     VARCHAR2(2000):= NULL;
      v_error_flag        VARCHAR2(1)   := NULL;
      v_error_at          VARCHAR2(100) := NULL;
      --        v_to1                               DATE   := sysdate;
      --        v_from1                             DATE   := sysdate-45;
      tab_ib_parent_dat tab_typ_ib_parent_dat;
      tab_ib_ecs_dat tab_typ_ib_ecs_dat;
      tab_ib_ecs_dat_c tab_typ_ib_ecs_dat;
    BEGIN
      print_log('*********************************************************************');
      print_log('print log message 01');
      print_log('Process Starts... : '||to_date(SYSDATE,'DD-MON-YYYY HH24:MI:SS'));
      v_error_at := 'Start of the process';
      fnd_client_info.set_org_context(i_org_id);
      --  v1.2 begins, to get from date ----==----
      BEGIN
        print_log('print log message 02');
        --OPEN  get_from_date( v_request_id,v_conc_prog_id);
        --FETCH get_from_date INTO   v_from;
        --CLOSE get_from_date;
        v_error_at := 'main Process/ before from ';
        --        v_from := Sysdate-15;
        v_from := SYSDATE-45;
        --Added v1.4 ,AND    ARGUMENT1 = i_org_id
        SELECT
          /*+ index(a FND_CONCURRENT_REQUESTS_N6) index(a FND_CONCURRENT_REQUESTS_N7)*/
          requested_start_date BULK COLLECT
        INTO tbl_req_start_date
        FROM fnd_concurrent_requests
        WHERE request_id            < v_request_id
        AND concurrent_program_id   = v_conc_prog_id
        AND argument1               = i_org_id
        AND status_code             ='C'
        AND phase_code              ='C';
        v_error_at                 := 'main Process/ after from selection ';
        IF tbl_req_start_date.count >0 THEN
          FOR i                    IN tbl_req_start_date.FIRST .. tbl_req_start_date.LAST
          LOOP
            IF v_from < tbl_req_start_date(i) THEN
              v_from := tbl_req_start_date(i);
              print_log( 'Tabel Req StartDate : '||tbl_req_start_date(i));
              print_log( 'In the Loop VFrom : '||v_from);
            END IF;
          END LOOP;
        END IF;
        v_error_at := 'main Process/ after from Loop ';
        print_log( 'Out the loop v_from is : '||v_from);
      EXCEPTION
      WHEN no_data_found THEN
        print_log('Error in  from_date process exception : '||sqlerrm);
        print_log('Error at : '||v_error_at);
        v_from := NULL;
      WHEN OTHERS THEN
        print_log('Error in  from_date process exception : '||sqlerrm);
        print_log('Error at : '||v_error_at);
        v_from := NULL;
      END;
      -- v1.2 ends---==----
      print_log('print log message 03');
      BEGIN
        OPEN cur_get_to_date ( v_request_id,v_conc_prog_id);
        FETCH cur_get_to_date INTO v_to;
        CLOSE cur_get_to_date;
        --v1.3 starts
        v_update_date := v_to -(1/86400);
        --v1.3 ends
        v_error_at := 'main Process/ after from and to date';
        print_log('v_from1... : '||TO_CHAR(v_from,'DD-MON-YYYY HH24:MI:SS'));
        print_log('v_to1  ... : '||TO_CHAR(v_to ,'DD-MON-YYYY HH24:MI:SS'));
        --v1.3 starts
        print_log('Updated v_to  ... : '||TO_CHAR(v_update_date ,'DD-MON-YYYY HH24:MI:SS'));
        --v1.3 ends
      EXCEPTION
      WHEN no_data_found THEN
        print_log('Error in  main process1 : '||sqlerrm);
        print_log('Error at : '||v_error_at);
      WHEN OTHERS THEN
        print_log('Error in  main process1 : '||sqlerrm);
        print_log('Error at : '||v_error_at);
      END;
      BEGIN
        print_log('print log message 04');
        OPEN cur_get_parent_ib_rec(v_from ,v_to);
        LOOP
          print_log('After Loop Get Records v_from... : '||TO_CHAR(v_from,'DD-MON-YYYY HH24:MI:SS'));
          print_log('After Loop Get Records v_to  ... : '||TO_CHAR(v_to ,'DD-MON-YYYY HH24:MI:SS'));
          FETCH cur_get_parent_ib_rec BULK COLLECT INTO tab_ib_parent_dat;
          print_log('Parent Instance first : ');
          --  FOR i IN 1 .. tab_ib_parent_dat.COUNT
          print_log('print log message 05');
          FOR i IN tab_ib_parent_dat.FIRST .. tab_ib_parent_dat.LAST
          LOOP
            BEGIN
              print_log('Parent Instance : '||tab_ib_parent_dat(i).instance_id);
              print_log('====================================================================');
              v_error_at       := 'main Process/ start of the loop';
              v_ret_error_flag := NULL;
              v_segment1       := NULL;
            EXCEPTION
            WHEN no_data_found THEN
              print_log('Error in  main process exception1 : '||sqlerrm);
              print_log('Error at : '||v_error_at);
            WHEN OTHERS THEN
              print_log('Error in  main process exception1 : '||sqlerrm);
              print_log('Error at : '||v_error_at);
            END;
            OPEN cur_get_outbound_data(tab_ib_parent_dat(i).instance_id);
            LOOP
              FETCH cur_get_outbound_data BULK COLLECT INTO tab_ib_ecs_dat;
              --FOR j IN 1 .. tab_ib_ecs_dat.COUNT
              FOR j IN tab_ib_ecs_dat.FIRST .. tab_ib_ecs_dat.LAST
              LOOP
                BEGIN
                BEGIN
                     SELECT COUNT(1)
                      INTO v_count
                      FROM apps.xxcsi_trex_ob_ecs_mhm
                      WHERE instance_id  = NVL(tab_ib_ecs_dat_c(j).instance_id,'');
                    EXCEPTION
                    WHEN OTHERS THEN
                      v_count := 0;
                    END;
                    print_log('v_count : '||v_count);
                    IF v_count = 0 THEN
                  --        print_log('PARENT_DAT: '||NVL(tab_ib_ecs_dat(j).instance_id);
            print_log('print log message 06');
                  INSERT
                  INTO xxcsi_trex_ob_ecs_mhm
                      instance_id,
                      instance_number,
                      inventory_item_id,
                      unit,
                      unit_name,
                      master_organization_id,
                      serial_number,
                      quantity,
                      uom,
                      active_start_date,
                      active_end_date,
                      install_date,
                      object_version_number,
                      last_vld_organization_id,
                      pre_registration_location,
                      order_header_id,
                      order_number,
                      order_line_id,
                      pre_registration_date,
                      pre_registration_operator,
                      bill_to_customer_name,
                      bill_to_site_id ,
                      bill_to_state ,
                      bill_to_country ,
                      bill_to_city ,
                      bill_to_location ,
                      ship_to_customer_name,
                      ship_to_site_id ,
                      ship_to_state ,
                      ship_to_country ,
                      ship_to_city ,
                      ship_to_location,
                      ship_to_pin_code,
                      bill_to_pin_code,
                      ship_to_number,
                      bill_to_number,
                      customer_number,
                      ea_license_number,
                      ea_va_sales_order_number,
                      parent_instance_id,
                      parent_y_n,
                      process_flag,
                      error_code,
                      error_details,
                      request_id,
                      created_by,
                      creation_date,
                      last_updated_by,
                      last_update_date,
                      last_update_login,
                      eai_process_flag,
                      master_organization_name,
                      system_id,
                      system_name
                    VALUES
                      NVL(tab_ib_ecs_dat(j).instance_id,''),
                      NVL(tab_ib_ecs_dat(j).instance_number,''),
                      NVL(tab_ib_ecs_dat(j).inventory_item_id,''),
                      NVL(tab_ib_ecs_dat(j).segment1,''),
                      NVL(tab_ib_ecs_dat(j).description,''),
                      NVL(tab_ib_ecs_dat(j).master_organization_id,''),
                      NVL(tab_ib_ecs_dat(j).serial_number,''),
                      NVL(tab_ib_ecs_dat(j).quantity,''),
                      NVL(tab_ib_ecs_dat(j).uom,''),
                      NVL(tab_ib_ecs_dat(j).active_start_date,''),
                      NVL(tab_ib_ecs_dat(j).active_end_date,''),
                      NVL(tab_ib_ecs_dat(j).install_date,''),
                      NVL(tab_ib_ecs_dat(j).obj_version_num,''),
                      NVL(tab_ib_ecs_dat(j).last_vld_organization_id,''),
                      NVL(tab_ib_ecs_dat(j).pre_registration_location,''),
                      NVL(tab_ib_ecs_dat(j).order_header_id,''),
                      NVL(tab_ib_ecs_dat(j).order_number,''),
                      NVL(tab_ib_ecs_dat(j).order_line_id,''),
                      NVL(tab_ib_ecs_dat(j).actual_shipment_date,''),
                      NVL(tab_ib_ecs_dat(j).email_address,''),
                      NVL(tab_ib_ecs_dat(j).bill_to_company_name,''),
                      NVL(tab_ib_ecs_dat(j).bill_to_site_id,''),
                      NVL(tab_ib_ecs_dat(j).bill_to_state,''),
                      NVL(tab_ib_ecs_dat(j).bill_to_country,''),
                      NVL(tab_ib_ecs_dat(j).bill_to_city,''),
                      NVL(tab_ib_ecs_dat(j).bill_to_location,''),
                      NVL(tab_ib_ecs_dat(j).ship_to_company_name,''),
                      NVL(tab_ib_ecs_dat(j).ship_to_site_id,''),
                      NVL(tab_ib_ecs_dat(j).ship_to_state,''),
                      NVL(tab_ib_ecs_dat(j).ship_to_country,''),
                      NVL(tab_ib_ecs_dat(j).ship_to_city,''),
                      NVL(tab_ib_ecs_dat(j).ship_to_location,''),
                      NVL(tab_ib_ecs_dat(j).ship_to_pin_code,''),
                      NVL(tab_ib_ecs_dat(j).bill_to_pin_code,''),
                      NVL(tab_ib_ecs_dat(j).ship_to_number,''),
                      NVL(tab_ib_ecs_dat(j).bill_to_number,''),
                      NVL(tab_ib_ecs_dat(j).customer_number,''),
                      NVL(tab_ib_ecs_dat(j).ea_license_number,''),
                      NVL(tab_ib_ecs_dat(j).ea_va_sales_order_num,''),
                      NULL,
                      'P',
                      'N',
                      NULL,
                      NULL,
                      v_request_id,
                      v_created_by,
                      SYSDATE,
                      v_created_by,
                      SYSDATE,
                      v_last_update_login,
                      'N',
                      NVL(tab_ib_ecs_dat(j).master_organization_name,''),
                      NVL(tab_ib_ecs_dat(j).system_id,''),
                      NVL(tab_ib_ecs_dat(j).system_name,'')
    ELSE
    Update apps.xxcsi_trex_ob_ecs_mhm set 
                    instance_id=NVL(tab_ib_ecs_dat_c(j).instance_id,''),
      instance_number= NVL(tab_ib_ecs_dat_c(j).instance_number,''),
                    inventory_item_id= NVL(tab_ib_ecs_dat_c(j).inventory_item_id,''),
                    unit      = NVL(tab_ib_ecs_dat_c(j).segment1,''),
                    unit_name =  NVL(tab_ib_ecs_dat_c(j).description,''),
                    master_organization_id=NVL(tab_ib_ecs_dat_c(j).master_organization_id,''),
                    --serial_number=NVL(tab_ib_ecs_dat_c(j).serial_number,''),
                    quantity= NVL(tab_ib_ecs_dat_c(j).quantity,''),
                    uom=NVL(tab_ib_ecs_dat_c(j).uom,''),
                    active_start_date= NVL(tab_ib_ecs_dat_c(j).active_start_date,''),
                    active_end_date= NVL(tab_ib_ecs_dat_c(j).active_end_date,''),
                    install_date= NVL(tab_ib_ecs_dat_c(j).install_date,''),
                    object_version_number=NVL(tab_ib_ecs_dat_c(j).obj_version_num,''),
                    last_vld_organization_id= NVL(tab_ib_ecs_dat_c(j).last_vld_organization_id,''),
                    pre_registration_location=NVL(tab_ib_ecs_dat_c(j).pre_registration_location,''),
                    order_header_id=NVL(tab_ib_ecs_dat_c(j).order_header_id,''),
                    order_number= NVL(tab_ib_ecs_dat_c(j).order_number,''),
                    order_line_id=NVL(tab_ib_ecs_dat_c(j).order_line_id,''),
                    pre_registration_date= NVL(tab_ib_ecs_dat_c(j).actual_shipment_date,''),
                    pre_registration_operator= NVL(tab_ib_ecs_dat_c(j).email_address,''),
                    bill_to_customer_name=NVL(tab_ib_ecs_dat_c(j).bill_to_company_name,''),
                    bill_to_site_id = NVL(tab_ib_ecs_dat_c(j).bill_to_site_id,''),
                    bill_to_state = NVL(tab_ib_ecs_dat_c(j).bill_to_state,''),
                    bill_to_country =NVL(tab_ib_ecs_dat_c(j).bill_to_country,''),
                    bill_to_city = NVL(tab_ib_ecs_dat_c(j).bill_to_city,''),
                    bill_to_location =  NVL(tab_ib_ecs_dat_c(j).bill_to_location,''),
                    ship_to_customer_name=NVL(tab_ib_ecs_dat_c(j).ship_to_company_name,''),
                    ship_to_site_id = NVL(tab_ib_ecs_dat_c(j).ship_to_site_id,''),
                    ship_to_state =NVL(tab_ib_ecs_dat_c(j).ship_to_state,''),
                    ship_to_country=NVL(tab_ib_ecs_dat_c(j).ship_to_country,''),
                    ship_to_city =NVL(tab_ib_ecs_dat_c(j).ship_to_city,''),
                    ship_to_location= NVL(tab_ib_ecs_dat_c(j).ship_to_location,''),
      ship_to_pin_code= NVL(tab_ib_ecs_dat_c(j).ship_to_pin_code,''),
      bill_to_pin_code=NVL(tab_ib_ecs_dat_c(j).bill_to_pin_code,''),
      ship_to_number=NVL(tab_ib_ecs_dat_c(j).ship_to_number,''),
      bill_to_number= NVL(tab_ib_ecs_dat_c(j).bill_to_number,''),
      customer_number= NVL(tab_ib_ecs_dat_c(j).customer_number,''),
      ea_license_number= NVL(tab_ib_ecs_dat_c(j).ea_license_number,''),
      ea_va_sales_order_number= NVL(tab_ib_ecs_dat_c(j).ea_va_sales_order_num,''),
      parent_instance_id=NVL(tab_ib_parent_dat(i).instance_id,''),
      parent_y_n='C',
      process_flag='N',
      error_code= NULL,
      error_details= NULL,
      request_id=v_request_id,
      created_by=v_created_by,
      creation_date= SYSDATE,
      last_updated_by=v_created_by,
      last_update_date=SYSDATE,
      last_update_login= v_last_update_login,
      eai_process_flag='Y',
      master_organization_name=NVL(tab_ib_ecs_dat_c(j).master_organization_name,''),
      system_id= NVL(tab_ib_ecs_dat_c(j).system_id,''),
      system_name= NVL(tab_ib_ecs_dat_c(j).system_name,'')
      WHERE instance_id  = NVL(tab_ib_ecs_dat_c(j).instance_id,'');
      END IF; --V_COUNT
                EXCEPTION
                WHEN no_data_found THEN
                  print_log('Error in inserting Parent Instance : '||tab_ib_ecs_dat(j).instance_id||': '||sqlerrm);
                WHEN OTHERS THEN
                  print_log('Error in inserting Parent Instance : '||tab_ib_ecs_dat(j).instance_id||': '||sqlerrm);
                END;
                --      END LOOP;
              END LOOP;
              EXIT
            WHEN cur_get_outbound_data%notfound;
            END LOOP;
            CLOSE cur_get_outbound_data;
            print_log('print log message 07');
            BEGIN
              FOR rec_get_child_ib_rec IN cur_get_child_ib_rec
                tab_ib_parent_dat(i).instance_id
              LOOP
                print_log
                  'cur_get_child_ib_rec : '||tab_ib_parent_dat(i).instance_id
                OPEN cur_get_outbound_data(rec_get_child_ib_rec.subject_id);
                LOOP
                  FETCH cur_get_outbound_data BULK COLLECT INTO tab_ib_ecs_dat_c;
                  --            tab_ib_ecs_dat_c1 := tab_ib_ecs_dat_c;
                  --            FOR k IN 1 .. tab_ib_ecs_dat_c.COUNT
                  FOR k IN tab_ib_ecs_dat_c.FIRST .. tab_ib_ecs_dat_c.LAST
                  LOOP
                    print_log('Child Instance : '||tab_ib_ecs_dat_c(k).instance_id);
                    --        BEGIN
                    BEGIN
                      SELECT COUNT(1)
                      INTO v_count
                      FROM apps.xxcsi_trex_ob_ecs_mhm
                      WHERE instance_id  = NVL(tab_ib_ecs_dat_c(k).instance_id,'');
                    EXCEPTION
                    WHEN OTHERS THEN
                      v_count := 0;
                    END;
                    print_log('v_count : '||v_count);
                    IF v_count = 0 THEN
                      BEGIN
                        INSERT
                        INTO xxcsi_trex_ob_ecs_mhm
                            instance_id,
                            instance_number,
                            inventory_item_id,
                            unit,
                            unit_name,
                            master_organization_id,
                            serial_number,
                            quantity,
                            uom,
                            active_start_date,
                            active_end_date,
                            install_date,
                            object_version_number,
                            last_vld_organization_id,
                            pre_registration_location,
                            order_header_id,
                            order_number,
                            order_line_id,
                            pre_registration_date,
                            pre_registration_operator,
                            bill_to_customer_name,
                            bill_to_site_id ,
                            bill_to_state ,
                            bill_to_country ,
                            bill_to_city ,
                            bill_to_location ,
                            ship_to_customer_name,
                            ship_to_site_id ,
                            ship_to_state ,
                            ship_to_country ,
                            ship_to_city ,
                            ship_to_location ,
                            ship_to_pin_code,
                            bill_to_pin_code,
                            ship_to_number,
                            bill_to_number,
                            customer_number,
                            ea_license_number,
                            ea_va_sales_order_number,
                            parent_instance_id,
                            parent_y_n,
                            process_flag,
                            error_code,
                            error_details,
                            request_id,
                            created_by,
                            creation_date,
                            last_updated_by,
                            last_update_date,
                            last_update_login,
                            eai_process_flag,
                            master_organization_name,
                            system_id,
                            system_name
                          VALUES
                            NVL(tab_ib_ecs_dat_c(k).instance_id,''),
                            NVL(tab_ib_ecs_dat_c(k).instance_number,''),
                            NVL(tab_ib_ecs_dat_c(k).inventory_item_id,''),
                            NVL(tab_ib_ecs_dat_c(k).segment1,''),
                            NVL(tab_ib_ecs_dat_c(k).description,''),
                            NVL(tab_ib_ecs_dat_c(k).master_organization_id,''),
                            NVL(tab_ib_ecs_dat_c(k).serial_number,''),
                            NVL(tab_ib_ecs_dat_c(k).quantity,''),
                            NVL(tab_ib_ecs_dat_c(k).uom,''),
                            NVL(tab_ib_ecs_dat_c(k).active_start_date,''),
                            NVL(tab_ib_ecs_dat_c(k).active_end_date,''),
                            NVL(tab_ib_ecs_dat_c(k).install_date,''),
                            NVL(tab_ib_ecs_dat_c(k).obj_version_num,''),
                            NVL(tab_ib_ecs_dat_c(k).last_vld_organization_id,''),
                            NVL(tab_ib_ecs_dat_c(k).pre_registration_location,''),
                            NVL(tab_ib_ecs_dat_c(k).order_header_id,''),
                            NVL(tab_ib_ecs_dat_c(k).order_number,''),
                            NVL(tab_ib_ecs_dat_c(k).order_line_id,''),
                            NVL(tab_ib_ecs_dat_c(k).actual_shipment_date,''),
                            NVL(tab_ib_ecs_dat_c(k).email_address,''),
                            NVL(tab_ib_ecs_dat_c(k).bill_to_company_name,''),
                            NVL(tab_ib_ecs_dat_c(k).bill_to_site_id,''),
                            NVL(tab_ib_ecs_dat_c(k).bill_to_state,''),
                            NVL(tab_ib_ecs_dat_c(k).bill_to_coun

    The logic is:
    1. Create any new lookup table rows that may be needed
    2. Create new data rows that reference the lookup table
    All you did was post a buch of code. You didn't post ANYTHING that shows how you executed that code or what the result was.
    You need to SHOW US (not tell us):
    1. WHAT you do
    2. HOW you do it
    3. WHAT results you get
    4. WHAT results you expected to get
    The code you posted has some SERIOUS ISSUES. Here are just three of them
    1. You are using BULK COLLECT without a LIMIT clause
    2. You are using unnecessary IF . . .COUNT statements to test collections for values. The FOR clause will simply NOT execute if the collection is empty so the IF statements add unnecessary clutter.
    3. The first loop iterates a collection but sets a single SCALAR value - making that loop totally USELESS
    LOOP
            IF v_from < tbl_req_start_date(i) THEN
              v_from := tbl_req_start_date(i);
              print_log( 'Tabel Req StartDate : '||tbl_req_start_date(i));
              print_log( 'In the Loop VFrom : '||v_from);
            END IF;
          END LOOP;
    That checks EVERY row in the collection and appears to save the MAX value of 'tbl_req_state_date' into the 'v_from' variable.
    What is the point of that?

  • Problem while inserting into a table which has ManyToOne relation

    Problem while inserting into a table *(Files)* which has ManyToOne relation with another table *(Folder)* involving a attribute both in primary key as well as in foreign key in JPA 1.0.
    Relevent Code
    Entities:
    public class Files implements Serializable {
    @EmbeddedId
    protected FilesPK filesPK;
    private String filename;
    @JoinColumns({
    @JoinColumn(name = "folder_id", referencedColumnName = "folder_id"),
    @JoinColumn(name = "uid", referencedColumnName = "uid", insertable = false, updatable = false)})
    @ManyToOne(optional = false)
    private Folders folders;
    public class FilesPK implements Serializable {
    private int fileId;
    private int uid;
    public class Folders implements Serializable {
    @EmbeddedId
    protected FoldersPK foldersPK;
    private String folderName;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "folders")
    private Collection<Files> filesCollection;
    @JoinColumn(name = "uid", referencedColumnName = "uid", insertable = false, updatable = false)
    @ManyToOne(optional = false)
    private Users users;
    public class FoldersPK implements Serializable {
    private int folderId;
    private int uid;
    public class Users implements Serializable {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Integer uid;
    private String username;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "users")
    private Collection<Folders> foldersCollection;
    I left out @Basic & @Column annotations for sake of less code.
    EJB method
    public void insertFile(String fileName, int folderID, int uid){
    FilesPK pk = new FilesPK();
    pk.setUid(uid);
    Files file = new Files();
    file.setFilename(fileName);
    file.setFilesPK(pk);
    FoldersPK folderPk = new FoldersPK(folderID, uid);
         // My understanding that it should automatically handle folderId in files table,
    // but it is not…
    file.setFolders(em.find(Folders.class, folderPk));
    em.persist(file);
    It is giving error:
    Internal Exception: java.sql.SQLException: Field 'folderid' doesn't have a default value_
    Error Code: 1364
    Call: INSERT INTO files (filename, uid, fileid) VALUES (?, ?, ?)_
    _       bind => [hello.txt, 1, 0]_
    It is not even considering folderId while inserting into db.
    However it works fine when I add folderId variable in Files entity and changed insertFile like this:
    public void insertFile(String fileName, int folderID, int uid){
    FilesPK pk = new FilesPK();
    pk.setUid(uid);
    Files file = new Files();
    file.setFilename(fileName);
    file.setFilesPK(pk);
    file.setFolderId(folderId) // added line
    FoldersPK folderPk = new FoldersPK(folderID, uid);
    file.setFolders(em.find(Folders.class, folderPk));
    em.persist(file);
    My question is that is this behavior expected or it is a bug.
    Is it required to add "column_name" variable separately even when an entity has reference to ManyToOne mapping foreign Entity ?
    I used Mysql 5.1 for database, then generate entities using toplink, JPA 1.0, glassfish v2.1.
    I've also tested this using eclipselink and got same error.
    Please provide some pointers.
    Thanks

    Hello,
    What version of EclipseLink did you try? This looks like bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=280436 that was fixed in EclipseLink 2.0, so please try a later version.
    You can also try working around the problem by making both fields writable through the reference mapping.
    Best Regards,
    Chris

  • Apex Application inserting into two tables from two regions in a page

    Hey Guys,
    Fairly new to apex like two days. So please bare with me. I am using apex 4.0.2.00.07.
    I have a page with two regions. The first region has only one row and I have no problems accessing it and inserting those values into the table this is what I used to access one column from that one row APEX_APPLICATION.G_F03(1)
    The second region is an interactive report, to which I have managed to add a checkbox and a textbox.
    1)So if a checkbox has been checked off the row should be inserted
    2) if the textbox has been entered it should replaceone of the values.
    My question is how to access the second region? I started a loop based on the rows in the collection but that is as far as I got.
    FOR idx IN 1..l_collectionTable_name
    loop
    end loop
    Any help would be greatly appreciated?
    Thank you
    Edited by: Aj05 on Aug 2, 2012 2:10 PM

    Hi Phil I used the following code
    <cfquery name="qArrivalDates" datasource="rayannesql">
    SET NOCOUNT ON
    INSERT INTO booking (book_made, book_checkin_date,
    book_checkout_date, book_adults, book_children)
    VALUES('#FORM.book_made#','#FORM.book_checkin_date#','#FORM.book_checkout_date#','#FORM.bo ok_adults#','#FORM.book_children#')
    SELECT SCOPE_IDENTITY() AS theNewId;
    SET NOCOUNT OFF
    </cfquery>
    <cfquery name="qArrivalDates" datasource="rayannesql">
    INSERT INTO Customer( firstname, lastname, address, address2,
    city, state, postalcode, country, phone, mobile, email, notes)
    Values (#qArrivalDates.theNewId# '#FORM.firstname#',
    '#FORM.lastname#', '#FORM.address#', '#FORM.address2#',
    '#FORM.city#', '#FORM.state#', '#FORM.postalcode#',
    '#FORM.country#', '#FORM.phone#', '#FORM.mobile#', '#FORM.email#',
    '#FORM.notes#' )
    </cfquery>
    When I tried to complete the form, I got the following error
    Macromedia][SequeLink JDBC Driver][ODBC
    Socket][Microsoft][SQL Native Client][SQL Server]Incorrect syntax
    near 'Fred'.
    The error occurred in
    C:\Inetpub\wwwroot\rayanne\customerinsertsql.cfm: line 16
    14 : <cfquery name="qArrivalDates"
    datasource="rayannesql">
    15 : INSERT INTO Customer( firstname, lastname, address,
    address2, city, state, postalcode, country, phone, mobile, email,
    notes)
    16 : Values (#qArrivalDates.theNewId# '#FORM.firstname#',
    '#FORM.lastname#', '#FORM.address#', '#FORM.address2#',
    '#FORM.city#', '#FORM.state#', '#FORM.postalcode#',
    '#FORM.country#', '#FORM.phone#', '#FORM.mobile#', '#FORM.email#',
    '#FORM.notes#' )
    17 : </cfquery>

Maybe you are looking for

  • Import ABAP error in ECC6 system copy targert

    Hi Experts,                   I am istalling SAP Ecc 6 in System copy targrt, ABAP import fail in 2/87. I got the error Loading of 'SAPDFACT' import package: ERRORImport Monitor jobs. My OS  Windows 2003 64 bit and Oracle 10.2. Please find the log fi

  • Macbook Pro Retina Boot Camp Issue

    Hi all, I recently purchased a macbook pro with retina display and installed windows 7 on it with boot camp.  Windows 7 on boot camp does not wake on sleep after closing the lid or making it sleep for the second time.  I have tried unplugging, pressi

  • BW Metadata is incomplete error while generating datasources using CTBW

    The variant configuration datasources were created successfully in development system and BI side works fine in dev. We moved the VC datasources to our Quality system. Since our QA system client (500) is different from development (100) ECC system, I

  • 10.1.2.0.2 App Server Release Date?

    Folks, Does anyone know what the expected release date is for the Oracle 10g Application Server Release 2 Version 10.1.2.0.2 (Aka, the one with Forms and Reports services) and the accompanying 10.1.2.0.2 Developer Suite? I would like to get a feel so

  • Calling external Java from ABAP using JCo?

    Does anyone know if one can use JCo to write a server application that can be called from ABAP. We are presently using JCo to communicate from Java to SAP. But we need to call an external Java program from within ABAP. Is this possible? Thanks for an