Inventory count entry by Batch-Input Method with Transaction MI34, MI38, MI39, MI40
Inventory count entry by Batch-Input Method with Transaction MI34, MI38, MI39, MI40
Before you start using Batch-Input method for inventory count entry you should be familiar with the usual transactions for manual entry of physical inventory counts and posting.
Test the manual transactions, note down the entries, as you need to provide the same info in a batch-input.
Use F1 field help, followed by click on technical field help to obtain the table names.
SAP provides batch-input transactions that reference an existing physical inventory document as well as transactions to count without reference.
MI34 Physical Inventory Count with Reference to the Document – manual transaction MI04
MI38 Enter Count with Reference to Document, Post Differences – manual transaction MI08
MI39 Enter Count Without Reference to Document – manual transaction MI09
MI40 Enter Count Without Reference to Document, Post Differences – manual transaction MI10
If you want to use MI34 or MI38, then you have to create the physical inventory document with MI31 first. It can as well be created with MI01, but using MI01 does not make much sense if you are going to automate things, as it is a pure manual creation and probably needs factor 10 time than entering a count using the manual MI04 transaction.
The selection screen of all 4 Batch-input transactions looks equal. Only the defaulted Name of Logical file is different. It is MMIM_PHYSICAL_INVENTORY_DOCUMENTS for MI34 and MI38; MMIM_PHYSICAL_INVENTORY_NO_DOCUMENTS for MI39 and MI40
To setup the batch input method you should read the documentation behind the blue i Icon on top of the selection screen. (and this blog now)
As the Logical file name is already defined by SAP we do not really need to bother about setting one up for ourselves, we can just use the given one, it worked right away in all systems I have tested these transactions in preparation for this blog.
With customizing transaction FILE you can view how it is defined.
Double click the folder Logical File Name Definition on the left, find the file name (that can be seen in e.g. MI34) then go into the detail.
Alternative you can use SM30 with view V_FILENAME to get the same info.
Here you see that SAP expects a physical file called phyinv34_38 for the MI34 and MI38 transaction
(for MI39 and MI40 transaction the file name is phyinv39_40)
And it expects it to be in directory: /usr/sap/trans/data (this is in Unix file system)
Further you can see that this file is expected in ASCII data format.
Now we know that we have to transfer an Text file called phyinv39_40 into directory /usr/sap/trans/data
Let us continue with the content of this file.
SAP explains in the documentation that you can create a test file, this should help you to know what is needed.
Start with MB52 to list the stock of one location in your plant. Then create a physical inventory document with just one or two materials using Mi31 or Mi01.
So you know the plant, location, material number, batch number, unit of measure, quantity, stock type, the inventory document number, the inventory date and the count date.
SAP help explains that you need to maintain table T159i to create a batch input with test data.
You do this in SE16. Enter table name T159i, then click the create icon. Do this in your Development System, you probably do not have the authority for table maintenance with SE16 in production system.
You will then get this table screen and, and according to the SAP help you have to enter the report ID RM07II34 and the transaction code MI04 to create test data for MI34 transaction (RM07II39 with MI09 to create test data for MI39 transaction. Please obtain the relevant report ID for the transaction from SAP documentation in the selection screen)
The other fields have to be maintained with the data from your physical inventory document, off course with the actual count and not with the book inventory from MB52 list.
Remember, to create a zero count, it is not sufficient to enter 0 in ERFMG field; you have to set the indicator for zero count in field XNULL too.
Now you can proceed in MI34 transaction.
You activate the box in front of test data and execute.
SAP issues a warning message: Sequential file /usr/sap/trans/data/phyinv34_38
overwritten with test data
Please double click the message and read its long text.
This is a warning only, it tells you that this listed file will be overwritten. Just think about what content this file has. If it has just test data from a test made by yourself then there is no harm to continue with Enter and have SAP overwrite the content of this file. But it could have productive data. Could it really? Probably not in a development system., but it could be test data from a colleague of you.
If you want to check what content it has, then execute AL11 transaction. Browse through the directory to /usr/sap/trans/data/ and then double click the file phyinv34_38
You will then get a file similar to that one (this is from MI39)
If you get a message like Sequential file & cannot be opened, then it can be a authorization issue, it could as well be that you have the wrong report ID maintained in T159i table. Or you do not even have any record in T159I
After you had successfully written data do the file using the test data flag SAP gives you the following screen with information from the Batch Input session that was created. And you can process this session now from here clicking Process session, or you go into SM35 to process the batch input session.
But before we actually execute the batch input session we should verify if it has the data in the right fields. This is less important for correct maintained test data from T159i table than later when you try with your own external data.
When you are in SM35, then find your batch input session in the NEW tab using either your user ID or the session name which was listed in the screen shot before (based on your entry made in T159i)
Select the session, then click the analysis button. Now go to the tab Screens and click the button Display Field list. Now check if the content is at the right fields. This is as well a screen shot for MI39 transaction, but for MI34 you will see almost the same. The main purpose is to check if the content is in the right fields.
If you are satisfied with the content, then you can execute the batch-input session.
SAP recommends doing it in Error mode. I personally prefer to do it in foreground in the first test.
Until here it was basically the technic how to execute the batch input with test data from table T159i. But more important is a test with own external data.
Table T159i could already give you an idea how the data has to be. SAP says in the documentation that your file shall be based on table structure BISEG.
Execute SE80, select Repository Information System, drill down Objects > Abap Objects > Fields > Structure fields. Then enter BISEG as Structure name and click execute. SAP will give you a list with the field names, from there you can as well go into the details and see the field definitions.
Alternative, just use SE11, enter BISEG as table and click display.
This structure has all possible fields that could be needed in physical inventory process. Many of them are used for special stocks inventory. If you are familiar with all inventory types and with manual execution, then you should not be worried about those fields.
But very important is to know how to prepare this file.
This batch input process is in general used when the physical inventory is done in a legacy system.
So you create this file with a program in your legacy system.
Excel is not a legacy system.
You must not have field names in the beginning of the file, there is no option to omit this info in the transactions.
SAP expects the data in a sequential flat file respecting the field length of the BISEG structure.
As the BISEG structure is like a mask that is put over your data in this file and then the program uses character 1 to 12 and moves the content to the field MAPPE (session), then it takes character 13 to 32 and moves the content to the field TCODE (transaction) and so on.
Excel has columns, but it does not respect the field length.
If you save Excel as text file, then you have tabs as delimiter, but all content is just concatenated
See this example:
Content coming from Excel saved as Text file:
If the program then moves the characters 1 to 12 to the session name field, then it will have MY_MI39#MI09 as content, and the transaction code field would have ####1300#0001#MS
This is just garbage from plant number, storage location and material number, and cannot be loaded.
How to get this external file into your SAP directory?
You can use the standard transaction CG3Z for this purpose.
It gives you option to search for your source file in your local PC via F4 .
And the target directory and file name needs to be entered manually.
Remember that you need ASC as format and activate the check box to Overwrite an existing file.
Here you will not get any warning like it is in the MI34 transaction.
After the file is loaded you receive a success message
Then you continue in the batch input transaction. Now you must not enter the Test flag.
SAP will then read the data from your loaded file and create a batch input session.
Which you finally process in SM35 (or directly from the transaction, if possible)
The Transaction without document references have a field for number of items. It is defaulted with 20, which means that SAP only takes 20 records into one inventory document, then another inventory document is created until all your items are processed. This field must not have a value bigger than 333.
You cannot have more than 333 inventory items in one inventory document. There is no difference in mass processing with batch input method compered to the manual transactions.
Please read SAP Note 1655631 – MI31 / MI34 Maximum number of line items per Physical Inventory Document