PLSQL Code for Substracting / Reducing Quantity

Hi All
I have two tables Cash and Product. Cash table has cash related sales in it. Product has product information in it.
End user selects the products and specifying their quantity in cash form then saves it. The quantity must be reduced or deducted form product table before the next cash sale is booked in cash so it will reflect the actual stock or quantity of product.
My question is how to know the end user has selected which product and it's quantity?
What would be the code?
Best Regards
Thunder2777

Hi,
If you don't already have one, add a quantity_in_stock column to the product table, with a check constraint that guarantees this column is greater than or equal to 0.
Add a trigger to the cash table, to change product.quantity_in_stock when any change is made to the cash table, somehting like this untested example:
CREATE OR REPLACE TRIGGER     cash_bdiu
BEFORE     DELETE OR INSERT OR UPDATE
ON     cash
FOR EACH ROW
DECLARE
     net_amt     NUMBER     := NVL (:NEW.quantity;, 0);
BEGIN
     IF  :OLD.quantity != 0
     THEN     -- Add back old quantity
          IF  :OLD.product != :NEW.product
          THEN     -- undo previous transaction
               UPDATE  procuct
               SET     quantity_in_stock := quantity_in_stock + :OLD.quantity
               WHERE     product_id       = :OLD.product_id;
          ELSE     -- combine with normal update below
               net_amt := net_amt - :OLD.quantity;
          END IF;
     END IF;
     IF  net_amt != 0
     THEN
          UPDATE  product
          SET     quantity_in_stock := quantity_in_stock - net_quantity
          WHERE     product_id       = :NEW.product_id;
     END IF;
END;Most of the complexity is due to handling situation like:
(a) a row is deleted
(b) a row is updated with a different quantity
(c) a row is updated with a different product_id (and perhaps a different quantity)
We want to avoid doing two UPDATES on the same row of product in the same call to this trigger. That's why I used the local variable net_amount.

Similar Messages

  • How to create plsql code for a snowflake cube

    hi everybody!
    do anyone know how to create plsql code for a snowflake tiype dimension to create
    a cube?how to map the atributes, or if there are any exceptional atributes which I can use like in a temporal dimension?
    thank you
    waiting for any answer

    The DBMS_AWM package provides stored procedures for creating an analytic workspace cube from a star schema. Is it posible to create a cube from a snoflake schema?

  • How to explicitely write PLSQL code for "Help - Display Error"? [SOLVED]

    I'm using menu DEFAULT&SMARTBAR and I'd like to write command in PLSQL code for "Help - Display Error" to display error. Has anyone any idea how to do this? I can not find syntaks in form help for this.
    Message was edited by:
    marussig

    Display_Error;

  • Plsql code for button.....

    i have a page which contain fields term_id,*term_desc*,*term_condition*
    and some buttons Add,*delete* and save..
    Actually no data in the table..
    when i press Add button the term_id should get increment by '1' .
    where i have to wite the below coding in Edit Add button?
    can i put the coding in Conditional Item Display condition type PLSQL?
    declare
    a number;
    begin
    select max(nvl(term_id,0))+1 into a from term_creation;
    *:P5_TERM_ID*:=a;
    end;
    Edited by: skud on Mar 5, 2011 2:05 AM

    You can submit the page with a request say "MY_REQUEST" and run a conditional PLSQL block(request equal to MY_REQUEST) and add the PLSQL code there.
    If you want to do it without submitting page
    <li>Apex Version 4 : Add an id to button (button attributes, id ="MY_BUTTON" ) and add a Dynamic Action fired on click of DOM element : MY_BUTTON , event type would be PLSQL and write your PLSQL code there(add required page items to be submitted in the field)
    <li>Apex 3.x and 2.x(works iwth apex 4 too), create an ondemand PLSQL process, call the process from a javascript function(add the item values to session using the ajax request handle) and call the javascript function from the button click( action type: redircet to URL , javascript:function_name(parameter1,parameter2) )

  • Suggest plsql code for form security during runtime

    Hi
    I made a project using forms 6I . I created 4 forms in all. I created a Menu item too like create,insert, delete,modify records, reports print etc. Now What I want is “ if user want to enter a particular form he should select appropriate menu item from the menu “ But what I my exact need is if user attempt to enter a form “a small popup dialogue box should be displayed in the middle of the screen and asks for a password” . So I want a pl&sql function or procedure which creates a default password and match the same when the user enterered the same in popup dialogue box and allow or reject the user request.” Please suggest me a full DETAILED PL/SQL CODE FOR THIS PURPOSE. OR ANY FORM 6I FEATURE.
    thanks in advance
    prasanth as.

    The dialog box is part of the ftandard Forms functionality. What you need to do is set up the user account with the password set to EXPIRED and no grace logins. The Admin Guide tells you how to do this.
    Cheers, APC

  • T-Code for reporting stock quantity difference between IM and WM

    Hi All
    I'm probably going to kick myself for asking this quastion but is there a report to show the stock quantity differences between IM and WM?
    I have searched the forum first but cannot find info.
    We have various differences in IM and WM shown in MD04 and LS26. This is usually the result of an unplanned plant to plant transfer not being recipted in at the destination plant.
    If no standard T-code is available, which tables can I join to create my own query?
    Thanks in advance
    Darren

    compare MMBE with LS26
    Make sure you dont enter a storage location and storage type in selection screen of LS26.
    if you post a difference with LI20, then you have just posted a difference within WM, means you moved a quantity from a bin into the difference storate type 998.  The balance of both is still equal to your stock shown in MMBE. You have to clear the difference with IM by executing LI21 transaction. Only then the quantity will disappear from difference storage type and will be adjusted in MM and FI.
    LX23 will only report real inconstencies and will adjust them.
    If you do a MM movement like 303, then this creates a transfer request in WM, this TR needs to be converted into a TO. to move the stock from the bin to the interim storage type for goods issue.
    In your case you created just a negative quant in the interim storage type for goods issue and still have a positive quant in the bin, the balance is equal to the stock shown in MMBE.

  • How to register a custom plsql code

    Hi
    i have wrritten a custom plsql code for my Overtime entries validation for payroll processing.
    Can any body tell me how to register it in application.
    Secondly i want to get the output file generated by report submission on my desktop.i want to know where the report output files for HR and payroll are stored so that i can get them through FTP.
    Regards

    if you want to integrate your plsql into a fast formula, please download the fast formula guide from metalink. Or ask your functional payroll consultant.
    All reports and processes in Oracle Apps are handled via concurrent programs and requests. When a concurrent request is finished, click on the output button, and depending from the filetype, your browser will take action.
    All concurrent output is also stored on the concurrent server. Ask your apps dba where she mapped the concurrent output directory. But i do not see why you should need this.

  • To automate the SQL scripts using PLSQL Code

    Hi All,
    I have 20 database server (11.2.0.3) hosted on  unix and Windows platforms.
    Every day I have to kill inactive sessions from all the these 20 database servers. So I have made a below script::
    connect sys/&&sys_password@&&tns_database_name as sysdba
    SPOOL E:\DELETE_INACTIVE_SESSIONS.SQL
    set PAGESIZE 1000
    set LIN 5000
    SET ECHO OFF;
    SET FEEDBACK OFF;
    SET HEADING OFF;
    select 'alter system kill session '||'`'||SID||','||SERIAL#||'`'||' immediate;'  from v$session where status='INACTIVE' and username in ('OSS_DICTIONARY','ADMINISTRATOR');
    SPOOL OFF;
    @@E:\DELETE_INACTIVE_SESSIONS.SQL
    Is there any way so that this execution of script can be automated in PLSQL code for 20 servers so and that code could be put in batch file for execution(i.e. can be execute through batch file from my windows laptop).
    Thanks

    Shrma wrote:
    Is there no way to handle the sql scripts in PLSQL code?
    Well, remember that PL/SQL is executed on a specific server by a certain user so you are already connected when executing a PL/SQL code.
    You could actually use a SQL Plus script to connect to different servers using connect and run your script.
    i.e.:
    SQL> connect sys/pwd_server1@db_server1
    SQL> @killinactive.sql
    SQL> connect sys/pwd_server2@db_server2
    SQL> @killinactive.sql
    But it does not make so much difference with my previous solution.
    Please explain exactly what you would like to do.
    Regards.
    Al

  • Sample Bapi code for creating orders

    HI all,
    ive been working on creating an order using idoc_input_orders and couldnt do it because of 2 fields. now changed my decission and thinking of writing a bapi to do the same. has anybody got the sample code for mapping and filling in the bapis before calling bapi for creating an order. Could somebody help me with a sample code and i could use it as a reference before starting coding.
    thanks,
    Kiran

    See if this helps.
            one order with total sum of effort
              clear:   l_order_header,
                       l_salesdocument,
                       l_order_partners,
                       l_order_items,
                       l_order_schdl.
              refresh: it_order_items,
                       it_order_partners,
                       it_order_schdl,
                       it_return.
    ???????? get from material ...
            Order header
              l_order_header-doc_type          = 'ZQBV'.
              l_order_header-distr_chan        = '10'.
              l_order_header-division          = '00'.
              if g_qals-werk eq '1100'.
                l_order_header-sales_org         = '1000'.
              else.
                if g_qals-werk eq '3100'.
                  l_order_header-sales_org         = '3000'.
                else.
                  message i001(00) with text-005.
                endif.
              endif.
              l_order_header-purch_no_c        = g_qals-prueflos.  " <= lot
            Partner data
              l_order_partners-partn_role      = 'AG'.
              l_order_partners-partn_numb      = g_qals-kunnr.
              append l_order_partners to it_order_partners.
            Order items => only one
              l_order_items-itm_number         = 10.
              l_order_items-material           = g_qals-matnr.
              l_order_items-target_qty         = 1.
              append l_order_items to it_order_items.
            Schedules for quantity
              l_order_schdl-itm_number         = 10.
              l_order_schdl-req_qty            = 1.        " <=  only 1 !
              append l_order_schdl to it_order_schdl.
            Conditions for value
              l_order_conditions-itm_number    = 10.
              l_order_conditions-cond_type     = 'PR00'.
              l_order_conditions-cond_value    = g_effort_sum.
              l_order_conditions-currency      = g_effort_unit.
              append l_order_conditions to it_order_conditions.
            BAPI to create sales order
              CALL FUNCTION 'BAPI_SALESORDER_CREATEFROMDAT2'
                EXPORTING
               SALESDOCUMENTIN               =
                  ORDER_HEADER_IN               = l_order_header
               ORDER_HEADER_INX              =
               SENDER                        =
               BINARY_RELATIONSHIPTYPE       =
               INT_NUMBER_ASSIGNMENT         =
               BEHAVE_WHEN_ERROR             =
               LOGIC_SWITCH                  =
               TESTRUN                       =
               CONVERT                       = ' '
                IMPORTING
                  SALESDOCUMENT                 = l_salesdocument
                TABLES
                  RETURN                        = it_return
                  ORDER_ITEMS_IN                = it_order_items
               ORDER_ITEMS_INX               =
                  ORDER_PARTNERS                = it_order_partners
                  ORDER_SCHEDULES_IN            = it_order_schdl
               ORDER_SCHEDULES_INX           =
                  ORDER_CONDITIONS_IN           = it_order_conditions
               ORDER_CONDITIONS_INX          =
               ORDER_CFGS_REF                =
               ORDER_CFGS_INST               =
               ORDER_CFGS_PART_OF            =
               ORDER_CFGS_VALUE              =
               ORDER_CFGS_BLOB               =
               ORDER_CFGS_VK                 =
               ORDER_CFGS_REFINST            =
               ORDER_CCARD                   =
               ORDER_TEXT                    =
               ORDER_KEYS                    =
               EXTENSIONIN                   =
               PARTNERADDRESSES              =
              if not l_salesdocument is initial.
              order successfully created
                message i001(00) with text-001 l_salesdocument.
              endif.
            endif.

  • Please provide the abap code for this requirement

    note : if the below mentioned user exit is not suitable please find the suitable user exit and provide the code for this requirement.
    •     The User-exit MEFLD004 is only to be used at PO level (ME21N/ME22N).
    •     When PO is create or changed (ekko-ebeln) user exit MEFLD004 is triggered which check for the business requirement of the PO check for PO doc types (ekko-bsart) :z4,z6,z11,z12 from the table ekko and Account Assignment Category (knttp) is either N or K then stock process follows.  
    •     When an PO is cancelled, all entries will have to be reversed
    •     The Buffer table for the PO will have the following fields:
    Purchase order Number                     EKKO-EBELN
    Line item number of the PO               EKPO-EBELP
    Vendor Number                                  EKKO-LIFNR
    PO Quantity                                        EKPO-MENGE
    PO Nett Price                                     EKPO-NETPR
    Base Unit of Measure                  EKPO-LMEIN
    Account Assignment Category          EKPO-KNTTP
    PO Doc type                       EKPO-BSART     
    Plant                            EKPO-WERKS     
    Purchase Org                                  EKKO-EKORG
    Purchase Group                    EKKO-EKGRP     
    Company code                                EKPO-WAERS
    Item category                     EKPO-PSTYP
    PO Doc Date                      EKKO-BEDAT
    •     No duplications are allowed for any created, changed or cancelled purchase orders. If such a case occurs, the record will be updated with the latest update time stamp. This custom table will be keyed by purchase order number.

    Cross-post: http://forum.java.sun.com/thread.jspa?threadID=763485

  • How to disable a custom designed Tx code for multiple user at a time

    Hii ,
    I have designed a screen in module pool for end user to make entries in the screen and when he saves the data is saving in standard table and ztable. the main field in the screen is Batch number..from that batch  number bag number will be generated. and consumed quantity will be saved in that bag no.Bag number will be generated like first 5 digits of batch number and bag number series of that batch number. for example if batch number is 12345 and already 5 times packing is done for same batch..last bag number in the ztable will be 123450005.so next time when user tries to pack using same batch number the new bag number will be 123450006 for batch 12345.Problem here is when user tries to make enrties in that Tx code and at the same time if another user opens same Tx code to make packing for same batch both of them are getting same bag numbers before saving.
    I have called Enqueue and Dequeue FM's but still at a time for same batch user is able to do the packing.now my issue is i want to restrict 2 user to use same batch while packing in that Tx code.
    I have written following code for enqueue and dequeue technics
    data: B_matnr type mara-matnr,
           B_charg type mchb-charg.
    data : i_temp type TABLE OF zpackhdr WITH HEADER LINE,
           i_temp1 type TABLE OF zpackhdr WITH HEADER LINE.
    move : 1110 to WA_BCH-werks,
           chk_matnr1 to WA_BCH-matnr,
           v_bcharg to WA_BCH-charg,
           vgrade to WA_BCH-grade,
           new_batch to WA_BCH-bagno,
           m_baleno to WA_BCH-baleno,
           b_date to WA_BCH-indat.
    APPEND wa_bch to i_bch.
    clear b_date.
    READ TABLE i_bch INTO wa_bch INDEX 1.
        B_MATNR = WA_BCH-matnr.
        B_CHARG = WA_BCH-bagno.
    concatenate  B_matnr B_charg  into
        WA_BCH-objek respecting blanks .
       modify I_BCH from WA_BCH index sy-tabix.
    CLEAR: B_MATNR,
               B_CHARG.
    call function 'ENQUEUE_EMMCH1E'
    EXPORTING
       MODE_MCH1            = 'E'
       MANDT                = SY-MANDT
       MATNR                = WA_BCH-MATNR
       CHARG                = WA_BCH-BAGNO
    if sy-subrc <> 0.
    endif.
    call function 'DEQUEUE_EMMCH1E'
    EXPORTING
       MODE_MCH1       = 'E'
       MANDT           = SY-MANDT
       MATNR           = WA_BCH-MATNR
       CHARG           = WA_BCH-CHARG

    I do understand what u say...mine is a custom designed screen...when i open that screen i have around 15 input fields in which batch is obligatroy...when i give batch and hit enter all the other fields will be filled automatically picking from the table which are relevant for that batch..for example..material,order etc are picked from table...and bag number field will be generated taking first 5 digits of batch and followed by 0001 if its afirst time entry for that batch....so when a user is opening that screen in 2 different windows and giving details without saving any of the screens...in both screens bag number is generating as 001...and when saving it ..its saving 2 entries with same bag number...so i have created a lock entry for afpo table taking order field...so when a user opens 2 screens with same batch...and giving entries in those 2 screens without saving..he is getting same bag numbers as 001.....now when user saving the first screen and coming to second screen to save...he is gettimg message 'ORDER CURRENTLY BEING PROCESSED'..but after the data gettng saved in first screen,then when he saves the second screen it is getting saved...with same bag numbers as 001.so my issue is here...when he saves first screen and comes to second screen to save it the user should get that error message and should come out of the screen....so that he can make a fresh entry for that batch and bag number will be generated as 002 for that batch...
    Regards,
    venkat.

  • Tax Code for NR00 Free Goods

    Hello,
    I have configured discount-in-kind free goods using the standard NR00 condition type.  With the necessary configuration and condition records in place I am attempting to test my setup by creating a purchase order.
    The discount-in-kind calculation is working correctly, creating item 11 containing the free goods quantity (set up as exclusive).
    However, I am receiving the error:  In case of ERS, please enter Tax Code.  Due to our business process the user is not able to enter this manually, it must be automatically populated.
    We have a tax condition type on in our main calculation schema which is correctly determining the tax code for the item 10.  However, this is not getting copied down when item 11 is created, and since it is a free good, there is no condition tab which is used to determine the tax code.
    Am I missing something or is there additional set up to populate the tax code for the free good?  Our taxes are somewhat complex as we operate cross boarder (one material may be not taxable in one country, and taxed at different rates in another one).
    Thanks in advance,
    Matt

    Hi,
    ERS indicator is based on Vendor Master if you are creating PO for that vendor for all items it will ask for Tax code
    Since tax code is mandatory to for ERS to run in backgeorund
    Now if you are using one line item as free goods you need to create some dummay tax code with ZERO tax
    Hope its clear
    Thanks
    Diwakar

  • ORA-01403: no data found Error in PLSQL code raised during plug-in processing.

    Hello OTN community,
    We are having the access to APEX problem. a New user was setup to access the APEX application. When I test to login as a new user, I get the message "ORA-01403: no data found Error in PLSQL code raised during plug-in processing.". When click OK to the disply message, the application will take me out of the sstem. I need help to even understand what is happening. I didn't develop the application, there is no documentation for this application, I am just supporting the application whenever there is a problem and I am new to APEX. As you can see I need help to figure this thing out. Your help is dearly appreciated.
    Thank you OTN

    Try to check the query that is executed and check if there is data or not

  • How to write a file in unix server through oracle plsql code

    Hi All,
    My requirement is to create and write a file (any file for eg txt file) in unix box with in a specified directory through oracle plsql code.
    Oracle sits in windows server.
    using utl_file package we can create directory where oracle resides and write it there in oracle server in our case windows..
    But here we need to create,write a file but in unix server which is different server than where the oracle server resides..
    we are using Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - 64bit Production
    PL/SQL Release 11.2.0.2.0 - Production
    Can any one one please help me out in this issue...
    Thanks in Advance.
    Prakash

    Mr Prakash,
    Why are you asking this question multiple times in every forum you can spell?
    Valid responses have been presented to you already two times.
    Can you explain why you can't follow them up, but continue to abuse this forum by repeating doc questions?
    Sybrand Bakker
    Senior Oracle DBA

  • Displaying Images in a Report or in PLSQL Code

    Hi all,
    I have a products catelog in an items table (item_id, item_name, item_image (blob)). I want to display it in a table form but Reports in Portal30 do not allow images.
    I can write simple PLSQL code to display table contents in tabular form (using htp, htp packages) but I could not find any procedure/function to display image stored in a db table to an HTML table.
    I shall be grateful for any help or hint regarding this. You can mail me directly if you like.

    Armaghan
    This question is best asked in the Oracle9iAS Portal Applications Forum.

Maybe you are looking for

  • Link between table SOFFPHF and FI document

    Hello Experts, I have a requirement to find all the FI documents with the attachement . We have a table SOFFPHF (SOFF: Files of Physical Information Objects) where i can get the details of attachement, But now how to link this table with the FI docum

  • Basic query on PLSQL using TOAD

    hi all, First of all thanks a lot to everyone for always helping and guiding me through all the doubts i had asked here.I have leasrned a lot and appreciate your help. So,my question is executing the STORED PROCEDURE in Toad 9.0 execute assign_daily_

  • How to count no of rows affected by a ref cursor ?

    Hi, I have taken a ref cursor inside the function since I want to return resultset to the calling application. I also need the NO. OF ROWS AFFECTED by the ref cursor. When I used refcur%rowcount, it returned me 0. Whereas actual no. of rows inside th

  • Bluetooth Might Mouse Problems

    Sorry if this is the wrong forum, but: My bluetooth might mouse stops working after about 5 minutes of use. The arrow moves, but it's impossible to click on anything. Sometimes the arrow grabs a window, and it's impossible to let go of it. If I turn

  • My home page always reverts to a city in which I do not live,

    I live in Oregon and whenever my msn home page loads, it shows Vancouver, WA and will not change permanently. Very annoying.