Skip to Content
author's profile photo Former Member
Former Member

how to automatically assign a batch number

Hello experts,

Our customer have the "Manage Item by" settings on "Batches" and the "Management Method" settings on "On Release Only".

He don't want to manually generates the batch numbers in Delivery Entry because he would like to have an automatic assignment of batch number like a progressive number for year.

How can I achieve it using DI API ?

I have tried to create a Delivery Document using the BatchNumbers object but I got the following error message "the batch number you selected doesn't exists".

So I created a Goods Receipt for the batch number above and finally the delivery document has been created successfully.

The issue came out is about the stock quantity for the itemcode because the Goods Receipt have increased it and as result I have the same stock quantity as before the delivery and of course it's not correct !

I noticed that SAP B1 after the manually generation of batch number it creates a record on the OIBT table using an existing Good Receipt.

How can I add a batch number in the OIBT table using DI API without the need to create a Good Receipt ?

Can someone help me ?

It would be very appreciated.

Many thanks for your time in advance.

Best regards

Andrea

Add a comment
10|10000 characters needed characters exceeded

Related questions

3 Answers

  • Best Answer
    author's profile photo Former Member
    Former Member
    Posted on Dec 22, 2011 at 05:46 PM

    Hi Andrea,

    Unfortunately, this function is not supported yet through DI API. You may try UI API to simulate system function.

    Thanks,

    Gordon

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member

      Hi Gordon,

      So I'll going to say to my customer to set the "Management Method" option on "On Every Transaction" and so I'll automatically assign a batch number in Goods Receipt entry through DI API.

      According to this way in Delivery entry I have to press "Auto Select" button in "Batch Number Selection" window for every document row !

      Is there a way to simulate the "Auto Select" system function to bypass that window and assign for evey document row the correct batch numbers through DI API ?

      This would be very useful for the user because very often he have to manage many delivery rows.

      Thanks again for your quick reply.

      Best regards

      Andrea

  • author's profile photo Former Member
    Former Member
    Posted on Dec 24, 2011 at 07:02 AM

    Hi,

    Try this code, May be it will help you

    Dim v_StockEntry As SAPbobsCOM.Documents = oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oInventoryGenEntry)

    Dim v_StockExit As SAPbobsCOM.Documents = oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oInventoryGenExit)

    Dim str_ProEntryNo As String = oDBDSHeader.GetValue("DocNum", 0)

    'Dim str_DocDate As String = CDate(frmProductionEntry.Items.Item("t_DocDate").Specific.Value).ToString("yyyyMMdd")

    Dim str_DocDate As String = Date.Now

    Dim intStockRowCount As Integer = 0

    Dim FGCost As Double = 0

    Dim RMCost As Double = 0

    Dim RMQty As Double = CDbl(oDBDSHeader.GetValue("U_TotRW", 0))

    '--- RM Exist

    v_StockExit.Comments = "Stock Exit For Production Entry(RM) Production-Entry No: " & str_ProEntryNo

    v_StockExit.DocDueDate = str_DocDate

    v_StockExit.Reference2 = str_ProEntryNo

    intStockRowCount = 0

    For i As Integer = 1 To oMatrix1.VisualRowCount - 1

    intStockRowCount += 1

    If intStockRowCount > 1 Then v_StockExit.Lines.Add()

    v_StockExit.Lines.ItemCode = oMatrix1.GetCellSpecific("ItemCode", i).Value

    v_StockExit.Lines.Quantity = oMatrix1.GetCellSpecific("Qty", i).Value

    v_StockExit.Lines.WarehouseCode = oMatrix1.GetCellSpecific("WarCode", i).Value

    'v_StockExit.Lines.AccountCode = AccCode

    Dim qty = oMatrix1.GetCellSpecific("Qty", i).Value

    qty = IIf(qty.ToString.Trim = "", 0, qty)

    Dim cost = oMatrix1.GetCellSpecific("Cost", i).Value

    cost = IIf(cost.ToString.Trim = "", 0, cost)

    Dim PerQtycost = CDbl(cost) / CDbl(qty)

    v_StockExit.Lines.Price = PerQtycost 'GetItemPrice(oMatrix1.GetCellSpecific("ItemCode", i).Value)

    Dim ManBtchNum = getSingleValue("Select ManBtchNum from OITM Where ItemCode='" & oMatrix1.GetCellSpecific("ItemCode", i).Value & "'")

    If ManBtchNum.Trim <> "N" Then

    Dim rs As SAPbobsCOM.Recordset = GFun.DoQuery("select * from OBTQ where ItemCode ='" & _

    oMatrix1.GetCellSpecific("ItemCode", i).Value & _

    "' and WhsCode ='" & oMatrix1.GetCellSpecific("WarCode", i).Value & _

    "' And Quantity > 0 order by SysNumber")

    Dim count As Double = oMatrix1.GetCellSpecific("Qty", i).Value

    For k As Integer = 0 To rs.RecordCount - 1

    If CDbl(rs.Fields.Item("Quantity").Value) >= count Then

    Dim ss = rs.Fields.Item("SysNumber").Value

    v_StockExit.Lines.BatchNumbers.BatchNumber = _

    getSingleValue("select DistNumber from OBTN where ItemCode ='" & _

    oMatrix1.GetCellSpecific("ItemCode", i).Value & _

    "' and SysNumber ='" & rs.Fields.Item("SysNumber").Value & "'")

    v_StockExit.Lines.BatchNumbers.Quantity = count

    v_StockExit.Lines.BatchNumbers.Add()

    Exit For

    Else

    v_StockExit.Lines.BatchNumbers.BatchNumber = _

    getSingleValue("select DistNumber from OBTN where ItemCode ='" & _

    oMatrix1.GetCellSpecific("ItemCode", i).Value & _

    "' and SysNumber ='" & rs.Fields.Item("SysNumber").Value & "'")

    v_StockExit.Lines.BatchNumbers.Quantity = rs.Fields.Item("Quantity").Value

    v_StockExit.Lines.BatchNumbers.Add()

    count = count - CDbl(rs.Fields.Item("Quantity").Value)

    End If

    rs.MoveNext()

    Next

    End If

    Next

    If oMatrix1.VisualRowCount > 1 Then

    If v_StockExit.Add() <> 0 Then

    StatusBarWarningMsg("Unable To RM Post Stock Document....... " & oCompany.GetLastErrorDescription)

    Return False

    End If

    End If

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member Former Member

      Hi Andrea,

      did you ever get a way out with this? i also had the same request from my customer and need a way out. they suffer when having to autoselect the batch.

      i managed to ceated a UDF that shows the lists of batch number, and the user can select it, i wish now to be able to set the Batch table to select according to the batch number and qty i selcted in the invoice rows.

      Noella

  • Posted on Dec 31, 2013 at 05:13 AM

    Hello Andrea

    Try this code.

    //Code To get BatchNumber

    ldna_Rec=clsAddOn.LDNA_Company.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset);

    string GetBatch = "select DistNumber from OBTN where ItemCode ='" + YourItemCode+ "' ";

    ldna_Rec.DoQuery(GetBatch);

    String BatchNumber=ldna_Rec1.Fields.Item("DistNumber").Value;

    //Code To assign Batch Number

    SAPbobsCOM.Items oItemN;

    oItemN = clsAddOn.LDNA_Company.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oItems);

    oItemN.GetByKey(YourItemCode);

    if (oItemN.ManageBatchNumbers == SAPbobsCOM.BoYesNoEnum.tYES)

    {

    oStock.Lines.BinAllocations.SerialAndBatchNumbersBaseLine = 0;

    oStock.Lines.BatchNumbers.BatchNumber = BatchNumber;

    oStock.Lines.BatchNumbers.Quantity = Quantity;

    oStock.Lines.BatchNumbers.Add();

    }

    Regard's,

    Pritam

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.