Order by is not working

Hello,
I'm using FORM 6i and writing the data to Excel Report
I'm passing the string to the Order By clause. But the data is not sorted.
Code is as follows:
procedure test (pi_order IN VARCHAR2)
is
type t_data IS REF CURSOR;
c_data t_data;
l_order_by VARCHAR2(200);
type data_rec IS RECORD (col1 NUMBER(2),
col2 VARCHAR2(100));
r_data data_rec;
BEGIN
IF (pi_order_by IS NULL) THEN
l_order_by := NULL;
ELSE
l_order_by := pi_order_by;
END IF;
OPEN c_data for SELECT COL1, COL2 , pkg1.p2(x, y) col3
FROM table_name
WHERE col1 = 1
ORDER BY l_order_by;
LOOP
FETCH c_data INTO r_data;
EXIT WHEN c_data%NOTFOUND;
---- OTHER CODE HERE--
EXCEPTION
END;
So, basically i'm using the REF CURSOR, and passing the order by string dynamically from the Oracle Form. The above procedure is part of PLL.
I have verified running the script at SQL*PLUS, to test if there is any dependency on Forms. But data is not sorted in SQL*PLUS environment also.
And also i'm using a packaged procedure as one column in the cursor query. So I can't use EXEC_SQL, which will parse the total statement once . To me known we can use EXEC_SQL, when we don't have any input parameters to the SQL statement.
Any suggestion on passing Dynamic Order by cluase in any appraoch?
Cheers
Ram

Hi
I researched some and found this.
It looks like you are using 'REF CURSOR WITH STATIC SQL'.
You need REF CURSOR with DYNAMIC SQL ( put it in single quotes ).
Read this article here:
http://www.oracle.com/technology/oramag/oracle/04-may/o34asktom.html
Goto this section and read ---
Cursor or Ref Cursor
At an interview for an Oracle PL/SQL developer job, I was asked to describe the difference between cursor and ref cursor and when you would appropriately use each of these. Could you please tell me the answer?
Well, technically, under the covers, at the most basic level, they are the same. A typical PL/SQL cursor is static by definition. Ref cursors, on the other hand, can be dynamically opened (the query is not known until runtime) or opened by use of a set of static SQL statements, the choice of which is based on logic (an IF/THEN/ELSE block will open one or the other query). For example, the following block of code demonstrates a typical static PL/SQL cursor, cursor C. Also, it shows how you can use a ref cursor (L_CURSOR in this example) to open a query by using dynamic SQL or static SQL:
Declare
type rc is ref cursor;
cursor c is select * from dual;
l_cursor rc;
begin
if (to_char(sysdate,'dd') = 30)
then
-- ref cursor with dynamic sql
open l_cursor for
'select * from emp';
elsif (to_char(sysdate,'dd') = 29)
then
-- ref cursor with static sql
open l_cursor for
select * from dept;
else
-- with ref cursor with static sql
open l_cursor for
select * from dual;
end if;
-- the "normal" static cursor
open c;
end;
Message was edited by:
brian952

Similar Messages

  • My order number does not work.  when i sign in it says no orders.  who do i speak to regarding this?

    My order number does not work.  When i sign in it just says no orders.  How do i reach anyone to actually ask what is going on.

    contact adobe support by clicking here and, when available, click 'still need help', https://helpx.adobe.com/contact.html

  • Order by clause not working

    Hi, everyone,
    I am trying to use the following insert statement to insert records in asc order. if i use the select statement alone the order by clause works fine, but when i use the same sql and add a insert into table statment the order by clause does not work. I am not getting the records in ascending order. could anybody help me in this regard?
    INSERT INTO cat_sales_stg
    select      b.SSC,                
         ltrim(rtrim(a.CAT_DESC)) cat_desc,                
         SUM(a.AMOUNT) AMOUNT               
    FROM Trans a, SSC b                     
    WHERE a.ACCOUNT_NUMBER = TO_CHAR(b.ACCOUNT_NUMBER)                    
         AND a.TMONTH >= 200905 AND a.TMONTH <= 200910                
         AND a.FORMAT_NAME = 'ABC'                
         AND b.BMONTH = 200910                
         AND b.SAMPLE = 3                
         AND b.BANNER_NAME = 'ABC'               
         AND b.MODEL_NAME = 'XYZ'               
    group by b.SSC, ltrim(rtrim(a.CAT_DESC))
    order by ssc,cat_desc
    Thanks in advance

    user10636796 wrote:
    Hi, everyone,
    I am trying to use the following insert statement to insert records in asc orderWhat Toon, William, and others have said is that you DON'T insert rows in a specific order. That is completely outside the way relational databases are designed. You insert rows as unordered and use an ORDER BY clause in a SELECT when reading them. ORDER BY is for SELECT statements, not INSERT.
    In particular Toon poined out that we can't control where individual rows get stored.
    There is a databas object called a varray that can store data in sorted order. I have never seen them used because selecting the data back out again is more work; using an ordinary table and an ORDER BY clause is much easier.

  • [JS CS5] Re order pages script not working for me

    Hi, I'm attempting to use the reorder script marked as the answer in this post :
    http://forums.adobe.com/thread/519470
    My problem is that when it reorders the pages, it puts them all into one spread and errors once it reaches 10.
    Some details on what I am doing -
    It's an 18 page document, reorder is as follows:
    1,2,4,18,17,5,6,16,15,7,8,14,13,9,3,10,11,12
    Currently it's in spreads, but even when I turn off facing pages, move each page by itself and turn the master into one page, I still have the same error. I've been fighting with this a while, I've tried each of those by themselves as well.
    In case you are curious about the order - this is a booklet, but the middle signature is 3 pages. I'm attempting to create a script that will take it from reader to printer spreads as "print booklet" will not work because of the 3 page signature (extra page is a fold out on finished product).
    I'm fairly new to scripting and feel it must be something obvious I'm just missing.
    Thank you for your time!!

    @Krista – I suggest you ask in the thread you are pointing to with your link.
    No need to split the thread into two.
    Now to your problem:
    if all the pages end up in one spread it is no surprise that you get an error after page 10. The maximum page count of one single spread is 10.
    Why do the pages go to one spread?
    It's pure speculation, but I think it has to do with some preconditions your spreads are in.
    Check for "Allow Document Pages to Shuffle" and "Allow Selected Spread to Shuffle".
    Is "Allow Selected Spread to Shuffle" "off" or "on" for the particular spread where all pages are added?
    And another question:
    what is the particular script you refer to? There are a couple of scripts in this thread from various authors.
    Uwe

  • Download link from order e-mail not working 'page error'

    I ordered Adobe Photoshop Elements 10 & Adobe Premiere Elements 10 back in Nov2011.  I downloaded both to learn I needed the 64 bit version.  When I had time I downloaded Photoshop Elements 64 bit and got my project done.  Now I went back to get my 64 bit version of Premiere but the link no longer works.  On the order it says you can re-download anytime.  I sign in to my Adobe Account, go to Order History, hover over download - I see the address in my browser status bar at bottom left.  When I click on download the the status bar displays the yellow triangle with the warning message 'page error'  when you expand the message it indicates a address is not working.  I tried turning my firewall off - didn't have to do that before - but same message.  There must be a link where paying customers can get the proper download?  Everything I find is for the trial version.  Is there a link?  Why do the links in the order e-mail expire?  Thanks in advance!            

    OK, I finally worked around the issue.  Right click on the word download – then select open in new window.  Not sure why this worked – but it did.  Jeff, the alternate download option does appear on the second page that loads AFTER you get past the initial download link.  Though once I got there I was able to use the primary download for 64 bit.  Thanks all for looking at this.  J potter, try this and see if it helps.

  • Recovery media kit order web page not working for Canada site

    The laptop crashed (Pavilion G6-2288ca with Windows 8). I'm planning to replace the hard drive. I want to order the recovery media kits from hp but the Canada site is not working. After I entered the postal code, the site says it is temperarily out of service. I tried the same on the US site with a pretended zipcode and it worked fine. Can someone please help?
    Thanks.

    Try phoning HP Support. 1-800-474-6836
    ******Clicking the Thumbs-Up button is a way to say -Thanks!.******
    **Click Accept as Solution on a Reply that solves your issue to help others**

  • Incoming orders in COPA not working if Sales Order blocked for Credit Check

    Hi all,
    We need to build a report showing all incoming sales order by entry date and/or change date (change of values or quantities later on). COPA allows to do this, but the problem is that COPA line item table is only updated if the sales order is released from credit check (VKM3). I am looking for a solution to be able to record sales orders in COPA even if they are still blocked for credit check. By doing that we will be able to report all sales orders entered from COPA and provide basis for commissions calculation to the business.
    I have investigated possible COPA enhancements like COPA0005 but it doesn't seem to be used at the time of sales order save.
    Thanks.

    Hello ,
    Thanks for the reply
    As you said , the credit check in the service order is information message "Credit check (maximum percentage for ope
    exceeded)" .
    If you enter and come out this message then one more message will come , i.e., "The business transaction can not be carried out" detail message -  System status CNOK is active (ORD XXXXXXX).
    with the above message , system will not allow to do the Service order release.
    In this particular case , we have done the VKM1 for the sales order to unblock the order from credit check . But again system is checking the credit check at service order (created w.r.t sales order) . we are not able to control this .
    we also suggested the solution to the customer , saying removal of credit check for service orders . But customer requires credit check to happen at both the documents.

  • Process order settlement Ko88 not working.

    Hello Sapients,
    i am getting a message:"There are no accrued amounts; settlement is not possible."
    Following are the steps i cariried.
    1.) created a Process order CR01
    2.) did goods issue to the process order using MIGO_GI
    3.) when i run KKAX I am able to the costs in WIP.
    4.) but when i execute the ko88 for the particular process order systme is not settling any but instead giving me a message: "There are no accrued amounts; settlement is not possible."
    5.) Could you please advise if I am missing any thing.
    Thanks and Regards
    Ravi

    Hi Ravi,
    Please, check if you have run the settlement already for period that you wants to do the settle by path  KO88 -> goto -> previous settlement or by  extras -> activate flow trace at Ko88 to analysis the problem.
    Please, also verify the SAP note 179533. This note has some informations regarding the problem.
    Regards,
    Paulo

  • Maintain order at runtime not working for MDM in PI 7.31

    Hi All
    I have and one outbound and 5 inbound interfaces all going to MDM system
    first one is import and next 4 are webservice calls to MDM multiple times but the mapping changes for each.
    So I kept 5 different operation mappings for 5 inbound interfaces and maintain order at runtime in receiver interfaces
    The first one import if fails in MDM due to value exception or any exception, MDM PI adapter is not catching that and the other interfaces are executed
    So the maintain order at runtime is not useful in my case. do we know why is this behaviour? can we make sure the import is successfully completed before the next interface execution using maintain order at runtime?
    thx
    mike

    Hi Mike,
    I'm not sure if this is still relevant or even up to date. The MDM adapter is/was nothing more than the old file integration with enhanced audit log. So, unfortunately, it will tell you all about the import successes and errors in the audit log, but it will not change the message status accordingly. Regarding message status it still behaves as if it was a file receiver adapter stopping transaction at file system level. In my opinion, this is not very helpful, and scenarios like yours cannot be implemented using standard tools. You can't even use the standard monitor to check whether normal distributions worked. You'd have to check the audit log of every message. Or check the file system directly or read the MDM log, as before.
    I hope they improved that in the meantime.
    Regards,
    Jörg

  • HT1933 I want to cancel a order that did not work

    Othe other day I had trouble playing bingo so during I put buy on several things that came up thinking that would make it work,,,so it ended up charging me for  5 things with a total of 15.00,,,which I have not downloaded so I would like to cancel the complete order,,,and every time I put in the number on the order it says it is wrong,,,,the number is MH6SB2D71F     it says to report a problem and so I am,,,I do not want it,,,,so please take it off my bill if you can,,,please help

    Please be aware that you are not communicating with Apple when you post in these forums. The only people who will reply to your posts are your fellow users. Go here:
    http://www.apple.com/support/itunes/contact/
    and follow the instructions to report the issue to the iTunes Store.
    Regards.

  • "contains" and "order by" does not work in Oracle 9i

    Hello All.
    I have next query:
    select q.*
    from
    (SELECT v.id, o.longname as name, v.dord,
    TP.longname as TYPE_NAME, v.actualfl, o.NORD, v.version
    FROM R_ORD O, R_VORD V, R_TPORD TP, R_BODY b
    WHERE TP.ID = o.tp_id and v.ORD_ID = o.ID
    and v.ID = b.ID(+) and v.actualfl = '1'
    and CONTAINS( o.longname, 'bank%', 1) > 0
    ) q
    ORDER BY name
    It's work perfect in Oracle 8.1.7, but I can not get result of the query in Oracle 9.
    If I comment
    -- ORDER BY name
    or
    -- and CONTAINS( o.longname, 'bank%', 1) > 0
    then the query return a result.
    Please help.
    Thanks in advance.
    P.S. I use Oracle 9i SR1 and
    sort_area_size = 524288
    sort_area_retained_size = 0
    Victor Zogin.

    Description Cost Cardinality Byte
    SELECT STATEMENT, GOAL = CHOOSE               6     1     1260
    SORT ORDER BY               6     1     1260
    COUNT                         
    NESTED LOOPS OUTER               4     1     1260
    NESTED LOOPS               8     1     1247
    NESTED LOOPS               3     61     11895
    TABLE ACCESS BY INDEX ROWID     OMEGA     R_TPORD     1     1     140
    INDEX RANGE SCAN     OMEGA     PK_R_TPORD     1     1     
    TABLE ACCESS BY INDEX ROWID     OMEGA     R_VORD     2     149     8195
    INDEX RANGE SCAN     OMEGA     IDX_R_VORD_ACT     1     149     
    TABLE ACCESS BY INDEX ROWID     OMEGA     R_ORD     8     1     1052
    DOMAIN INDEX     OMEGA     CK_ORD_IDX     4     1     
    INDEX UNIQUE SCAN     OMEGA     PK_R_BODY          22437     291681

  • SIS S550 Orders - cumulative quantity not working - quantities are doubling

    We are using SIS S550 to gather our order info.  We have Order Quantity field set to be a Cumalative Qty Type.  This works in most cases.  But it seems that when certain changes are made like Delivery Date at the Header level or Unloading Point, the order quantity is duplicated in the S550 entry.
    Can anyone help as to why thsi may be occuring or how to make it stop?  We are getting doubled quantities in our reporting which is clearly a bad thing.
    Thanks in advance!!

    550 is within the customer number range, i.e. this infostructure exists only in your system and I doubt forum could be of much help. There are transactions that show how the update was carried for a specific document (I don't remember from the top of my head but there are very many posts regarding SIS in SD forum). Find a record (material #, customer #) that has an issue and that has the least amount of documents associated with it.
    Just a wild guess - this could be because of the credit documents (CR, RE). Numbers are always stored as positive in SD and need to be negated in the SIS update. If this was not configured correctly then a sale and a return would cause double the numbers.
    Once again - there is plenty of info in SD forum.

  • Enable PDF Generation of Sales Order from Opportunity not working

    Hi all,
    we are trying to enable the PDF Generation for Sales Order from Opportunity.
    We´re working on the ERP-HCI Scenario.
    We´ve setup the necessarry configurations (chapter 11.3.11) how described in the document:
    https://websmp201.sap-ag.de/~sapidb/012002523100002166322015E/1502_SAP_C4C_ERP_HCI.pdf
    1. Create Endpoint in ECC for the WS "SalesDocumentPrintPreviewQuery"
    After saving the settings we have an calculated enpoint:
    /sap/bc/srt/rfc/sap/salesdocumentprintpreviewquery/{SAP-CLIENT}/salesdocumentprintpreviewquery/salesdocumentprintpreviewquery
    2. Create a new Communication Arrangement in C4C for the Scenario "Print Preview of Business Documents in SAP Business Suite"
    Question to the following Step:
    Go to Advanced Settings and enter the URL you have captured from SOAMANAGER in the Create Endpoint section.
    Why we use the host and calculated endpoint from the ECC instead of the HCI settings, and maintain in HCI the target host and endpoint?
    The Check Service and Check Connection test was successfull.
    Finally if we try the scenario from C4C (Customers > {Select a Customer} > Opportunity > Sales Document > {Click the link}
    We got a blank new Window, in the C4C UI we get the error "PDF Document could not be retrieved"
    In the ECC > SOA Runtime Error Log i get the following Error!?
    What´s wrong with our config?
    Thanks in advance,
    Fabian

    There is nothing impossible in SAP. After all there is a code behind everything that we see in SAP screens and transactions and that code can be changed according to our requirement. That has always been m firm belief.
    Like I said get hold of your ABAP programmer and write out the spec and he should be able to do it.
    Its news for me that you can generate an automatic PO from a GR so if that is possible then why not this.
    Its not been attempted before.
    Try creating a new Sales doc type and map it to a delivery and see if it works. Much similar to a cash sale and rush order when both docs get generated immediately. Maybe you need to map your copy control criteria too in a way it can be done.Also maybe you need to create a new field called Immediae sales Order like we have an immediate delivery check box in a sales order so that an automatic sales order can be generated when you save a delivery.
    Like I said it needs some coding.
    regards
    Jude

  • Sales Order - Output determination not working

    Dear Friends,
    Greetings!
    I have a strange problem,
    Order Acknowledgement is to be emailed out automatically on meeting requirement 902 on order save. It goes out to customer (Output: ZBAC: Partner – SP: Customer copy – different layout), and commissioned agents (Output: ZEC1 to ZEC5, upto 5 partners: C1 to C5, Rep copy layout). Customer copy - ZBAC works fine, but ZEC1-ZEC5 rep copy output does not appear at all.
    here is <u>output analysis</u> for ZEC1 and ZEC2:
    ZEC1     529     No condition access - if desired, please set in Customizing
    ZEC1     562     This output is not defined for Customer 0001010059
    ZEC2     529     No condition access - if desired, please set in Customizing
    ZEC2     562     This output is not defined for Customer 0001010059
    All output types use same <u>access Sequence</u> as below:
    1     5     Sales Organization/Order Type     0
    2     13     Sales Org.     0
    3     7     Order Type     0
    Sample <u>Output Procedure</u>, using requirement 902
    2     1     ZBAR     Ord Conf. - Rep copy     902 >>> Rep copy, I originally thought would be possible to create 5 condition records with partners C1 to C5; but
    3     1     ZBAC     Ord Conf. - Customer     902 >>> Customer copy
    930     1     ZEC1     eMail Partner C1     902 >>> Rep copy should go to partner C1
    931     2     ZEC2     eMail Partner C2     902 >>> Rep copy should go to partner C2
    932     3     ZEC3     eMail Partner C3     902 >>> Rep copy should go to partner C3
    933     4     ZEC4     eMail Partner C4     902 >>> Rep copy should go to partner C4
    934     5     ZEC5     eMail Partner C5     902 >>> Rep copy should go to partner C5
    <u>VV12 Output record for ZEC1: by Order Type</u>
    ZOR     Sales Order     C1          5     4     EN
    ZOR     Sales Order     C2          5     4     EN
    <u>VV12 Output record for ZBAC: by Sales Org</u>
    3000     Rochester Operations     SP          5     4     EN
    >>> C1 and C2, SP Partner does not get description, when I click F4 then SAP throws following message: Possible entries only for mail addresses and PD Org objects Message no. VN341
    Appreciate your feedback, let me know if any additional information required.
    thank you,
    Hetal

    check in NACO transaction is you have assigned access sequence to your ZEC* output ytpes and if you have ticked checkbox "Access to output conditions" - otherwise it will not even try to access condition records.
    From help :
    Access to output conditions                                                                               
    Indicates whether the system determines the output by searching for valid
        condition records.                                                                               
    Procedure                                                                               
    If you want the system to search condition records for the appropriate   
        output, mark the field.                                                                               
    Note                                                                               
    If you leave the field blank and if you are processing sales, shipping,  
        or billing documents, the system automatically determines output from    
        information stored in the customer master record.

  • Sale Order Api Is not working

    Hi experts ,
    I am trying to load the data via api , Its not getting load , can u help me pls ,
    DECLARE
    l_line_id NUMBER;
    l_item_id NUMBER;
    l_order_qty NUMBER;
    l_msg_index number;
    L_data VARCHAR2 (2000);
    l_debug_file VARCHAR2 (200);
    resultout VARCHAR2 (100);
    l_order_uom VARCHAR2 (10);
    l_reship_order NUMBER;
    itemkey number := 215600;
    l_negative_prorate NUMBER;
    l_prorate_qty NUMBER;
    l_sch_ship_date DATE;
    l_debug_level NUMBER := 3;
    l_ship_to_org_id NUMBER;
    l_attribute1 VARCHAR2 (150);
    l_attribute2 VARCHAR2 (150);
    l_line_num NUMBER;
    l_agreement_id NUMBER;
    l_organization_id NUMBER;
    l_segment VARCHAR2 (120);
    l_child_onhand NUMBER := 0;
    l_qty_temp NUMBER := 0;
    l_excl_temp NUMBER := 0;
    l_prorate_percent NUMBER;
    l_onhand NUMBER;
    l_error VARCHAR2 (240);
    l_error_message VARCHAR2 (240);
    l_line_tbl oe_order_pub.line_tbl_type;
    l_line_tbl_count NUMBER := 0;
    l_temp_count NUMBER := 0;
    p_line_tbl_rec oe_order_pub.line_tbl_type;
    p_line_id NUMBER;
    p_error_flag VARCHAR2 (1000);
    p_error_message VARCHAR2 (1000);
    l_api_version_number NUMBER := 1;
    l_return_status VARCHAR2 (2000);
    l_return_status1 VARCHAR2 (2000);
    l_msg_count NUMBER;
    l_msg_data VARCHAR2 (2000);
    -- l_msg_index VARCHAR2 (1000);
    l_line_out_tbl oe_order_pub.line_tbl_type;
    p_parent_item VARCHAR2 (100) := 'PROPANE';
    p_organization_id NUMBER := 321;
    l_header_id NUMBER := 152066;
    --- Child Cursor Without Exclusion of Soldado
    CURSOR c_child_items (
    p_parent_item VARCHAR2,
    p_organization_id NUMBER
    IS
    CURSOR c_positive_items (
    p_parent_item VARCHAR2,
    p_organization_id NUMBER
    IS
    SELECT inventory_item_id,
    segment1,
    organization_id,
    SUM (onhand - order_qty) onhand,
    COUNT ( * ) OVER () total_rows
    FROM ( SELECT msi.inventory_item_id,
    msi.segment1,
    msi.organization_id,
    NVL (
    SUM(inv_convert.inv_um_convert_new (
    moq.inventory_item_id,
    5,
    moq.transaction_quantity,
    moq.transaction_uom_code,
    l_order_uom,
    NULL,
    NULL,
    'U'
    0
    onhand,
    (SELECT NVL (SUM (ordered_quantity), 0)
    FROM oe_order_lines_all
    WHERE header_id = l_header_id
    AND flow_status_code NOT IN
    ('CLOSED', 'SHIPPED')
    AND inventory_item_id =
    msi.inventory_item_id)
    order_qty
    FROM mtl_system_items_b msi,
    oe_lookups ol,
    mtl_onhand_quantities_detail moq
    WHERE msi.segment1 = ol.meaning
    AND TRIM (SYSDATE) BETWEEN ol.start_date_active
    AND NVL (ol.end_date_active,
    TRIM (SYSDATE))
    AND ol.enabled_flag = 'Y'
    AND ol.lookup_type = p_parent_item
    AND msi.organization_id = p_organization_id
    AND msi.inventory_item_id = moq.inventory_item_id(+)
    AND msi.organization_id = moq.organization_id(+)
    AND (msi.segment1 LIKE '%SOLDADO%'
    OR msi.segment1 LIKE '%T4%')
    GROUP BY msi.inventory_item_id,
    msi.segment1,
    msi.organization_id)
    GROUP BY inventory_item_id, segment1, organization_id
    HAVING SUM (onhand - order_qty) > 0
    ORDER BY segment1;
    --- Child Cursor With only Positive Buckets
    CURSOR c_positive_onhand (
    p_parent_item IN VARCHAR2,
    p_organization_id IN NUMBER
    IS
    BEGIN
    IF (l_debug_level > 0)
    THEN
    l_debug_file := oe_debug_pub.set_debug_mode ('FILE');
    oe_debug_pub.initialize;
    oe_debug_pub.setdebuglevel (l_debug_level);
    oe_msg_pub.initialize;
    END IF;
    --- Initialization Block
    DBMS_OUTPUT.put_line ('Initialization Block');
    fnd_global.apps_initialize (fnd_global.user_id,
    fnd_global.resp_id,
    fnd_global.resp_appl_id);
    -- BEGIN
    -- MO_GLOBAL.SET_POLICY_CONTEXT ('S', 321);
    -- END;
    -- fnd_global.apps_initialize (-1, 21623, 660);
    --- Get Line ID from workflow
    l_line_id := TO_NUMBER (itemkey);
    --- To get the line details
    BEGIN
    SELECT header_id,
    ordered_item,
    inventory_item_id,
    line_number,
    order_quantity_uom,
    ordered_quantity,
    ship_from_org_id,
    ship_to_org_id,
    schedule_ship_date,
    attribute1,
    attribute2,
    agreement_id
    INTO l_header_id,
    l_segment,
    l_item_id,
    l_line_num,
    l_order_uom,
    l_order_qty,
    l_organization_id,
    l_ship_to_org_id,
    l_sch_ship_date,
    l_attribute1,
    l_attribute2,
    l_agreement_id
    FROM oe_order_lines_all
    WHERE line_id = l_line_id;
    DBMS_OUTPUT.put_line ('To get the line details');
    EXCEPTION
    WHEN OTHERS
    THEN
    l_header_id := NULL;
    l_segment := NULL;
    l_item_id := NULL;
    l_order_qty := NULL;
    l_organization_id := NULL;
    DBMS_OUTPUT.put_line ('Not Avilable for To get the line details');
    END;
    -- To get the Original sales order Number
    BEGIN
    SELECT attribute10
    INTO l_reship_order
    FROM oe_order_headers_all
    WHERE header_id = l_header_id;
    EXCEPTION
    WHEN OTHERS
    THEN
    l_reship_order := NULL;
    END;
    --- Check for the Top Level Item Name
    IF l_segment IN ('PROPANE', 'BUTANE', 'ISO BUTANE', 'GASOLINE')
    THEN
    --- To get the total positive onhand quantity for all the child items
    BEGIN
    SELECT NVL (SUM (trx_qty), 0)
    INTO l_onhand
    FROM ( SELECT moq.inventory_item_id,
    NVL (
    SUM(NVL (
    inv_convert.inv_um_convert_new (
    msi.inventory_item_id,
    5,
    moq.transaction_quantity,
    moq.transaction_uom_code,
    l_order_uom,
    NULL,
    NULL,
    'U'
    0
    - (SELECT NVL (SUM (ordered_quantity), 0)
    FROM oe_order_lines_all
    WHERE header_id = l_header_id
    AND flow_status_code NOT IN
    ('CLOSED', 'SHIPPED')
    AND inventory_item_id =
    msi.inventory_item_id),
    0
    trx_qty
    FROM mtl_onhand_quantities_detail moq,
    mtl_system_items msi,
    oe_lookups ol
    WHERE msi.segment1 = ol.meaning
    AND TRIM (SYSDATE) BETWEEN ol.start_date_active
    AND NVL (
    ol.end_date_active,
    TRIM (SYSDATE)
    AND ol.enabled_flag = 'Y'
    AND ol.lookup_type = l_segment
    AND msi.organization_id = l_organization_id
    AND moq.inventory_item_id = msi.inventory_item_id
    AND moq.organization_id = msi.organization_id
    AND (msi.segment1 NOT LIKE '%SOLDADO%'
    AND msi.segment1 NOT LIKE '%T4%')
    GROUP BY msi.inventory_item_id, moq.inventory_item_id)
    WHERE trx_qty > 0;
    DBMS_OUTPUT.put_line ('l_onhand' || l_onhand);
    EXCEPTION
    WHEN OTHERS
    THEN
    l_onhand := 0;
    DBMS_OUTPUT.put_line ('Not Avilable for on hand');
    END;
    -- To check whether this order is a reshipment order
    DBMS_OUTPUT.put_line (
    'To check whether this order is a reshipment order'
    IF l_reship_order IS NOT NULL
    THEN
    DBMS_OUTPUT.put_line ('1st Else Case reship');
    ELSE
    DBMS_OUTPUT.put_line ('1st Else Case no reship');
    FOR l_positive_items
    IN c_positive_items (l_segment, l_organization_id)
    LOOP
    DBMS_OUTPUT.put_line( 'l_positive_items.onhand'
    || l_positive_items.onhand
    || 'l_excl_temp'
    || l_excl_temp
    || ' l_order_qty'
    || l_order_qty);
    IF l_positive_items.onhand > 0 AND l_excl_temp < l_order_qty
    THEN
    l_line_tbl_count := l_line_tbl_count + 1;
    IF (l_order_qty - l_excl_temp) < l_positive_items.onhand
    THEN
    l_prorate_qty := l_order_qty - l_excl_temp;
    ELSE
    l_prorate_qty := l_positive_items.onhand;
    END IF;
    -- Initializing the Sales order Lines Record type
    DBMS_OUTPUT.put_line (
    'Initializing the Sales order Lines Record type'
    l_line_tbl (l_line_tbl_count) := oe_order_pub.g_miss_line_rec;
    l_line_tbl (l_line_tbl_count).operation :=
    oe_globals.g_opr_create;
    l_line_tbl (l_line_tbl_count).header_id := l_header_id;
    l_line_tbl (l_line_tbl_count).inventory_item_id :=
    l_positive_items.inventory_item_id;
    l_line_tbl (l_line_tbl_count).ship_to_org_id :=
    l_ship_to_org_id;
    l_line_tbl (l_line_tbl_count).ordered_quantity := l_prorate_qty;
    l_line_tbl (l_line_tbl_count).schedule_ship_date :=
    l_sch_ship_date;
    l_line_tbl (l_line_tbl_count).attribute1 := l_attribute1;
    l_line_tbl (l_line_tbl_count).attribute2 := l_attribute2;
    l_line_tbl (l_line_tbl_count).attribute9 := l_line_id;
    l_line_tbl (l_line_tbl_count).attribute10 :=
    ROUND (l_prorate_qty / l_order_qty * 100, 5);
    l_line_tbl (l_line_tbl_count).agreement_id := l_agreement_id;
    l_line_tbl (l_line_tbl_count).calculate_price_flag := 'Y';
    l_excl_temp := l_excl_temp + l_prorate_qty;
    END IF;
    END LOOP;
    -- To check if the total onhand is greater than zero
    DBMS_OUTPUT.put_line (
    'To check if the total onhand is greater than zero'
    IF l_onhand > 0
    THEN
    IF l_order_qty > l_excl_temp
    THEN
    -- To check whether the onhand is lesser than order qty
    DBMS_OUTPUT.put_line (
    'To check whether the onhand is lesser than order qty'
    IF (l_onhand < (l_order_qty - l_excl_temp))
    THEN
    -- Loop the cursor with exclusion of soldado logic
    DBMS_OUTPUT.put_line (
    'Loop the cursor with exclusion of soldado logic'
    FOR l_child_item
    IN c_child_items (l_segment, l_organization_id)
    LOOP
    l_prorate_percent := NULL;
    l_negative_prorate := 0;
    l_temp_count := 0;
    l_prorate_qty := 0;
    -- Initializing the Sales order Lines Record type
    DBMS_OUTPUT.put_line (
    'Initializing the Sales order Lines Record type2'
    l_line_tbl (l_line_tbl_count) :=
    oe_order_pub.g_miss_line_rec;
    l_line_tbl (l_line_tbl_count).operation :=
    oe_globals.g_opr_create;
    l_line_tbl (l_line_tbl_count).header_id := l_header_id;
    l_line_tbl (l_line_tbl_count).inventory_item_id :=
    l_child_item.inventory_item_id;
    l_line_tbl (l_line_tbl_count).ship_to_org_id :=
    l_ship_to_org_id;
    l_line_tbl (l_line_tbl_count).ordered_quantity :=
    l_prorate_qty;
    l_line_tbl (l_line_tbl_count).schedule_ship_date :=
    l_sch_ship_date;
    l_line_tbl (l_line_tbl_count).attribute1 := l_attribute1;
    l_line_tbl (l_line_tbl_count).attribute2 := l_attribute2;
    l_line_tbl (l_line_tbl_count).attribute9 := l_line_id;
    l_line_tbl (l_line_tbl_count).attribute10 :=
    ROUND (l_prorate_qty / l_order_qty * 100, 5);
    l_line_tbl (l_line_tbl_count).agreement_id :=
    l_agreement_id;
    l_line_tbl (l_line_tbl_count).calculate_price_flag := 'Y';
    END LOOP;
    ELSE
    -- Loop the cursor of all the positive buckets
    FOR l_child_items
    IN c_positive_onhand (l_segment, l_organization_id)
    LOOP
    l_prorate_percent := NULL;
    l_child_onhand := 0;
    l_prorate_qty := 0;
    -- To get the split percentage of the child items
    l_prorate_percent :=
    ROUND ( (l_child_items.trx_qty / l_onhand) * 100, 5);
    -- To check whether the prorate percentage exits
    IF l_prorate_percent IS NOT NULL
    AND l_prorate_percent > 0
    THEN
    -- To calculate the prorate quantity
    l_line_tbl_count := l_line_tbl_count + 1;
    l_prorate_qty :=
    ROUND (
    (l_order_qty - l_excl_temp)
    * (l_prorate_percent / 100),
    5
    l_qty_temp := l_qty_temp + l_prorate_qty;
    -- To calculate the prorate quantity for the last line
    IF c_positive_onhand%ROWCOUNT =
    l_child_items.total_rows
    THEN
    l_prorate_qty :=
    l_prorate_qty
    + (l_order_qty - (l_qty_temp + l_excl_temp));
    END IF;
    -- Initializing the line record type to process
    DBMS_OUTPUT.put_line (
    'Initializing the Sales order Lines Record type3'
    l_line_tbl (l_line_tbl_count) :=
    oe_order_pub.g_miss_line_rec;
    l_line_tbl (l_line_tbl_count).operation :=
    oe_globals.g_opr_create;
    l_line_tbl (l_line_tbl_count).header_id := l_header_id;
    l_line_tbl (l_line_tbl_count).inventory_item_id :=
    l_child_items.inventory_item_id;
    l_line_tbl (l_line_tbl_count).ship_to_org_id :=
    l_ship_to_org_id;
    l_line_tbl (l_line_tbl_count).ordered_quantity :=
    l_prorate_qty;
    l_line_tbl (l_line_tbl_count).schedule_ship_date :=
    l_sch_ship_date;
    l_line_tbl (l_line_tbl_count).attribute1 :=
    l_attribute1;
    l_line_tbl (l_line_tbl_count).attribute2 :=
    l_attribute2;
    l_line_tbl (l_line_tbl_count).attribute9 := l_line_id;
    l_line_tbl (l_line_tbl_count).attribute10 :=
    ROUND (l_prorate_qty / l_order_qty * 100, 5);
    l_line_tbl (l_line_tbl_count).agreement_id :=
    l_agreement_id;
    l_line_tbl (l_line_tbl_count).calculate_price_flag :=
    'Y';
    DBMS_OUTPUT.put_line( '3rd insert'
    || 'l_prorate_qty'
    || l_prorate_qty
    || 'l_ship_to_org_id'
    || l_ship_to_org_id
    || 'l_sch_ship_date'
    || l_sch_ship_date
    || 'l_child_items.inventory_item_id'
    || l_child_items.inventory_item_id
    || 'l_agreement_id'
    || l_agreement_id);
    END IF;
    COMMIT;
    END LOOP;
    END IF;
    END IF;
    ELSIF l_order_qty > l_excl_temp
    THEN
    -- Loop the cursor with exclusion of soldado logic
    FOR l_child_item IN c_child_items (l_segment, l_organization_id)
    LOOP
    l_prorate_percent := 0;
    l_prorate_qty := 0;
    l_prorate_percent := ROUND (100 / l_child_item.total_rows, 5);
    l_prorate_qty :=
    ROUND (
    ( (l_order_qty - l_excl_temp) / l_child_item.total_rows),
    5
    l_line_tbl_count := l_line_tbl_count + 1;
    l_qty_temp := l_qty_temp + l_prorate_qty;
    -- To calculate the prorate quantity for the last line
    IF c_child_items%ROWCOUNT = l_child_item.total_rows
    THEN
    l_prorate_qty :=
    l_prorate_qty
    + (l_order_qty - (l_qty_temp + l_excl_temp));
    END IF;
    -- Initializing the line record type to process
    DBMS_OUTPUT.put_line (
    'Initializing the Sales order Lines Record type4'
    l_line_tbl (l_line_tbl_count) := oe_order_pub.g_miss_line_rec;
    l_line_tbl (l_line_tbl_count).operation :=
    oe_globals.g_opr_create;
    l_line_tbl (l_line_tbl_count).header_id := l_header_id;
    l_line_tbl (l_line_tbl_count).inventory_item_id :=
    l_child_item.inventory_item_id;
    l_line_tbl (l_line_tbl_count).ship_to_org_id :=
    l_ship_to_org_id;
    l_line_tbl (l_line_tbl_count).ordered_quantity := l_prorate_qty;
    l_line_tbl (l_line_tbl_count).schedule_ship_date :=
    l_sch_ship_date;
    l_line_tbl (l_line_tbl_count).attribute1 := l_attribute1;
    l_line_tbl (l_line_tbl_count).attribute2 := l_attribute2;
    l_line_tbl (l_line_tbl_count).attribute9 := l_line_id;
    l_line_tbl (l_line_tbl_count).attribute10 :=
    ROUND (l_prorate_qty / l_order_qty * 100, 5);
    l_line_tbl (l_line_tbl_count).agreement_id := l_agreement_id;
    l_line_tbl (l_line_tbl_count).calculate_price_flag := 'Y';
    END LOOP;
    END IF;
    END IF; -- to check whether any records are initialized
    IF l_line_tbl_count > 0
    THEN
    -- Cancel the Parent Item
    DBMS_OUTPUT.put_line ('Cancel the Parent Item');
    l_line_tbl (l_line_tbl_count + 1) := oe_order_pub.g_miss_line_rec;
    l_line_tbl (l_line_tbl_count + 1).operation :=
    oe_globals.g_opr_update;
    l_line_tbl (l_line_tbl_count + 1).header_id := l_header_id;
    l_line_tbl (l_line_tbl_count + 1).line_id := l_line_id;
    l_line_tbl (l_line_tbl_count + 1).ordered_quantity := 0;
    l_line_tbl (l_line_tbl_count + 1).attribute10 := l_order_qty;
    l_line_tbl (l_line_tbl_count + 1).cancelled_flag := 'Y';
    l_line_tbl (l_line_tbl_count + 1).change_reason := 'Not Provided';
    DBMS_OUTPUT.put_line( 'Cancellation Process fileds'
    || 'HDR_ID'
    || l_header_id
    || 'LINE'
    || l_line_id
    || 'l_order_qty'
    || l_order_qty);
    -- Call the procedure to process the sales order lines
    -- process_order_line_api (p_line_tbl_rec => l_line_tbl,
    -- p_line_id => l_line_id,
    -- p_error_flag => l_error,
    -- p_error_message => l_error_message);
    IF l_error = 'Y'
    THEN
    resultout := 'COMPLETE:Y';
    ELSE
    resultout := 'COMPLETE:N';
    END IF;
    ELSE
    resultout := 'COMPLETE:N';
    END IF;
    END IF;
    BEGIN
    fnd_global.apps_initialize (fnd_global.user_id,
    fnd_global.resp_id,
    fnd_global.resp_appl_id);
    -- BEGIN
    -- MO_GLOBAL.SET_POLICY_CONTEXT ('S', 321);
    -- END;
    -- fnd_global.apps_initialize (-1, 21623, 660);
    -- Call Process Line API to process sales order lines
    DBMS_OUTPUT.put_line ('fianl line to be processd');
    BEGIN
    oe_order_pub.process_line (p_line_tbl => p_line_tbl_rec,
    x_line_out_tbl => l_line_out_tbl,
    x_return_status => l_return_status,
    x_msg_count => l_msg_count,
    x_msg_data => l_msg_data);
    COMMIT;
    DBMS_OUTPUT.put_line ('API Processed' || l_msg_data);
    fnd_file.put_line (fnd_file.LOG, 'Processed - ' || l_msg_data);
    EXCEPTION
    WHEN OTHERS
    THEN
    DBMS_OUTPUT.put_line ('Failed With1' || SQLERRM);
    END;
    -- display error msgs
    IF (l_debug_level > 0)
    THEN
    FOR i IN 1 .. l_msg_count
    LOOP
    oe_msg_pub.get (p_msg_index => i,
    p_encoded => fnd_api.g_false,
    p_data => l_data,
    p_msg_index_out => l_msg_index);
    fnd_file.put_line (fnd_file.LOG, 'message is:' || l_data);
    fnd_file.put_line (fnd_file.LOG,
    'message index is:' || l_msg_index);
    DBMS_OUTPUT.put_line (
    'l_data' || l_data || 'l_debug_level' || l_debug_level
    END LOOP;
    END IF;
    IF p_error_flag = 'N'
    THEN
    FOR i IN 1 .. l_msg_count
    LOOP
    oe_msg_pub.get (p_msg_index => i,
    p_encoded => fnd_api.g_false,
    p_data => p_error_message,
    p_msg_index_out => l_msg_index);
    END LOOP;
    ELSE
    DBMS_OUTPUT.put_line ('Out Of loop Exit');
    END IF;
    fnd_file.put_line (fnd_file.LOG, 'p_error_message - ' || SQLERRM);
    DBMS_OUTPUT.put_line ('p_error_message' || p_error_message || SQLERRM);
    EXCEPTION
    WHEN OTHERS
    THEN
    DBMS_OUTPUT.put_line ('Failed With' || SQLERRM);
    fnd_file.put_line (fnd_file.LOG,
    'Unexpected Errors Found4 - ' || SQLERRM);
    END;
    END;
    Thanks
    Shagul

    Hi experts ,
    I am trying to load the data via api , Its not getting load , can u help me pls ,
    DECLARE
    l_line_id NUMBER;
    l_item_id NUMBER;
    l_order_qty NUMBER;
    l_msg_index number;
    L_data VARCHAR2 (2000);
    l_debug_file VARCHAR2 (200);
    resultout VARCHAR2 (100);
    l_order_uom VARCHAR2 (10);
    l_reship_order NUMBER;
    itemkey number := 215600;
    l_negative_prorate NUMBER;
    l_prorate_qty NUMBER;
    l_sch_ship_date DATE;
    l_debug_level NUMBER := 3;
    l_ship_to_org_id NUMBER;
    l_attribute1 VARCHAR2 (150);
    l_attribute2 VARCHAR2 (150);
    l_line_num NUMBER;
    l_agreement_id NUMBER;
    l_organization_id NUMBER;
    l_segment VARCHAR2 (120);
    l_child_onhand NUMBER := 0;
    l_qty_temp NUMBER := 0;
    l_excl_temp NUMBER := 0;
    l_prorate_percent NUMBER;
    l_onhand NUMBER;
    l_error VARCHAR2 (240);
    l_error_message VARCHAR2 (240);
    l_line_tbl oe_order_pub.line_tbl_type;
    l_line_tbl_count NUMBER := 0;
    l_temp_count NUMBER := 0;
    p_line_tbl_rec oe_order_pub.line_tbl_type;
    p_line_id NUMBER;
    p_error_flag VARCHAR2 (1000);
    p_error_message VARCHAR2 (1000);
    l_api_version_number NUMBER := 1;
    l_return_status VARCHAR2 (2000);
    l_return_status1 VARCHAR2 (2000);
    l_msg_count NUMBER;
    l_msg_data VARCHAR2 (2000);
    -- l_msg_index VARCHAR2 (1000);
    l_line_out_tbl oe_order_pub.line_tbl_type;
    p_parent_item VARCHAR2 (100) := 'PROPANE';
    p_organization_id NUMBER := 321;
    l_header_id NUMBER := 152066;
    --- Child Cursor Without Exclusion of Soldado
    CURSOR c_child_items (
    p_parent_item VARCHAR2,
    p_organization_id NUMBER
    IS
    CURSOR c_positive_items (
    p_parent_item VARCHAR2,
    p_organization_id NUMBER
    IS
    SELECT inventory_item_id,
    segment1,
    organization_id,
    SUM (onhand - order_qty) onhand,
    COUNT ( * ) OVER () total_rows
    FROM ( SELECT msi.inventory_item_id,
    msi.segment1,
    msi.organization_id,
    NVL (
    SUM(inv_convert.inv_um_convert_new (
    moq.inventory_item_id,
    5,
    moq.transaction_quantity,
    moq.transaction_uom_code,
    l_order_uom,
    NULL,
    NULL,
    'U'
    0
    onhand,
    (SELECT NVL (SUM (ordered_quantity), 0)
    FROM oe_order_lines_all
    WHERE header_id = l_header_id
    AND flow_status_code NOT IN
    ('CLOSED', 'SHIPPED')
    AND inventory_item_id =
    msi.inventory_item_id)
    order_qty
    FROM mtl_system_items_b msi,
    oe_lookups ol,
    mtl_onhand_quantities_detail moq
    WHERE msi.segment1 = ol.meaning
    AND TRIM (SYSDATE) BETWEEN ol.start_date_active
    AND NVL (ol.end_date_active,
    TRIM (SYSDATE))
    AND ol.enabled_flag = 'Y'
    AND ol.lookup_type = p_parent_item
    AND msi.organization_id = p_organization_id
    AND msi.inventory_item_id = moq.inventory_item_id(+)
    AND msi.organization_id = moq.organization_id(+)
    AND (msi.segment1 LIKE '%SOLDADO%'
    OR msi.segment1 LIKE '%T4%')
    GROUP BY msi.inventory_item_id,
    msi.segment1,
    msi.organization_id)
    GROUP BY inventory_item_id, segment1, organization_id
    HAVING SUM (onhand - order_qty) > 0
    ORDER BY segment1;
    --- Child Cursor With only Positive Buckets
    CURSOR c_positive_onhand (
    p_parent_item IN VARCHAR2,
    p_organization_id IN NUMBER
    IS
    BEGIN
    IF (l_debug_level > 0)
    THEN
    l_debug_file := oe_debug_pub.set_debug_mode ('FILE');
    oe_debug_pub.initialize;
    oe_debug_pub.setdebuglevel (l_debug_level);
    oe_msg_pub.initialize;
    END IF;
    --- Initialization Block
    DBMS_OUTPUT.put_line ('Initialization Block');
    fnd_global.apps_initialize (fnd_global.user_id,
    fnd_global.resp_id,
    fnd_global.resp_appl_id);
    -- BEGIN
    -- MO_GLOBAL.SET_POLICY_CONTEXT ('S', 321);
    -- END;
    -- fnd_global.apps_initialize (-1, 21623, 660);
    --- Get Line ID from workflow
    l_line_id := TO_NUMBER (itemkey);
    --- To get the line details
    BEGIN
    SELECT header_id,
    ordered_item,
    inventory_item_id,
    line_number,
    order_quantity_uom,
    ordered_quantity,
    ship_from_org_id,
    ship_to_org_id,
    schedule_ship_date,
    attribute1,
    attribute2,
    agreement_id
    INTO l_header_id,
    l_segment,
    l_item_id,
    l_line_num,
    l_order_uom,
    l_order_qty,
    l_organization_id,
    l_ship_to_org_id,
    l_sch_ship_date,
    l_attribute1,
    l_attribute2,
    l_agreement_id
    FROM oe_order_lines_all
    WHERE line_id = l_line_id;
    DBMS_OUTPUT.put_line ('To get the line details');
    EXCEPTION
    WHEN OTHERS
    THEN
    l_header_id := NULL;
    l_segment := NULL;
    l_item_id := NULL;
    l_order_qty := NULL;
    l_organization_id := NULL;
    DBMS_OUTPUT.put_line ('Not Avilable for To get the line details');
    END;
    -- To get the Original sales order Number
    BEGIN
    SELECT attribute10
    INTO l_reship_order
    FROM oe_order_headers_all
    WHERE header_id = l_header_id;
    EXCEPTION
    WHEN OTHERS
    THEN
    l_reship_order := NULL;
    END;
    --- Check for the Top Level Item Name
    IF l_segment IN ('PROPANE', 'BUTANE', 'ISO BUTANE', 'GASOLINE')
    THEN
    --- To get the total positive onhand quantity for all the child items
    BEGIN
    SELECT NVL (SUM (trx_qty), 0)
    INTO l_onhand
    FROM ( SELECT moq.inventory_item_id,
    NVL (
    SUM(NVL (
    inv_convert.inv_um_convert_new (
    msi.inventory_item_id,
    5,
    moq.transaction_quantity,
    moq.transaction_uom_code,
    l_order_uom,
    NULL,
    NULL,
    'U'
    0
    - (SELECT NVL (SUM (ordered_quantity), 0)
    FROM oe_order_lines_all
    WHERE header_id = l_header_id
    AND flow_status_code NOT IN
    ('CLOSED', 'SHIPPED')
    AND inventory_item_id =
    msi.inventory_item_id),
    0
    trx_qty
    FROM mtl_onhand_quantities_detail moq,
    mtl_system_items msi,
    oe_lookups ol
    WHERE msi.segment1 = ol.meaning
    AND TRIM (SYSDATE) BETWEEN ol.start_date_active
    AND NVL (
    ol.end_date_active,
    TRIM (SYSDATE)
    AND ol.enabled_flag = 'Y'
    AND ol.lookup_type = l_segment
    AND msi.organization_id = l_organization_id
    AND moq.inventory_item_id = msi.inventory_item_id
    AND moq.organization_id = msi.organization_id
    AND (msi.segment1 NOT LIKE '%SOLDADO%'
    AND msi.segment1 NOT LIKE '%T4%')
    GROUP BY msi.inventory_item_id, moq.inventory_item_id)
    WHERE trx_qty > 0;
    DBMS_OUTPUT.put_line ('l_onhand' || l_onhand);
    EXCEPTION
    WHEN OTHERS
    THEN
    l_onhand := 0;
    DBMS_OUTPUT.put_line ('Not Avilable for on hand');
    END;
    -- To check whether this order is a reshipment order
    DBMS_OUTPUT.put_line (
    'To check whether this order is a reshipment order'
    IF l_reship_order IS NOT NULL
    THEN
    DBMS_OUTPUT.put_line ('1st Else Case reship');
    ELSE
    DBMS_OUTPUT.put_line ('1st Else Case no reship');
    FOR l_positive_items
    IN c_positive_items (l_segment, l_organization_id)
    LOOP
    DBMS_OUTPUT.put_line( 'l_positive_items.onhand'
    || l_positive_items.onhand
    || 'l_excl_temp'
    || l_excl_temp
    || ' l_order_qty'
    || l_order_qty);
    IF l_positive_items.onhand > 0 AND l_excl_temp < l_order_qty
    THEN
    l_line_tbl_count := l_line_tbl_count + 1;
    IF (l_order_qty - l_excl_temp) < l_positive_items.onhand
    THEN
    l_prorate_qty := l_order_qty - l_excl_temp;
    ELSE
    l_prorate_qty := l_positive_items.onhand;
    END IF;
    -- Initializing the Sales order Lines Record type
    DBMS_OUTPUT.put_line (
    'Initializing the Sales order Lines Record type'
    l_line_tbl (l_line_tbl_count) := oe_order_pub.g_miss_line_rec;
    l_line_tbl (l_line_tbl_count).operation :=
    oe_globals.g_opr_create;
    l_line_tbl (l_line_tbl_count).header_id := l_header_id;
    l_line_tbl (l_line_tbl_count).inventory_item_id :=
    l_positive_items.inventory_item_id;
    l_line_tbl (l_line_tbl_count).ship_to_org_id :=
    l_ship_to_org_id;
    l_line_tbl (l_line_tbl_count).ordered_quantity := l_prorate_qty;
    l_line_tbl (l_line_tbl_count).schedule_ship_date :=
    l_sch_ship_date;
    l_line_tbl (l_line_tbl_count).attribute1 := l_attribute1;
    l_line_tbl (l_line_tbl_count).attribute2 := l_attribute2;
    l_line_tbl (l_line_tbl_count).attribute9 := l_line_id;
    l_line_tbl (l_line_tbl_count).attribute10 :=
    ROUND (l_prorate_qty / l_order_qty * 100, 5);
    l_line_tbl (l_line_tbl_count).agreement_id := l_agreement_id;
    l_line_tbl (l_line_tbl_count).calculate_price_flag := 'Y';
    l_excl_temp := l_excl_temp + l_prorate_qty;
    END IF;
    END LOOP;
    -- To check if the total onhand is greater than zero
    DBMS_OUTPUT.put_line (
    'To check if the total onhand is greater than zero'
    IF l_onhand > 0
    THEN
    IF l_order_qty > l_excl_temp
    THEN
    -- To check whether the onhand is lesser than order qty
    DBMS_OUTPUT.put_line (
    'To check whether the onhand is lesser than order qty'
    IF (l_onhand < (l_order_qty - l_excl_temp))
    THEN
    -- Loop the cursor with exclusion of soldado logic
    DBMS_OUTPUT.put_line (
    'Loop the cursor with exclusion of soldado logic'
    FOR l_child_item
    IN c_child_items (l_segment, l_organization_id)
    LOOP
    l_prorate_percent := NULL;
    l_negative_prorate := 0;
    l_temp_count := 0;
    l_prorate_qty := 0;
    -- Initializing the Sales order Lines Record type
    DBMS_OUTPUT.put_line (
    'Initializing the Sales order Lines Record type2'
    l_line_tbl (l_line_tbl_count) :=
    oe_order_pub.g_miss_line_rec;
    l_line_tbl (l_line_tbl_count).operation :=
    oe_globals.g_opr_create;
    l_line_tbl (l_line_tbl_count).header_id := l_header_id;
    l_line_tbl (l_line_tbl_count).inventory_item_id :=
    l_child_item.inventory_item_id;
    l_line_tbl (l_line_tbl_count).ship_to_org_id :=
    l_ship_to_org_id;
    l_line_tbl (l_line_tbl_count).ordered_quantity :=
    l_prorate_qty;
    l_line_tbl (l_line_tbl_count).schedule_ship_date :=
    l_sch_ship_date;
    l_line_tbl (l_line_tbl_count).attribute1 := l_attribute1;
    l_line_tbl (l_line_tbl_count).attribute2 := l_attribute2;
    l_line_tbl (l_line_tbl_count).attribute9 := l_line_id;
    l_line_tbl (l_line_tbl_count).attribute10 :=
    ROUND (l_prorate_qty / l_order_qty * 100, 5);
    l_line_tbl (l_line_tbl_count).agreement_id :=
    l_agreement_id;
    l_line_tbl (l_line_tbl_count).calculate_price_flag := 'Y';
    END LOOP;
    ELSE
    -- Loop the cursor of all the positive buckets
    FOR l_child_items
    IN c_positive_onhand (l_segment, l_organization_id)
    LOOP
    l_prorate_percent := NULL;
    l_child_onhand := 0;
    l_prorate_qty := 0;
    -- To get the split percentage of the child items
    l_prorate_percent :=
    ROUND ( (l_child_items.trx_qty / l_onhand) * 100, 5);
    -- To check whether the prorate percentage exits
    IF l_prorate_percent IS NOT NULL
    AND l_prorate_percent > 0
    THEN
    -- To calculate the prorate quantity
    l_line_tbl_count := l_line_tbl_count + 1;
    l_prorate_qty :=
    ROUND (
    (l_order_qty - l_excl_temp)
    * (l_prorate_percent / 100),
    5
    l_qty_temp := l_qty_temp + l_prorate_qty;
    -- To calculate the prorate quantity for the last line
    IF c_positive_onhand%ROWCOUNT =
    l_child_items.total_rows
    THEN
    l_prorate_qty :=
    l_prorate_qty
    + (l_order_qty - (l_qty_temp + l_excl_temp));
    END IF;
    -- Initializing the line record type to process
    DBMS_OUTPUT.put_line (
    'Initializing the Sales order Lines Record type3'
    l_line_tbl (l_line_tbl_count) :=
    oe_order_pub.g_miss_line_rec;
    l_line_tbl (l_line_tbl_count).operation :=
    oe_globals.g_opr_create;
    l_line_tbl (l_line_tbl_count).header_id := l_header_id;
    l_line_tbl (l_line_tbl_count).inventory_item_id :=
    l_child_items.inventory_item_id;
    l_line_tbl (l_line_tbl_count).ship_to_org_id :=
    l_ship_to_org_id;
    l_line_tbl (l_line_tbl_count).ordered_quantity :=
    l_prorate_qty;
    l_line_tbl (l_line_tbl_count).schedule_ship_date :=
    l_sch_ship_date;
    l_line_tbl (l_line_tbl_count).attribute1 :=
    l_attribute1;
    l_line_tbl (l_line_tbl_count).attribute2 :=
    l_attribute2;
    l_line_tbl (l_line_tbl_count).attribute9 := l_line_id;
    l_line_tbl (l_line_tbl_count).attribute10 :=
    ROUND (l_prorate_qty / l_order_qty * 100, 5);
    l_line_tbl (l_line_tbl_count).agreement_id :=
    l_agreement_id;
    l_line_tbl (l_line_tbl_count).calculate_price_flag :=
    'Y';
    DBMS_OUTPUT.put_line( '3rd insert'
    || 'l_prorate_qty'
    || l_prorate_qty
    || 'l_ship_to_org_id'
    || l_ship_to_org_id
    || 'l_sch_ship_date'
    || l_sch_ship_date
    || 'l_child_items.inventory_item_id'
    || l_child_items.inventory_item_id
    || 'l_agreement_id'
    || l_agreement_id);
    END IF;
    COMMIT;
    END LOOP;
    END IF;
    END IF;
    ELSIF l_order_qty > l_excl_temp
    THEN
    -- Loop the cursor with exclusion of soldado logic
    FOR l_child_item IN c_child_items (l_segment, l_organization_id)
    LOOP
    l_prorate_percent := 0;
    l_prorate_qty := 0;
    l_prorate_percent := ROUND (100 / l_child_item.total_rows, 5);
    l_prorate_qty :=
    ROUND (
    ( (l_order_qty - l_excl_temp) / l_child_item.total_rows),
    5
    l_line_tbl_count := l_line_tbl_count + 1;
    l_qty_temp := l_qty_temp + l_prorate_qty;
    -- To calculate the prorate quantity for the last line
    IF c_child_items%ROWCOUNT = l_child_item.total_rows
    THEN
    l_prorate_qty :=
    l_prorate_qty
    + (l_order_qty - (l_qty_temp + l_excl_temp));
    END IF;
    -- Initializing the line record type to process
    DBMS_OUTPUT.put_line (
    'Initializing the Sales order Lines Record type4'
    l_line_tbl (l_line_tbl_count) := oe_order_pub.g_miss_line_rec;
    l_line_tbl (l_line_tbl_count).operation :=
    oe_globals.g_opr_create;
    l_line_tbl (l_line_tbl_count).header_id := l_header_id;
    l_line_tbl (l_line_tbl_count).inventory_item_id :=
    l_child_item.inventory_item_id;
    l_line_tbl (l_line_tbl_count).ship_to_org_id :=
    l_ship_to_org_id;
    l_line_tbl (l_line_tbl_count).ordered_quantity := l_prorate_qty;
    l_line_tbl (l_line_tbl_count).schedule_ship_date :=
    l_sch_ship_date;
    l_line_tbl (l_line_tbl_count).attribute1 := l_attribute1;
    l_line_tbl (l_line_tbl_count).attribute2 := l_attribute2;
    l_line_tbl (l_line_tbl_count).attribute9 := l_line_id;
    l_line_tbl (l_line_tbl_count).attribute10 :=
    ROUND (l_prorate_qty / l_order_qty * 100, 5);
    l_line_tbl (l_line_tbl_count).agreement_id := l_agreement_id;
    l_line_tbl (l_line_tbl_count).calculate_price_flag := 'Y';
    END LOOP;
    END IF;
    END IF; -- to check whether any records are initialized
    IF l_line_tbl_count > 0
    THEN
    -- Cancel the Parent Item
    DBMS_OUTPUT.put_line ('Cancel the Parent Item');
    l_line_tbl (l_line_tbl_count + 1) := oe_order_pub.g_miss_line_rec;
    l_line_tbl (l_line_tbl_count + 1).operation :=
    oe_globals.g_opr_update;
    l_line_tbl (l_line_tbl_count + 1).header_id := l_header_id;
    l_line_tbl (l_line_tbl_count + 1).line_id := l_line_id;
    l_line_tbl (l_line_tbl_count + 1).ordered_quantity := 0;
    l_line_tbl (l_line_tbl_count + 1).attribute10 := l_order_qty;
    l_line_tbl (l_line_tbl_count + 1).cancelled_flag := 'Y';
    l_line_tbl (l_line_tbl_count + 1).change_reason := 'Not Provided';
    DBMS_OUTPUT.put_line( 'Cancellation Process fileds'
    || 'HDR_ID'
    || l_header_id
    || 'LINE'
    || l_line_id
    || 'l_order_qty'
    || l_order_qty);
    -- Call the procedure to process the sales order lines
    -- process_order_line_api (p_line_tbl_rec => l_line_tbl,
    -- p_line_id => l_line_id,
    -- p_error_flag => l_error,
    -- p_error_message => l_error_message);
    IF l_error = 'Y'
    THEN
    resultout := 'COMPLETE:Y';
    ELSE
    resultout := 'COMPLETE:N';
    END IF;
    ELSE
    resultout := 'COMPLETE:N';
    END IF;
    END IF;
    BEGIN
    fnd_global.apps_initialize (fnd_global.user_id,
    fnd_global.resp_id,
    fnd_global.resp_appl_id);
    -- BEGIN
    -- MO_GLOBAL.SET_POLICY_CONTEXT ('S', 321);
    -- END;
    -- fnd_global.apps_initialize (-1, 21623, 660);
    -- Call Process Line API to process sales order lines
    DBMS_OUTPUT.put_line ('fianl line to be processd');
    BEGIN
    oe_order_pub.process_line (p_line_tbl => p_line_tbl_rec,
    x_line_out_tbl => l_line_out_tbl,
    x_return_status => l_return_status,
    x_msg_count => l_msg_count,
    x_msg_data => l_msg_data);
    COMMIT;
    DBMS_OUTPUT.put_line ('API Processed' || l_msg_data);
    fnd_file.put_line (fnd_file.LOG, 'Processed - ' || l_msg_data);
    EXCEPTION
    WHEN OTHERS
    THEN
    DBMS_OUTPUT.put_line ('Failed With1' || SQLERRM);
    END;
    -- display error msgs
    IF (l_debug_level > 0)
    THEN
    FOR i IN 1 .. l_msg_count
    LOOP
    oe_msg_pub.get (p_msg_index => i,
    p_encoded => fnd_api.g_false,
    p_data => l_data,
    p_msg_index_out => l_msg_index);
    fnd_file.put_line (fnd_file.LOG, 'message is:' || l_data);
    fnd_file.put_line (fnd_file.LOG,
    'message index is:' || l_msg_index);
    DBMS_OUTPUT.put_line (
    'l_data' || l_data || 'l_debug_level' || l_debug_level
    END LOOP;
    END IF;
    IF p_error_flag = 'N'
    THEN
    FOR i IN 1 .. l_msg_count
    LOOP
    oe_msg_pub.get (p_msg_index => i,
    p_encoded => fnd_api.g_false,
    p_data => p_error_message,
    p_msg_index_out => l_msg_index);
    END LOOP;
    ELSE
    DBMS_OUTPUT.put_line ('Out Of loop Exit');
    END IF;
    fnd_file.put_line (fnd_file.LOG, 'p_error_message - ' || SQLERRM);
    DBMS_OUTPUT.put_line ('p_error_message' || p_error_message || SQLERRM);
    EXCEPTION
    WHEN OTHERS
    THEN
    DBMS_OUTPUT.put_line ('Failed With' || SQLERRM);
    fnd_file.put_line (fnd_file.LOG,
    'Unexpected Errors Found4 - ' || SQLERRM);
    END;
    END;
    Thanks
    Shagul

  • Purchase Order History Program - not working properly

    Dear friends
    i am developing purchase order history program in ALV,
    which shows the report of purchase order status
    i.e (fields as below).
    document no
    PO date
    line item
    material number
    material name
    purchase org
    plant
    purchase group
    orderd quantity
    ordered amount
    delivered quantity
    delivered amount
    to be delivered quantity
    to be delivered amount
    invoice quantity
    invoice amount
    to be invoiced quantity
    to be invoiced amount
    how to test from me23n
    open me23n
    enter PO number
    press status tab
    you can get some fields for verification..
    the problem is
    i can get all the details correctly except delivered amount and to be delivered amount
    it works fine in both ( material purchase order and service purchase order )
    sometimes i am getting incorrect values in service purchase order specifically in delivered amount and to be delivered amount
    why i am getting these incorrect values ??
    only couple of POs generate these things.
    i am getting these values from EKBE table and using proper filtration like movement type and etc...
    if anyone can resolve ... would be appreciable
    avirat.

    Hi,
    for getting proper Po History you need to select PO's details from EKKO table and
    Header details from CHANGEDOCUMENT_READ_HEADERS based on the details got from this FM pass
    to the FM CHANGEDOCUMENT_READ_POSITIONS and get proper details.
    This is the logic used by the standard program also to get the PO History.
    Hope this helps.
    Regards
    Bikas

Maybe you are looking for

  • Problems in Pro*C installation for Oracle 8.1.7 on Redhat Linux 6.2

    Hello, I have installed Oracle 8.1.7 on Redhat Linux 6.2. After installing Proc and doing necessary changes in pcscfg.cfg file. I tried to compile demo programs. But I am getting following error while compiling. Syntax error at line 368, column 19, f

  • Program to Print Preview from Spool

    Hello gurus, I hope you guys could help me out...my requirement is to write an ABAP program that receives a spool number and displays its print preview to the user from there user can choose to print or delete the spool number Any advices ?:)

  • InfoPackage selection offset with OLAP variable

    Hi Bw Gurus, I have a requirement to load ODS with full upload everytime but in order to reduce repeated loads I am trying to use a DATE field which is not part of communication str. as a selection critera in InfoPacakge. I changed DS to include this

  • Threats and more threats - they keep coming!!

    Briefly, I am a senior with hearing and sight difficulties, but no 'prejudices'.    I cannot hear and understand non-standard English accents very well, hence I ask for all communications (with all companies, not just BT) to be other than the spoken

  • Report painter layout variants

    Dear sirs, a colleague of mine needs your experience. Our customer needs us to create some Report Painter reports with the possibility to change the layout. Is this/ something like this possible? An example would be to pick up the columns or to chang