cancel
Showing results for 
Search instead for 
Did you mean: 

SAP 9 PL09 Inventory Posting with batch numbers

ribessolutions
Explorer
0 Kudos
1,387

Good morning,
does someone has got some code about using InventoryPostingService with batch numbers?

In every manner I do that I've got always the same error (cause for sap b1 there's not sufficient quantity selected in batches).

Thank you in advance

Accepted Solutions (0)

Answers (10)

Answers (10)

edy_simon
Active Contributor
0 Kudos

Hi All,

After checking with my manager,

Turns out this is the correct design.
In the inventory posting screen, The batch selection is the batch that you don't have in your stock instead of the batch you have.
Example, Item A, in your inventory you still have Batch1 - Qty 1 and Batch2 Qty1.
When you do inventory posting, let's say counted quantity is 1 only and the correct physical batch in your WHS is Batch1.
Your batch selection criteria is Batch2-Qty 1 (The batch that you don't have and need to adjust)
If your counted qty is equal to your inventory qty, then you don't need to select the batch.

Regards
Edy

ribessolutions
Explorer
0 Kudos

Thank you so much Pedro,
I'm going to open a ticket to SAP (it's really the first for me about DI...).

I think it's very important to understand if this is a bug or something else.

I'll post here the result.

Bye.

pedro_magueija
Active Contributor
0 Kudos

Hi Alessandro,

Here is the code that fails for me:

var companyService = company.GetCompanyService();
var postingSrv = companyService.GetBusinessService(ServiceTypes.InventoryPostingsService) as InventoryPostingsService;

var posting = postingSrv.GetDataInterface(InventoryPostingsServiceDataInterfaces.ipsInventoryPosting) as InventoryPosting;

var line = posting.InventoryPostingLines.Add();
line.ItemCode = "B90123";
line.CountedQuantity = 1;
line.WarehouseCode = "01";

var batch = line.InventoryPostingBatchNumbers.Add();
batch.BatchNumber = "B90001";
batch.Quantity = 1;

var results = postingSrv.Add(posting);

Here is the same attempt in the client:

Note: if you use the Create button and create a new batch, it works.

Perhaps this is where we should read the documentation on Inventory Posting (from a functional perspective)?

Pedro Magueija

LinkedIn | Twitter | Blog

edy_simon
Active Contributor
0 Kudos

Hi Pedro,

Can I see your Inventory Posting screen above, I wonder why the total selected quantity is -1.
The create button should be used if your current inventory is less than the counted quantity.
But then again, the error message is pointing to line 2.

Regards
Edy

pedro_magueija
Active Contributor
0 Kudos

Hi Edy,

Yeah, I found that weird too, and even weirder is that if you create a batch rather than use an existing one, it works.

One more thing I didn't type -1, I actually typed 1 and then pressed '>'. That's when it becomes -1.

Do you have the same issue?

Pedro Magueija

LinkedIn | Twitter | Blog

ribessolutions
Explorer
0 Kudos

Hi Pedro,

only one (ehm...two) more things:

1) Can you post the complete proof of concept of the code you used to reproduce the issue?
2) You say that this is reproducible by client. If I'm not wrong in my test all works fine by client.

Thank you.

pedro_magueija
Active Contributor
0 Kudos

Hi Alessandro,

I've tried this as well and it fails (on 9.1 and 9.2). I'd say you're right and there is something wrong with the DI API.

You'll have to open a ticket with SAP.

Could you let us know what the reply from SAP is?

Note: this seems to be reproducible from the client.

Pedro Magueija

LinkedIn | Twitter | Blog

ribessolutions
Explorer
0 Kudos

Hi,

I get the document in XML format and there's no a blank batchnumber/quantity.

So I think it's not an error due to the position of the "Add()" method. I also checked the presence of an "item(0)" in the object, but it doesn't exist.

So at this point: is this a bug in DI???

ribessolutions
Explorer
0 Kudos

Thank you Pedro,

I know that thing but it seems in this case it's not so, but I'm going to try it, anyway.

I'll let you know asap if it is only a problem related to this.
pedro_magueija
Active Contributor
0 Kudos

Hi Alessandro,

Usually these "collections" such as batch/serial and even items, already have a row ready to use. When you invoke .Add() at the beginning without using this "default" row, you are effectively creating one more row, leaving the default empty.

Business One will then attempt to use the information there are throw some errors.

Move the .Add() to after setting the Batch information.

You're also assigning the quantity to the BatchNumber

mybatch.BatchNumber = Quantity;

Perhaps that's an error as well.

Pedro Magueija

LinkedIn | Twitter | Blog

ribessolutions
Explorer
0 Kudos
                        SAPbobsCOM.InventoryPostingLine Line = oDoc.InventoryPostingLines.Add();
                        Line.ItemCode = ItemCode;
                        Line.WarehouseCode = MagaDec;
                        Line.CountedQuantity = Quantity;
                        InventoryPostingBatchNumber mybatch = CurrentLine.InventoryPostingBatchNumbers.Add();
                        mybatch.BatchNumber = Quantity;
                        mybatch.Quantity = Math.Abs(UsedQty);

The "real" code is very complicated (because is inserted in a more big context), but the poc in the code is what I do. I think the question is: what's the quantity to put in the batchnumber? What about the sign?

It's also important to known that I made all controls about batch quantity and so on, but whichever way the problem remain the same.

pedro_magueija
Active Contributor
0 Kudos

Hi Alessandro,

Can you post the code you are using so we can check what might be the issue?

Pedro Magueija

LinkedIn | Twitter | Blog