How to update the COST column using another table's column

Dear All,
I have table:
table parts: pno, pname, qoh, price, olevel
table orders: ono, cno, eno, received, shipped
table odetails: ono, pno, qty
view:orders_view: ono, cno, eno, received, shipped,sum(qty*price)order_costview:odetails_view: ono, pno, qty, (qty*price)cost
after I update the price in parts, I need to update COST and ORDER_COST too. The orders_view does not have pno, qty, and price, the odetails_view does not have price, how can I update the COST and ORDER_COST. Please help and Thanks in advance!!!
I wrote the update the price in parts:
create or replace procedure change_price(ppno in parts.pno%type, pprice in parts.price%type) as
begin
    update parts
    set price = pprice
    where pno = ppno;
end;
show errorsthis procedure works fine.
I wrote the trigger:
create or replace trigger update_orders_v
after update of price on parts
for each row
begin
    update orders_view
    set order_cost = sum(parts.(:new.price)*parts.qty)
    where parts.pno = :new.pno;
end;
show errorsIt gives me:Errors for TRIGGER UPDATE_ORDERS_V:
LINE/COL ERROR
3/5 PL/SQL SQL Statement ignored
4/22 PL/SQL ORA-00934: group function is not allowed hereplease help!

You could add the columns to the tables and then you would need a trigger to update those columns. However, you could just as easily select the price * qty to get the cost, without creating an additional column or trigger. I have no idea what you might want to do with a global temporary table. I think you need to explain what your purpose is, before any of us can suggest the best method. Since I have already demonstrated an update with a view, I will demonstrate an update with the cost column added to the odetails table and a trigger as you asked about. Notice that you will need triggers on both tables, the one that has qty and the one that has price.
scott@ORA92> create table parts
  2    (pno    number(5) not null primary key,
  3       pname  varchar2(30),
  4       qoh    integer check(qoh >= 0),
  5       price  number(6,2) check(price >= 0.0),
  6       olevel integer)
  7  /
Table created.
scott@ORA92> create table odetails
  2    (ono    number(5),
  3       pno    number(5) references parts,
  4       qty    integer check(qty > 0),
  5       cost   number,
  6       primary key (ono,pno))
  7  /
Table created.
scott@ORA92> create or replace procedure change_price
  2    (ppno   in parts.pno%type,
  3       pprice in parts.price%type)
  4  as
  5  begin
  6    update parts
  7    set    price = pprice
  8    where  pno = ppno;
  9  end;
10  /
Procedure created.
scott@ORA92> create or replace trigger update_cost1
  2    after insert or update of price on parts
  3    for each row
  4  begin
  5    update odetails
  6    set    cost = qty * :new.price
  7    where  pno = :new.pno;
  8  end update_cost1;
  9  /
Trigger created.
scott@ORA92> show errors
No errors.
scott@ORA92> create or replace trigger update_cost2
  2    before insert or update of qty on odetails
  3    for each row
  4  declare
  5    v_price parts.price%type;
  6  begin
  7    select price
  8    into   v_price
  9    from   parts
10    where  pno = :new.pno;
11    --
12    :new.cost := :new.qty * v_price;
13  end update_cost2;
14  /
Trigger created.
scott@ORA92> show errors
No errors.
scott@ORA92> insert into parts values (1, 'name1', 1, 10, 1)
  2  /
1 row created.
scott@ORA92> insert into odetails values (1, 1, 22, null)
  2  /
1 row created.
scott@ORA92> -- starting data:
scott@ORA92> select * from parts
  2  /
       PNO PNAME                                 QOH      PRICE     OLEVEL
         1 name1                                   1         10          1
scott@ORA92> select * from odetails
  2  /
       ONO        PNO        QTY       COST
         1          1         22        220
scott@ORA92> -- update:
scott@ORA92> execute change_price (1, 11)
PL/SQL procedure successfully completed.
scott@ORA92> -- results:
scott@ORA92> select * from parts
  2  /
       PNO PNAME                                 QOH      PRICE     OLEVEL
         1 name1                                   1         11          1
scott@ORA92> select * from odetails
  2  /
       ONO        PNO        QTY       COST
         1          1         22        242
scott@ORA92> -- select works without extra cost column or trigger:
scott@ORA92> select o.ono, o.pno, o.qty, (o.qty * p.price) as cost
  2  from   odetails o, parts p
  3  where  o.pno = p.pno
  4  /
       ONO        PNO        QTY       COST
         1          1         22        242
scott@ORA92>

Similar Messages

  • How to update the FB01L transaction using the FM  bapi_acc_document_post

    Hi All,
            How to update the FB01L transaction using the bapi_acc_document_post but there is no ledger group field in the bapi function module.
    Please help me how to do it.

    hi,
    use batch input method for the same.
    check this.
    [https://forums.sdn.sap.com/click.jspa?searchID=19107237&messageID=884744]

  • How to update the ztable by using table handling function

    how to update the ztable by using table handling function
    It is very urgent ...............................
    thanks in advance

    see the  below code for the direct   ztable update
    Report  ZUPDATE_PRPS.
    tables: zprps.
    parameter: p_wbs like zprps-pspnr,
               p_value like zprps-fakkz default 'X'.
    data: wa_fakkz type zprps-fakkz.
    *START-OF_SELECTION
    start-of-selection.
    call function 'CONVERSION_EXIT_ABPSP_INPUT'
         exporting
             input     = p_wbs
        importing
             output    = p_wbs
        exceptions
             not_found = 1
             others    = 2.
    select single fakkz
      into wa_fakkz
      from zprps
    where pspnr eq p_wbs.
    if sy-subrc eq 0.
       update zprps set fakkz = p_value where PSPNR eq p_wbs.
       if p_value is initial.
         message i999(za) with 'Billing element field has been unchecked'.
       else.
         message i999(za) with 'Billing element field has been checked'.
       endif.
    else.
      message i999(za) with 'WBS element not found'.
    endif.
    reward  points if it is usefull .....
    Girish

  • Need to update multiple columns using another table

    I have 2 tables. and i need to update rows of 1 table using another table
    Table1
    Serial_no.     payment_date     Payment_amt
    101     22/11/2010     150
    101     18/03/2011      355
    102     15/04/2011      488
    103     20/05/2011      178
    102     14/06/2011      269
    101     28/06/2011      505
    Table2
    Serial_no     Charge_amt      Last_paymt_dt     Last_paymt_amt
    101     255
    102     648
    103     475
    I want to update Last_paymt_dt and Last_paymt_amt of table2 using Table1, I have written following update statement but it gives error that single row subquery return multiple row.
    Update Table2
    set (Last_paymt_dt,Last_paymt_amt) = (select max(payment_date, payment_amt) from table1
    where table1.Serial_no = table2.Serial_no group by payment_amt)
    kindly suggest how should i update.

    SQL> select * from table1
      2  /
    SERIAL_NO PAYMENT_DA PAYMENT_AMT
           101 22/11/2010         150
           101 18/03/2011         355
           102 15/04/2011         488
           103 20/05/2011         178
           102 14/06/2011         269
           101 28/06/2011         505
    6 rows selected.
    SQL> select * from table2
      2  /
    SERIAL_NO CHARGE_AMT LAST_PAYMT LAST_PAYMT_AMT
           101        255
           102        648
           103        475
    SQL> update  table2
      2     set  (last_paymt_dt,last_paymt_amt) = (
      3                                            select  max(payment_date),
      4                                                    max(payment_amt) keep(dense_rank last order by payment_date)
      5                                              from  table1
      6                                              where table1.serial_no = table2.serial_no
      7                                           )
      8  /
    3 rows updated.
    SQL> select * from table2
      2  /
    SERIAL_NO CHARGE_AMT LAST_PAYMT LAST_PAYMT_AMT
           101        255 28/06/2011            505
           102        648 14/06/2011            269
           103        475 20/05/2011            178
    SQL> SY.

  • How to update the datasource 0CRM_LEAD_H using the BWA1 t-code from CRM

    Hi all,
    I would like to know how I can update the extractor 0CRM_LEAD_H from BWA1 t-code in CRM.
    If I see the datasource thru RSA5 the extract structure doesn't have the STATUS_LEAD field. but thru BWA1 I see the field in the extract structure, and the field has an "A" in the Selection column and I can't change it, the values could be:
    Field Attribute     Short Description
    A          Field in OLTP and BW Hidden by SAP
    M          Selection Required, Visible
              No Selection Possible, Visibility Set
    P          Selection Adjustable, Visibility Set
    X          Selection Adjustable, Visibility Set
    1          Pure Selection Field, Selection Set
    2          Pure Selection Field, Selection Set
    3          Selection Adjustable, Visibility Adjustable
    4          No Selection Possible, Visibility Adjustable
    The field is not In the Mapping tab.
    Do you know how I can include the field in the extraction?
    Regards, Federico

    In CRM badis are only used to do enhancement either for EEWB or enhancements (with filter or non filter).
    Still the standard exits (EXIT_SAPLRSAP_001,..004) can be used for populate the appened extract structure.
    How ever you can apply some tricks to make a dynamic call to function module.. or class methods (as the subroutine call are not advisable in OOPs concept)..
    Thanks,
    -J

  • How to Update the APC values in another Depreciation Area

    Hi
    We have an issue that:
    Due to our configuration mistakes the past values have not posted to our depreciation area 15 (Tax depreciation) and our Group Assets are not updated with these values. Now we have rectified the configuration but we want to update the already posted values in depreciation area 15 (Group Assets).
    How we can update the same.
    Thanks in advance to all.

    You can use transaction ABSO and use a copy from the transaction type 158 Gross interco.transf.acquis. prior-yr acq.
    You have to create a new transaction type copy from 158 and Limit Transaction Types to Depreciation Area 15
    TC SPRO: Financial Accounting / Asset Accounting / Transactions / Acquisitions /  Define Transaction Types for Acquisitions

  • How to update the Weekly data using BAPI for MD61

    Hi All,
    i have used two BAPI's in my Z program to upload data from flat file to sap-system (BAPI_REQUIREMENTS_GETDETAIL and BAPI_REQUIREMENTS_CHANGE) and i uploaded the Monthly Data from the flat file on sap system successfully.
    but i have to also upload the Weekly Data on the sap system using BAPI.
    is there any BAPI for the same or what can be the solution for the uploading weekly data on sap system ?
    Please reply me.
    Thanks in advance..
    Edited by: Prajapati_Shyam on Dec 29, 2010 4:19 PM

    Hi Jovito,
    thanks for your reply,
    i developed a Z program to upload monthly data as well as weekly data into tcode MD61 by selecting the radio button weekly or monthly but i am not able to upload the weekly data as i didnt' get any BAPI OR any other logic to upload weekly data Or not able to use the existing BAPI BAPI_Requirement_create , because the upload file is in monthly format.
    MD61 tcode can be used for both data (Monthly or weekly data).
    can you suggesst me any BAPI to upload the weekly data or any other logic for the same
    thanks & regards
    Prajapati

  • How to update the sent mail using SO_NEW_DOCUMENT_ATT_SEND_API1

    I have a requirement to update/ append the sent mail like a trail.Since i am sending mails using SO_NEW_DOCUMENT_ATT_SEND_API1, how can i update new contents to sent mails using this RFC???Please help me.

    you may have to store content of each time mail send then only, you can send with history.

  • How to update the Nokia 1520 using sd card

    I have a Lumia 1520. I do not have a WiFi connedtion for phone updates. The first update I did was yesterday and I had to find a free wifi hotspot. I understand that you can do this via a computer to micro SD card to phone. How do I do this? I can find no guide to tell me how as I have searched this site, google and Nokia + Windows Phone sites and can find nothing. I 'think' I can down load latest updates to my computer and move it to a SD card but how do I get the phone to run/install the update.
    A how to guide would be nice for this as its inconvienent to search out wifi hotspots all the time.
    Thanks again for any help! 
    Solved!
    Go to Solution.

    http://discussions.nokia.com/t5/Nokia-Lumia/Several-questions-about-Lumia-1520/m-p/2379301#M88118
    The silence will fall

  • How to read the data from an internal table,when column names are known

    Hi All
    I have a specific requirement. I got an internal table with many fields (let it be my_tab).  Some of the fieldnames (column names in internal table my_tab) are stored in separate internal table(let it be my_fields).
    I need to store/read data corresponding to the fields (whose name is stored in my_fields) from my_tab.
    I am able to build dynamic table (referred by field-symbol) with respect to the given field names in my_fields.
    But i am unable to read the data corresponding to the fieldnames from my_tab.
    Please provide  me some pointer in this regard.
    Regards
    Swetabh Shukla

    HI All
    Thanks for the prompt response. I got solution for my question. Please check below thread. For quick reponse i posted my question in one more category. Thanks to all of you.
    How to read internal table w.r.t. fieldnames stored in other table

  • How to update the connection of a "command table"?

    We use DataSets with MySQL ODBC connections to pass the data to the report with setDataSource() in C#.
    The report works fine until we try to add a SQL Command Table. We get the usual "Failed to open the connection.":
    Crystal Report Windows Forms Viewer
    Failed to open the connection.
    Failed to open the connection.
    PerformanceReport(cas) {F752A44A-9725-49D8-9F08-BCD752CCAA0E}.rpt
    Of course, the connection used to design the report doesn't exist on the production PC.
    How can we resolve this?
    We use Crystal Reports 2008 v12.0.0.683 with Visual Studio .NET 2008 SP.

    Crystal Reports 2008 v12.0.0.683 was not supported with .NET 2008. You must apply at least Service pack 1:
    https://smpdl.sap-ag.de/~sapidp/012002523100006555792009E/cr2008win_sp1.exe
    See if that helps.
    One thing I am not clear on is; how are you adding the SQL Command Table? Can you add the Command Table to the report in the CR designer?
    Ludek

  • How to Update the oracle toad column value in table by using SSRS 2008

    Hi Team,
    How to update the oracle DB table column value by using SSRS 2008.
    Can any one help me on this.
    Thanks,
    Manasa.
    Thank You, Manasa.V

    Hi veerapaneni,
    According to your description, you want to use SSRS to update data in database table. Right?
    Though Reporting Services is mostly used for rendering data, your requirement is still can be achieved technically. You need to create a really complicated stored procedure. Pass insert/delete/update and the columns we need to insert/delete/update as
    parameters into the stored procedure. When we click "View Report", the stored procedure will execute so that we can execute insert/delete/update inside of the stored procedure. Please take a reference to two related articles below:
    Update Tables with Reporting Services – T-SQL Tuesday #005
    SQL Server: Using SQL Server Reporting Services to Manage Data
    If you have any question, please feel free to ask.
    Best Regards,
    Simon Hou

  • The workflow could not update the item, possibly because one or more columns for the item require a different type of information using Update Item action

       I got error  "The workflow could not update the item, possibly because one or more columns for the item require a different type of information "I  found out the cause is  Update Item action       
    I need to update item in another List call Customer Report ,the field call "Issues"  with data type  "Choice"   to yes
    then the error arise .   please help..

    Thanks for the quick response Nikhil.
    Our SPF 2010 server is relatively small to many setups I am sure. The list with the issue only has 4456 items and there are a few associated lists, eg lookups, Tasks, etc see below for count.
    Site Lists
    Engagements = 4456 (Errors on this list, primary list for activity)
    Tasks = 7711  (All workflow tasks from all site lists)
    Clients = 4396  (Lookup from Engagements, Tslips, etc)
    Workflow History = 584930 (I periodically run a cleanup on this and try to keep it under 400k)
    Tslips = 3522 (Engagements list can create items here, but overall not much interaction between lists)
    A few other lists that are used by workflows to lookup associations that are fairly static and under 50 items, eg "Parters Admin" used to lookup a partners executive admin to assign a task.
    Stunpals - Disclaimer: This posting is provided "AS IS" with no warranties.

  • From two given tables, how do you fetch the values from two columns using values from one column(get values from col.A if col.A is not null and get values from col.B if col.A is null)?

    From two given tables, how do you fetch the values from two columns using values from one column(get values from col.A if col.A is not null and get values from col.B if col.A is null)?

    Hi,
    Use NVL or COALESCE:
    NVL (col_a, col_b)
    Returns col_a if col_a is not NULL; otherwise, it returns col_b.
    Col_a and col_b must have similar (if not identical) datatypes; for example, if col_a is a DATE, then col_b can be another DATE or it can be a TIMESTAMP, but it can't be a VARCHAR2.
    For more about NVL and COALESCE, see the SQL Language manual: http://docs.oracle.com/cd/E11882_01/server.112/e26088/functions119.htm#sthref1310
    I hope this answers your question.
    If not, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) for all tables involved, and also post the results you want from that data.
    Explain, using specific examples, how you get those results from that data.
    Always say which version of Oracle you're using (e.g., 11.2.0.2.0).
    See the forum FAQ: https://forums.oracle.com/message/9362002

  • How to update the data in sqlserver table using procedure in biztalkserver

    Hi,
    Please can any one answer this below question
    how to update the data in sqlserver table using procedure in biztalkserver
    while am using executescalar,typedprocedure getting some warning
    Warning:The adapter failed to transmit message going to send port "SendtoSql1" with URL "mssql://nal126//MU_Stage2?". It will be retransmitted after the retry interval specified for this Send Port. Details
    Please send me asap....
    Thanks...

    Hi Messip,
    A detailed error would have helped us to answer you more appropriately but
    You can follow the post which has step by step instructions, to understand how to use Stored Procedure:
    http://tech-findings.blogspot.in/2013/07/insert-records-in-sql-server-using-wcf.html
    Maheshkumar
    S Tiwari|User
    Page|Blog|BizTalk
    2013: Inserting RawXML (Whole Incoming XML Message) in SQL database

Maybe you are looking for

  • Error while reversing goods issue using VL09

    Hi All ,   user is getting the error " 4902546971document does not contain any selectable items "  when reverse the GI using  VL09. Please find the below document flow. Free of Charge 70475917 / 10 . Purchase order 9900099037 / 10 . Delivery Standard

  • Error for object oriented alv running in background.

    Hi all, I have an  ALV report done using object oriented functionality. When I am trying to run that report in background , it is giving me error. I want to know why it is happening and how it can be corrected. Regards,    Vaibhav.

  • Hol calender FM

    Function Module Related to Holiday calender My scenrio to fetch Data from Holiday calender

  • Duplicate audio channel

    I recently recorded a wedding with my DV camcorder. I used a lapel microphone as the audio (connected to my camcorder's mic input jack). Unfortunately, this audio is only heard from the left speaker. I would like it to be heard from both left and rig

  • Customize rendering the Text Caption of the Header/DefaultSingleColumn

    in OAF R12 (Swan), The pagelayout region renders its title with a text and a horizontal line. I want the Header or DefaultSingleColumn(or DoubleColumn) region to render similarly as the pageLayout region. What css selectors do i need to specify? than