Stored procedure in purchase order for duplicate item for a vendor

Hi all
I have written a stored procedure for duplicate item for vendor the output i need from this SP is whenever for a vendor we will raise purchase order the system should check that their shouldn't be any po in the system for the same item by the selected vendor. Its working fine when only one item is selected but it is behaving wrongly when more than one item is selected.
If (@object_type='22' and @transaction_type='A')
BEGIN
Declare @Vend as varchar(200)
Declare @ItemCode as varchar(200)
Select @Vend =CardCode From OPOR Where DocEntry = @list_of_cols_val_tab_del
Select @ItemCode=ItemCode From POR1 Where DocEntry=@list_of_cols_val_tab_del
IF 1 !=(Select Count(T0.DocEntry) From OPOR T0  Inner Join POR1 T1 On T0.DocEntry=T1.DocEntry  Where T0.CardCode=@Vend and T1.ItemCode=@ItemCode)
Begin
select @error =1
select @error_message = 'Item Code Already Exists For This Vendor'
end
end
Thanks
Rashid.

Hi Rashid,
Try this,
if @object_type = N'22' and @transaction_type in (N'A', N'U')
begin
declare @line1 int
declare @lin1 int
declare @out1 int
Set @out1 = 0
SET @lin1 = 0
Declare @Vend as varchar(200)
Declare @ItemCode as varchar(200)
Select @Vend = CardCode From OPOR Where DocEntry = @list_of_cols_val_tab_del
Select @line1 = Max (LineNum)FROM POR1 WHERE POR1.DocEntry = @list_of_cols_val_tab_del
While @lin1 < @line1
Begin
     Select @ItemCode=ItemCode From POR1 Where DocEntry=@list_of_cols_val_tab_del and LineNum = @lin1
      if (SELECT COUNT(T0.DocEntry) FROM POR1 T0 inner join OPOR T1 on T0.DocEntry = T1.DocEntry
      WHERE T0.ItemCode = @ItemCode and T1.CardCode = @Vend)> 1
      Begin
           Set @Out1 = 1
           Break;
      END
           Else
           Begin
           Set @lin1 = @lin1+1
           Continue
      END
END
Set @lin1 = @lin1 + 1
if @out1 = 1
begin
      Set @error = 1
      Set @error_message = 'Item Code in line ' + CONVERT(nvarchar(4), @lin1) + N'already Exists For This Vendor!'
End
END
Regards,
Bala

Similar Messages

  • Stored procedure at Purchase order..

    hi.
    i need a stored procedure at purchase order..
    what i need is purchase quotation , posting date should be equal to purchase order posting date other wise..
    error will show...
    the below one i tried but it's not working..
    --IF (@object_type = '22' )and (@transaction_type IN ('A','U'))
    --BEGIN
    --If exists(SELECT T3.[Docentry]  FROM POR1 T0 left join OPQT T1 on  T0.[BaseDocNum]  =  T1.[DocNum]
    -- INNER JOIN PQT1 T2 ON T1.DocEntry = T2.DocEntry INNER JOIN OPOR T3 ON T0.DocEntry = T3.DocEntry WHERE DATEDIFF(DD,T3.DocDate,T1.DocDate ) <> 0   and T3.DocEntry =
    --@list_of_cols_val_tab_del )
    --  Begin
    --  set @error =105
    --  set @error_message = 'Please Check the Date'
    --  End
    --  end

    Try:
    IF (@object_type = '22' )and (@transaction_type IN ('A','U'))
    BEGIN
    If exists(SELECT T3.[Docentry]  FROM POR1 T0 left join OPQT T1 on  T0.[BaseEntry]  =  T1.[DocEntry]
    INNER JOIN PQT1 T2 ON T1.DocEntry = T2.DocEntry
    INNER JOIN OPOR T3 ON T0.DocEntry = T3.DocEntry
    WHERE T3.DocEntry = @list_of_cols_val_tab_del and DateDiff(dd,T3.DocDate,T1.DocDate) != 0)
      Begin
      set @error =22
      set @error_message = 'PO date must be the same as Quote date'
    End
    END
    Thanks,
    Gordon

  • Table for open Purchase order and pending invoices for vendors

    Hi,
    Are there any table to know open Purchase orders and pending invoices for vendors.
    Quick response will be appreciated.
    Thanks & Regards

    hi,
    Purchase Order:
    S011:(PURCH: Purch. Group Statistics)
    Statistics (SSOUR)
    Version (VRSIO)
    Month (SPMON)
    Day (SPTAG)
    Week (SPWOC)
    Posting Period (SPBUP)
    Purchasing Org (EKORG)
    Purchasing Group (EKGRP)
    Vendor No (LIFNR)
    S012: (PURCHIS: Purchasing Statistics)
    Statistics (SSOUR)
    Version (VRSIO)
    Month (SPMON)
    Day (SPTAG)
    Week (SPWOC)
    Posting Period (SPBUP)
    Purchasing Org (EKORG)
    Purchasing Group (EKGRP)
    Material No (MATNR)
    Plant (WERKS)
    Info Record Category (ESOKZ)
    Material Group (MATKL)
    Info Record (INFNR)
    Country (LAND1)
    EINE: (Purchasing Info Record: Purchasing
    Organization Data)
    Info Record (INFNR)
    Purchasing Org (EKORG)
    Info Record Type (ESOKZ)
    Plant (WEKS)
    EKET: (Delivery Schedules)
    Purchasing Doc (EBELN)
    Item (EBELP)
    Delivery Schedule (ETENR)
    EKPO: (Purchasing Document Item)
    Purchasing Doc (EBELN)
    Item (EBELP)
    EKKN: (Account Assignment in Purchasing
    Document)
    Purchasing Doc (EBELN)
    Item (EBELP)
    Account Assignment (ZEKKN)
    EKKO: (Purchasing Document Header)
    Purchasing Doc (EBELN)
    EORD: (Purchasing Source List)
    Material No (MATNR)
    Plant (WERKS)
    Source List No (ZEORD)
    thx,
    Ganpat

  • Creating a purchase order in web dynpro for java.........

    hello all,
    i am new to web dynpro for java.i have already done an application
    "Creating a Web Dynpro Application Accessing ABAP Functions" this application
    have good document on sdn.
    this application is working fine .
    Now i got an requiremnt for creating a purchase order in web dynpro for java.
    in normal report when i call  the bapi the parameter are the header, headerx,item, itemx is an internal table.
    CALL FUNCTION 'BAPI_PO_CREATE1'
      EXPORTING
        POHEADER                     = HEADER
        POHEADERX                    = HEADERX
      POADDRVENDOR                 =
      TESTRUN                      =
    IMPORTING
      EXPPURCHASEORDER             =
      EXPHEADER                    =
      EXPPOEXPIMPHEADER            =
    TABLES
       RETURN                       = RETURN
       POITEM                       = ITEM
       POITEMX                      = ITEMX.
    i just want to know how can i fill these internal table in web dynpro
    for java to create an application accessing "Bapi_po_create" .
    Thanks

    Hi Gopal,
    I'm not sure what is your issue, it seems you're not really understanding how the Model structure works in WDP.
    I'll assume few things here, like you know how to Import the Model into the WDP, and you know a little bit about what Java Classes will represent this Model in the Project.
    Try these steps:
    1. Import your Model into the Project;
    2. Open your Component Modeler, create a Data Link between your Model / Component (Or Custom Controller, as you prefer)
      - You can also use the "Apply Template -> Service Controler"
    3. Map the Input of your Model as the Main Node, check the Input Tables (you prob. will have two, POITEM = ITEM - POITEMX = ITEMX)
    4. Also, check the Return box, since this is BAPI return (You can use to display Backend messages)
    Now you have the Model mapped into your Controller, you need to develop the Java function to execute it.
    1. Create a new Input class, like
    BAPI_PO_CREATE1_Input purchaseOrderCreateInput = new BAPI_PO_CREATE1_Input();
    2. Bind your Input Node, in the Controller, with your Input Class;
    wdContext.nodeBAPI_PO_CREATE1().bind(purchaseOrderCreateInput);
    3. Set any Import parameters you need:
    purchaseOrderCreateInput.setEXPPURCHASEORDER(XXXX);
    4. To Add references to the Table, you will perform something like:
    First, you need to know what "Structure" you need to add (POItem Structure) - You have a Java class that represents that Structure..
    POITEM_Element poItemElement = new POITEM_Element();
    poItemElement.setPROPERTY();   /// Set your Properties
    purchaseOrderCreateInput.getPOITEM().add(poItemElement);
    5. Execute your Input,
    purchaseOrderCreateInput .execute();
    Hope it helps,
    Regards,
    Daniel

  • Unable to cancel - open purchase order where all items are removed

    Hi all,
    When We try to cancel/close open purchase order where all items are removed from item master ?
    It showing error message,
    "No matching records found  'Items' (OITM) "
    Purcahse order was created on may-2007.
    As purchase order showing in open item list.
    Any solution for this problem ?
    Jeyakanthan

    SAP does allow items to be removed from the item master with open documents, but only if the documents have not created journals.
    It does create headaches though, and this situation is one of them.
    If there are not many items, I suggest you recreate the items, close the PO and just cancel the items rather than remove them.
    The other workaround is to change the items on the PO to something different that is in the item master, then close it.

  • How to link asset with purchase order and PO Item.

    Hello,
           I have to generate a report which contains columns
    Asset No , po no(ebeln) ,PO Item(ebelp),Material no etc
    My query is how to link asset with purchase order and      PO Item.
    I am selecting asset and po no. from anla  but how to get
    po item no(ebelp)?
    po line item is important in this report because every line item has differrent asset and material no.
    i tried to match asset no in mseg table but i am not getting asset no in mseg .
    how should i proceed ?

    Thanks Thomas & Srimanta for the quick response.
    When I checked EKKN table by entering PO there is no asset no. in anln1 field.
    Also I would like to add that, In me23n for a PO, account assignment category we are entering 'F' for internal order settlement.
    Where can i find the link between asset and po no(ebeln) and po item(ebelp)?
    Regards,
    Rachel
    Edited by: Rachel on Aug 11, 2008 7:23 AM

  • Delivery date in Purchase Order in the item overview

    Hi all,
    In which table is Delivery date in Purchase Order in the item overview stored.
    the screen field name is eeind.
    Thanks

    In table EKET in field EINDT the delivery date is stored, based on the Schedule lines in the PO Item

  • Purchase order has no items

    Hi All,
    While i am posting the MIGO transaction with reference to PO I encountered error as a "Purchase order has no items.
    Thanks and regards,
    Ravi Vruddhula.

    Following are the reason
    Check the confirmation tab ate item level at the purchase order. It should be blank.
    Is there any goods receipt ag. this PO, if yes, check the PO history tab at item livel in the PO. Check the pending qty.
    It sholud not be deleted PO.
    Check the delivery date in the PUrchase order.
    Check the release stratagy in the PO. It should be release.
    Thanks,
    Samir Bhatt

  • PO account assignment Q + Purchase order has no items + M7033

    Hi All,
    I have create a PO with account assignment Q and now when I am trying to post GR to this PO I am getting the error 'Purchase Order has no items' Message number M7033. Please Guide.
    Thanks and Regards
    Pavan

    Following are the reason
    Check the confirmation tab ate item level at the purchase order. It should be blank.
    Is there any goods receipt ag. this PO, if yes, check the PO history tab at item livel in the PO. Check the pending qty.
    It sholud not be deleted PO.
    Check the delivery date in the PUrchase order.
    Check the release stratagy in the PO. It should be release.
    Thanks,
    Samir Bhatt

  • Last purchase order and goods receipt for material

    Hello to everyone,
    is there any standard report where I can see the last purchase order and goods receipt for a material?
    Regards

    Hi,
    Latest PO you can get from ME2M, by giving input as material and scope of list as best.
    Latest GR date can be get from MB51, by giving input as Material and movement type as 101.
    Regards,
    Prabu

  • No purchase order history was found for first purchase order

    Hi 
    We are doing the third party sales in system. User created the sales order and the process for the third party. Then he created the PO and due to some reason user has deleted the 1st PO and then created the PO for same material and sales order. Now user wants to create the billing document for the sales order no but system giving the message that u201CNo purchase order history was found for first purchase orderu201D and Message no. ZSD 006.
    Could you please suggest how to solve above issue?
    Thank you for your help.
    Regards
    Kishore Gulhane
    09324086205

    Hi Ashok
    Thank you for your reply ,
    But user has delete the first PO not the sales order. he is trying to create the billing document for same sales order no.
    Please suggest
    Thank you
    Kishore Gulhane

  • TS1702 i recently purchased an in-app item for my skylanders lost island game. I purchased that jewel pile worth Au$1.99, my account has already been debited but I did not receive the jewels.  Can anyone please tell me how I can get a refund or at least g

    i recently purchased an in-app item for my skylanders lost island game. I purchased that jewel pile worth Au$1.99, my account has already been debited but I did not receive the jewels.  Can anyone please tell me how I can get a refund or at least get what I actually purchased?

    iTunes Store Support
    http://www.apple.com/emea/support/itunes/contact.html

  • Get delivery number for PO items for complaint display report

    Hi All,
    I am working on Complaint Display report, While delivering the line items for a PO sometimes vendor may do mistake and then customer generates the complaint display report to let the vendor know the delivery mistakes. Delivery mistake can be done because of the following:
    1. Charging amount more than was it was mentioned on PO
    2. Not delivering complete quantities and etc.
    Now I want to get the delivery items for each goods receipt item.
    Information that I have is the invoice number and vendor number and the line item material number.
    Thanks,
    Mark

    You can refer to Purchase Order History Table ( EKBE) for this.You can pass the Purchase Order or Invoice number to the EKBE-EBELN and EKBE-BELNR fields respectively. set EKBE-VGABE = '2' ( i.e invoice receipts). EKBE-BEWTP = 'IR' or 'IR-L' ( Po history category).
    Hope it solves ur problem.

  • While creating Purchase order the system is showing error: vendor 200001145

    Hi experts,
    while creating Purchase order the system is showing error: vendor 200001145 on line 00010 for ctype ZB12 not defined as head office vendor.
    Plz  give solution for this.
    Thanks&Regards
    sreenivas

    Hi,
    Please check vendor schema maintained in the vendor master,. through this condition type arepicking from system
    Aboue condition type not mainatained inthe caluation schame ,which you assigend to vendorand purchasing organization
    regards
    Channa
    Edited by: channadodawad on Dec 3, 2009 9:22 AM

  • Interest calculation only for open item for customers

    Hi, do you know how to calculate Interest calculation only for open item for customers?I do not want to see cleared   items. I have problem with customization.
    Best Regards
    Tom

    In the item interest calculation, you can tick the  'open items' for calculation of interest and also select the 'no cleared items'.
    Regards

Maybe you are looking for

  • What is the best upgrade for the new Air?

    I am looking for a new Macbook Air for college and was wondering what upgrade would be the smartest decision. I was thinking of a 13" air with: 1.7GHz Dual-Core Intel Core i7, Turbo Boost up to 3.3GHz 8GB 1600MHz LPDDR3 SDRAM 128GB PCIe-based Flash S

  • I had to restore my computer and now it won't sync with my iPhone

    I had to restore my computer to default and now I can't transfer items in my iTunes library to my phone.  Is there anything besides 3rd party software that I can do to authorize this computer.  I restored my phone and I could transfer songs, but then

  • The type of the database table and work area are not Unicode convertible

    ***Data declaration TYPES : BEGIN OF t_zle_lagerplanung,                    SEl, "stores which row user has selected                    kdauf TYPE zle_lagerplanung-kdauf,                    kdpos TYPE zle_lagerplanung-kdpos,                    etenr

  • Portal Upgrade to SP18 CVersAccessException

    Hi all, I am trying to upgrade our portal from SP14 to SP18 and getting following error message: Caught CVersProxyAccessException while saving repository: CVersAccessException: Can not load mandatory table BC_COMPVERS, desc == null Some components we

  • [solved]terminus font without xorg.conf

    Hi I start X without a xorg.conf as every conf I tried did not work. Without the conf X works perfectly. But I now want the terminus font for my WM and pacman installed them in /usr/share/fonts/local This directory is not recognized by X by default.