Displaying Warning with MRP in the Planning of Products with BBD and Consideration by MRP

Expiry date products are an important issue especially for companies serving in the food industry.

 Displaying Warning with MRP in the Planning of Products with BBD and Consideration by MRP

Expiry-dated products are an important issue, especially for companies serving in the food industry. The production planning departments of the companies, on the other hand, want to know when the expiration date of the products with an expiration date, while doing their planning work. We have made an improvement to our customer, who has such a need, in the transaction code of the MD04 (Stock/Requirement List) transaction code, which will give this information when the date of the products with expiration dates expires, and MRP will take this negative record into account when planning. Below you will see the details of this development.

First we had to choose where to do this enhancement. Of course, this place is the "ADD_CHANGE_ELEMENTS" method in the "MD_ADD_ELEMENTS" badi that comes to mind first, since MRP elements (items such as planned order, need, etc.) can be intervened. As I just said, the reason why this body is deemed appropriate is that MRP elements on the relevant material can be easily seen and intervened during planning.

After choosing the right place, it remains to start the development. First of all, since the need for the expiry date development of the customer we are developing is for raw materials and packaging products, a condition was set for the MTART (Material Type) field in the im_mt61d structure in the method, including the raw material and packaging material types.

"IF im_mt61d-mtart EQ '1001' or im_mt61d-mtart EQ '1004'." If the relevant record complies with these conditions, it will enter the development section.

After entering this section, the records with the PLUMI field in the ch_copy_mdpsx table containing the MRP items (plant stock, planned order, need, etc.) for the material in waste, which will affect the stock in a – way (primary need, secondary need, etc.) is populated into an internal table. The reason for this is to be able to calculate whether the parties managed by the expiration date have any stock left after these “-“ records, that is, the needs, and if so, how much is left.

Afterwards, a comprehensive selection is made in which the MCHA, MCHB, MCH1 and MARC tables are joined in order to obtain the information of the parties of the relevant material. Joins are made as follows:

MCHA – MCHB

  • MATNR
  • CHARG
  • WERKS

MCHA – MARC

  • MATNR
  • WERKS

MCHA – MCH1

  • MATNR
  • CHARG

As a condition for Select, MATNR in MCHA is given MATNR in im_mt61d structure in body, WERKS in MCHA is WERKS in im_mt61d and LVORM field in MCHA is equal to empty (mcha~lvorm EQ ”).

The fields to be taken are the VFDAT (End use tr) and CHARG (Lot No) fields in the MCH1 table, and the CLABS (Unrestricted Stock) and CINSM (Quality Stock) fields in the MCHB table in order to take the stocks of the lots are added to a single field of the related table (lt_data). The reason for collecting and writing unrestricted and quality stocks is that the customer's demand is that both stocks become unusable if the expiration date has passed, regardless of whether the stock is unrestricted or of quality. The important point here is that the VFDAT (Expiry Date) information of the relevant parties should be entered while making the goods receipt. Otherwise, the date of 31.12.8999 will be defined as the expiry date for the lots whose VFDAT field is 0.

In this development, an internal table has been defined that contains the necessary fields so that expiration date calculations can be made with a table logic after all data has been pulled, and after the necessary data is pulled from the database, it will be made over this table. The fields of this table are as follows: VFDAT, CHARG, CLABS, REQUIRED_AMOUNT, REQUIRED_REST, STOCK_REST, USED, RECORD. The data expressed by these fields are as follows:

VFDAT: Expiration Date

CHARG: Lot No.

CLABS: Unrestricted Stock + Quality Stock value drawn from the table

REQUIRED_AMOUNT: MNG01 value of records with “-“ PLUMI field from ch_copy_mdpsx table

REQUIRED_REST: If greater, the amount remaining after subtracting CLABS from REQUIRED_AMOUNT

STOCK_REST: If CLABS value is larger, remaining amount after subtracting REQUIRED_AMOUNT value from CLABS value

USED: The value subtracted from the CLABS value. It indicates the used amount of lot stock.

RECORD: If lot stock is left, “-” record represents the record to be discarded at the expiry date. It can take the values of "X" or " ".

The data taken from the select, from which the lot information is drawn, is placed in the relevant fields of this table.

Afterwards, records with empty inventory fields are deleted from the table where the data is discarded. Then, as mentioned above, for records with an empty VFDAT field, the value of this field is defined as 31.12.8999. Of course, this value is given in the code as 89991231. With this operation, the expiration date field of all records in the table has been filled. Once filled, all records are sorted according to the VFDAT field from smallest to largest.

Then a loop is entered inside the internal table (lt_data) with the parties. In this loop, a loop is entered in the internal table (lt_mdps) where the records with the PLUMI field in the ch_copy_mdpsx table are filled with “-“ at first. There was a condition in the loop for the lt_mdps table: The "dat00" field in lt_mdps is entered for records less than VFDAT in the corresponding record of lt_data and for records whose check field is not "X". Here is the code view for better understanding:

       LOOP AT lt_data ASSIGNING .          LOOP AT lt_mdps ASSIGNING FIELD-SYMBOL()           WHERE dat00 LE -vfdat             AND check NE 'X'.

If there is a record that complies with this condition, the amount of this record, namely the MNG01 field, is written in the required_amount field in the calculation table (lt_data) and the value of the "check" field is updated as "X". Since the check field is X'ed, "check NE 'X'." condition does not pass. In this way, the required amounts are filled into the calculation table.

 

Now we have come to the part where the calculations will begin. First, if the previous loop (the loop inside the lt_mdps table) has been processed, that is, if there is a record in the lt_mdps table, it will enter the next calculation part. Checking this is at the beginning of the calculation part.

IF sy-subrc EQ is provided by setting the condition 0. When it comes to the calculation part, if there is a value in the required_rest (ie remaining need) field from the previous record, it is added to the required_amount (required amount) field in the current line. Whether there is a required_rest value or not is checked with a variable called lv_required_rest, where the value of the required_rest field is written after the calculations are made. Since this is the first record, it doesn't mean anything, but it would be a meaningful move when the required_rest field is full for subsequent records. Then the required_amount – clabs value is checked. As I said before, if the required_amount value is greater than the value of clabs, that is, if the result of this subtraction is greater than 0, the result is written to the required_rest field, but if it is less than 0, it is written to the stock_rest (remaining stock) field. In line with this information, there is an if condition in the code as follows:

IF ( -required_amount - -clabs ) LT 0.
If it is less than 0, it is subtracted and the result is multiplied by -1 and written into the stock_rest field. Since the amount of need value is equal to the amount used, it is written directly into the used field. Of course, since the amount of need is smaller than the lot stock and the lot stock remains after the need is met, it means that there is no other need that this lot can meet before the expiry date. For this reason, this lot is one of the records that will be recorded to the expiration date, and the value of the record field in the table is set to "X". Since there is no remaining need, the lv_required_rest value is set to 0.

ELSE.

If the required_amount - clabs result is greater than 0, it means that some need remains after the required amount is met by the lot stock. Accordingly, the result of the subtraction is written to the required_rest field. Since the lot stock (clabs) is equal to the used stock amount, the clabs value is written directly in the used field. The required_rest value is also set to the lv_required_rest variable so that it can be added to the requirement amount in the next record.

If the sy-subrc value is not 0 after the loop in the lt_mdps table, that is, if there is no record in the lt_mdps table, the code will not enter the calculation part described above. Therefore, the part that I will tell now will show how we proceed in these situations.

The fact that the lt_mdps table is empty means that there is no need for us to use the lot stocks. Therefore, in this case, we write the clabs field (lot stock) directly in the stock_rest field and set the value of the record field as "X". This is the scenario where the lot stock is completely thrown away. Hereby, all calculations are completed.

You can check the sample data of the entire calculation process described above, along with the operations performed, from the tables below for a clearer understanding. The color matches in the requirements table and the lot table show which batch can cover which needs.

Records with PLUMI field "-" from table CH_COPY_MDPSX (with Dates and Amounts):

Lot Data and Calculation Chart:

After the calculations are completed, there is a negative posting part for the lots whose stock is left on the day the expiration date ends. First of all, in order to separate these lots, records with record field "X" are read from the final version of the calculation table (lt_data). Afterwards, for this process, the records with the fields and values as follows for the lots whose expiration date has expired are placed in the table named ch_copy_mdpsx where the MRP items (Stock / Requirement Records) are located.

 mng01 = stock_rest. à - The amount of the lot record to be recorded, equal to the remaining lot stock dat00 = vfdat. Registration date equals expiration date plum = '-'. à Record to be discarded – specified as a valuable record delnr = charg. à Lot No. to MRP item number to identify which lot has expired, value is written delkz = 'WA'. à MRP item type is given “WA – Goods Issue”, a type that is not used systemically plaab = '2'. à A value of 2 here indicates clear planning vrfkz = 'X'. à The “X” value given to this field indicates that this record will be taken into account by MRP planning.


After these records are added to the ch_copy_mdpsx table for all batches one by one, the value of the "ch_changed" variable, which is in the method and works for this purpose, needs to be updated to "X" in order for the system to finally understand that this badi has been changed and to take into account the new situation. After the value of this variable is updated as "X", the development is completed and it shows the unused stock, lot information and the expiration date of the lots whose stock cannot be used until the expiration date, and it becomes taken into account by the MRP.

Below you can see an image of a sample record of a batch whose SKT has been completed:

In addition, we made a revision in the adaptation step, where the text of the MRP elements can be revised so that SKT is written at the beginning of the relevant record, as seen in the image. You can see the adaptation steps and the adaptation below.