Order by absolute value

Hi,
I am trying to write a SQL query which returns the % difference between 2 columns in a table, in sorted descending order, based on the absolute value.
The statement goes like this:
SELECT ((col1 - col2)/col2)*100
FROM table1
WHERE col2 > 0
UNION
SELECT 100
FROM table1
WHERE col2 = 0
ORDER BY 1 DESC
What I really want is the ORDER BY clause to be something like this:
ORDER BY ABS(1) DESC
However, that results in the following error:
ORA-01785: ORDER BY item must be the number of a SELECT-list expression
Does anyone have a nice, efficient way for fixing the SQL query?
Thanks!

Add another column to your select, and order by that:
SELECT ABS(((col1 - col2)/col2)*100),
((col1 - col2)/col2)*100
FROM table1
WHERE col2 > 0
UNION
SELECT 100, 100
FROM table1
WHERE col2 = 0
ORDER BY 1 DESC
null

Similar Messages

  • Cash Discount in absolute value, not in %

    Hello Friends,
    I have a scenario with respect to terms of payment, where the customer is entitled for a cash discount of Rs.100 per unit if the invoice is cleared within 7 days from the date of invoice, Rs.75 per unit within 14 days & Rs.50 per unit within 21 days with total credit period of 45 days.
    The problem I'm facing is that in the Terms of Payment configuration (transaction code OBB8), I'm able to store the cash discount in % and not in absolute value (field "percentage" under the "Payment Terms" heading in tcode OBB8).
    Request your suggestion at the earliest.
    Thnx & Rgds,
    Padmanabhan

    Hi,
    The CASH DISCOUNT will be given based on the Payment terms  with the CONDITION TYPE.
    In the Standard the CASH DISCOUNT condition types are SKTO & SKTV.
    If you are using the same condition types, change the CALCULATION TYPE  for these condition types in V/06  to B ( which is fixed amount)  and try.
    Hope it will solve your requirement.
    regards,
    santosh

  • Open Purchase Orders at Retail Value

    Hi
    I need to show Open Purchase Orders at Retail Value in one of my reports and I am using the key figure - "Open Purchase Orders (Retail Price) - 0RTOPDVSV".
    I am using this KF in the cube ZRT_STWK which is part of a multiprovider. Data to this cube is being pulled from 2LIS_03_BF. I couldn't find a probable field in ECC to which I can map the field 0RTOPDVSV in the cube.
    Any idea what the likely field could be in ECC which I can map to the key figure 0RTOPDVSV?
    Any help is appreicated.
    Thank you.
    Pavan.

    Hi,
    To prepare the Open PO report:
    Take all the purchase order details from EKKO and EKPO tables by writing a JOIN based on the selection screen paramters:(into ITAB)
    Then fetch the related GR and GI data from the table MSEG for each PO Item (using for all entries of ITAB passing EBELn and EBELP to MSEG).
    Here based on the movement type you have to consider the GR or GI.
    generally for 101 movement types it is fresh GR(goods receipt).
    so in this table MSEG you have many entries with different movement types for each PO items, so summing up the correct quanitities(ERFMG) for GR and other s is importants.So from ITAB you know the PO qty for a particular PO and from MSEG you know the qty received(GR QTY), if the both qty's are equal then that order is closed, if bothe qty's are not equal then that order is OPEN.
    Fetch the invoice related data from EKBE or RSEG tablse passing EBELN and EBELP fields for them.
    GR dat is in MSEG
    and Invoice data is in EKBE  or RSEG.
    Hope this is useful.
    regards,
    Anji

  • Change in Purchase Order Release Strategy Values

    Dear All,
    I am in process of changing Purchase Order release strategy values.
    I have following release strategy -
                           Current Value                  (Proposed Value)
    Level 1 -         Upto INR 0.1 Mn               (Proposed value - Upto 1.0 Mn)
    Level 2 -         From 0.11 Mn to 0.5 Mn   (Proposed Value - From 1.01 Mn to 5.00 Mn)
    Level 3 -         From 0.51 Mn to 1.0 Mn   (Proposed Value - From 5.01 Mn to 10.0 Mn)
    Level 4 -         Above 1.0 Mn                  (Proposed Value - Above 10.0 Mn)
    My questions are -
    1) Will this change affect the existing Purchase Orders (already created) which are not yet released?
    2) Will this change affect the existing Purchase Orders (already created) which are released?
    3) Are there any risk factors?
    Can you pl. put light on above questions?
    Regards,
    Prashant Kolhatkar

    Hi,
    Actually, what you had given is not enough to determine if the existing PO will be impacted or not
    If you are just changing the classification but not changing the number of release level of the release code in the release strategy, the partial released PO will not be impacted unless there's PO changes. PO that are released will definitely not be impacted unless there are changed.
    In general, after a release strategy is determined for PO, SAP will retrieve the latest list of release code of that release strategy for display for that PO. If this list never change (mean you only change classification of the release strategy), then they will not be apparent to the user. But if this list change (you add new release code, replace existing release code or remove release code), then you will see some discrepency on screen as you will only see the modified list of release code and not the old list of release code
    Hope this help

  • Purchase order with Freight Value

    Dear All,
    My scenario is....
    I Purchase some material to my x vendor. when he send the material , he charge freight amount on it. now please suggest me how to create a purchase  order with freight value & I want to take freight effect on every material. vendor is not divide freight amount on every material. now what will i do. If i take this effect only one material than My material map get change. How to take this effect on every material.
    Regards
    Vimal

    Hi,
    When vendor send material , vendor send firght value invoicce, means at the time of PO you don't know it,so it can be consider as unplanned delivery cost in SAP and you can post this cost in MIRO ,on details tab in unplanned delivery field.
    In following path you can decide where this value should add in material cost or G/l account in following path
    In SPRO ,Maintain settings as shown  MM---> Logistic Invoice Verification -->Incoming Invoice --> Configure How unplanned delivery costs are posted
    Regards
    Kailas Ugale
    Edited by: kailasugale on Dec 14, 2011 10:21 PM

  • Change the Purchase Order : Item - Conditions value

    Hi,
    How to change the Purchase Order : Item - Conditions value.
    In my PO, Item conditions shows the SKTO - Cash Discount value is 0. I want to change the Discount value 10.
    How can i change it??

    Hi,
    Goto the Transaction code MN05 and give the CONDITION TYPE SKTO and change the value
    MN05 is the Transaction code for Purchase order  condition types.
    Please check and revert back if you need more details.
    regards,
    santosh

  • Report similar to MC$4 that does not show absolute values

    Hi all,
    We need a report similar to Report similar to MC$4 which has the same drilldown capabilities but does not show absolute values, and instead shows the proper (actual) values.
    Or if its possible to change something in the MC$4 report to show the actual values and not the absolute.
    Thanks in advance!
    George

    HI
    Your input criteria should contain all plant numbers and the period to be analyzed.  Execute the report and then select:  Plant Analysis\Export\Transfer to XXL\Deselect all options and tick Plant, Storage Location and Month.  Follow the options to export to Excel.  Report will be based on Plant, Storage location and Month.
    Regards

  • Throw Information message for sale order created with value less that 5$

    Hi all,
            I am basically an abaper, I have got a requirement in SD. The requirement is any sales order created with value less that 5$, should be prompted with an error message saying the minimum order value should be more than 5$. Could any one help me on this.
    Thanks in advance,
    shiv

    userexit_save_document_prepare,main program - sapmv45a, issue an error message if your document value is less than 5$ (VBAK-NETWR) but check if your order has any non-rejected item, I would not issue this message if all items are rejected:
    loop at xvbap where updkz ne 'D' and abgru = ' '.
      exit.
    endloop.
    if sy-subrc = 0.  "-you have at least one non-rejected, non-deleted item.
    NOTE: sapmv45a works NOT only for orders, so please check document types in your logic which are relevant to your messge only (VBAK-VBTYP and/or VBAK-AUART).

  • Absolute value in ckf, performance effect?

    Hello BW Experts,
    req: always show positive values for one kf1 of a cube, even if you have negative values for kf1.
    options:
    create a ckf1 with the absolute value of kf1
    -- 1) are there any other options in the backend or frontend?
    -- 2) what are the performance effects of the abosolute function option as compared to having a kf in the cube.?
    Suggesions appreciated.
    Thanks,
    BWer

    Hi,
    You can multiply the values with -1 on the backend side or in the query itself there is an option of reversing the sign in the settings.
    Cheers,
    Kedar

  • Absolute Value in Transformation level

    Hi Team,
    I want to insert abolute value in Transformation routine level.Pl provide me the routine code to instert absolute value of Exchange Rate.
    I have tried to put below code but its not working.
    ABS(Exchange Rate).
    Regards
    Ramakanth.

    Hi,
    In your case, I'd strongly recommend you to use formula instead of routines (where you do have absolute function working).
    If you still want to go for Routine:
    data: abs_val type f.
    if SOURCE_FIELDS-EXRATE_ACC < 0.
    abs_val = SOURCE_FIELDS-EXRATE_ACC * -1.
    else.
    abs_val = SOURCE_FIELDS-EXRATE_ACC.
    endif.
    RESULT = SOURCE_FIELDS-NETVAL_INV * abs_val.
    --Akashdeep

  • Absolute value discount in Special Prices

    I have a customer that has special prices with a value discount, not a percentage one.
    I thought about adding a UDF to the Special Prices table and do a formatted search against it, but later I found that I cannot add an UDF to the Special Prices table...
    All the discount functionality in SBO is percentage based...how should I implement an absolute value discount?
    Any ideas will be much appreciated...

    Hi.
    This is sample code in C++ to add UDF.
    _bstr_t TableName = L"TableUID";
    _bstr_t FieldName;
    HRESULT hr;
    SAPbobsCOM::IUserFieldsMDPtr m_pUserFieldsMD = m_Cmp->GetBusinessObject( SAPbobsCOM::oUserFields );
    m_pUserFieldsMD->PutTableName(TableName);
    FieldName = L"FieldUID";   'without U_'
    m_pUserFieldsMD->PutType(SAPbobsCOM::db_Alpha);
    m_pUserFieldsMD->PutName( FieldName );
    m_pUserFieldsMD->PutDescription( L"desc");          
    m_pUserFieldsMD->PutSize(20);
    m_pUserFieldsMD->PutEditSize(20);
    if ( m_pUserFieldsMD == NULL )
    return -1;
    m_Cmp->StartTransaction();
    hr = m_pUserFieldsMD->Add();
    if (hr!=S_OK)
    'error'
    if ( m_Cmp->InTransaction )
    m_Cmp->EndTransaction( SAPbobsCOM::wf_Commit );
    Hope it helps.
    Kamil Wydra

  • How to get Production Order wise Actual Values

    Dear CO Experts,
    How to get Actual Values (Raw Material Issue, Activity Confirmations & OH Calculations & Goods Receipts from Production) each Production Order wise ?
    My Scenario is Product Cost Collectors (PCC)  with Production Orders.
    If we select above scenario Production Order is Statistical and PCC is real cost object.
    For PCC is Period wise we can track the cost Periodically in individual Material.
    But my client is asking how to see the each Production Order wise Actual values. Is there any T.Code ??
    In Production Order I am able to see only Plan values (CO03).
    Waiting for your favorable reply.
    Regards,
    KBR.

    Hi Bhaskar
    You are in Alaska and you wanna eat vegetarian food
    You cant get values at Prod order level if you have chosen PCC as cost object.... You will only get Qty at Prod order level
    To get a bird's eye view of costs incurred in PCC, execute report MCRY with PCC as the input...  MCRX shows only Qty info for components
    br, Ajay M

  • Is it possible to create purchase order with zero value ?

    Is it possible to create purchase order with zero value ?

    Hi,
    There are two scenarios where the purchase order is created with zero value.
    1. Standard Purchase order with Free tick indicator.
    Whenever we expect a material with free of cost from vendor, we use to put the free indicator in item overview.  This means the material is valuated at zero price irrespective of price control in material master. Quanitiy is updated while receipts.
    Conditions tab in item detail doesnt appear.
    2. Consignment PO.
    While creating a purchase order for consignment, the system doesnt ask us the price and the condition tab doesnt appear in item detail.
    An info record for consignment must be maintained before making the GR.
    Hope i have clarified.  If you want any further clarification. please do reply.

  • Is there any function module to give absolute value of a number?

    Hi,
    Is there any function module to give absolute value of a number?
    That has similar functionality to the Built in Function ABS.
    Please let me know.
    Thanks,
    cs

    hi,
    why are you looking for any function module.
    You can easily get it by mathematical function ABS .
    Syntax : <Turget Variable> = ABS <Source Variable>
    \[removed by moderator\]
    Anirban Bhattacharjee
    Edited by: Jan Stallkamp on Jun 27, 2008 4:19 PM

  • HOW TO KNOW THE  EACH PURCHASE ORDERS GROSS INVOICE  VALUE

    HI SIR,
    ANY  BODY PLESAE TELL ME
    HOW TO KNOW THE  EACH PURCHASE ORDERS GROSS INVOICE  VALUE BY GROUP WISE PER SPECIFIC TIME PERIOD.

    hi
    try ME80FN
    regards
    vijay

Maybe you are looking for

  • Where is the iPhoto in latest version of IOS in Macbook air..they got rid of it!!

    Ok,I am going CRAZY!! So my MacBook air just crashed, right so I went to the Apple Store a few hours ago, and they restarted everything so I have to start from scratch. Then the lady asked "would you like me to install the new version of the latest I

  • How to validate and transform large (180M) xml files

    Hi: I've been looking at various ways to do this with oracle and am getting a bit lost in the sea of documentation and different ways to go about this. I was hoping that something like the XMLParser class and XMLTransform would be smart enough to han

  • Creating Invoices on Specific Dates

    Hello Gurus,           you can process invoices periodically. All deliveries due for billing on a certain date can be combined into one collective invoice.           To do this, you must first: &#159; maintain individual billing dates in the factory

  • Portal Installation Error in NW2004S

    Input Error: The Solution manager key is not valid.Enter the correct key for host 'otisap11', the system ID 'O11' and the central instance number '12'.

  • How to enable an existing Extended Events Session or add a new Session?

    Hi, I am using Management Studio version 12.0.2000.8 and I have noticed that Extended Events for Azure SQL DB have been added to it. However, I can't add a new session because the option is grayed out in the dropdown menu. Also, the existing sessions