2024 Jun 06 4:50 PM - edited 2024 Jun 06 4:52 PM
Dear SAP colleagues,
I would like to reach a question which I have not been able to resolve in SAP. We have a machine in the plant which can produce let's say with two different molds:
I try to deliver a solution in which the MRP is able to pick the corresponding production version optimizing the stocks depending on the requirements on C or D.
Could you please help me with any option?
Thanks and regards!
Request clarification before answering.
@DominikTylczyn Actually this is my code:
METHOD if_ex_md_modify_prodvers~modify_production_version.
" ins - 29.07.2022 - cvivo: select production version for set BOMs depending on MRP situation
" The BAdI will explore all the co-products in the bills of materials for the current planned order and
" calculate the available stock for each. If this available stock is negative, it will be stored in an internal table.
"The alternative with the lowest sum of negative quantities will be picked.
"We do not explore substitutions individually because if alternative 1 has component A (-5 stock) and component B (-15 stock),
" whereas alternative 2 has component A (-5 stock) and component B (3 stock); at total calculation, A is summed in both alternatives,
" leading to its compensation, and only substitute components affect to total differences among alternatives.
TYPES: BEGIN OF ty_version,
verid TYPE mkal-verid,
stlal TYPE mkal-stlal,
stlan TYPE mkal-stlan,
menge TYPE menge_d,
END OF ty_version.
DATA: t_stb_aux TYPE TABLE OF stpox,
t_coproducts TYPE TABLE OF stpox,
t_coproducts_aux TYPE TABLE OF stpox,
t_position TYPE TABLE OF stpox,
t_mrp TYPE TABLE OF bapi_mrp_ind_lines,
selected TYPE mkal,
t_version TYPE TABLE OF ty_version.
SELECT SINGLE FROM tvarvc
WHERE name EQ 'ZPP_PV_SETS'
AND low EQ _matnr
AND high EQ _werks
INTO (result).
IF sy-subrc EQ 0.
SELECT * FROM mkal
WHERE matnr EQ _matnr
AND werks EQ _werks
AND bdatu GE -datlo
AND adatu LE -datlo
AND prfg_r EQ '1' " valid routing
AND prfg_s EQ '1' " valid BOM
AND mksp NE '1' " not locked
INTO TABLE (t_mkal).
IF sy-subrc EQ 0.
SORT t_mkal BY stlan stlal. DELETE ADJACENT DUPLICATES FROM t_mkal COMPARING stlan stlal. " to calculate totals by STLAL we need to ensure there are no duplicate values
LOOP AT t_mkal INTO DATA(mkal).
CALL FUNCTION 'CS_BOM_EXPL_MAT_V2'
EXPORTING
capid = 'PP01'
emeng = 1
datuv = sy-datlo
mtnrv = im_matnr
werks = im_werks
stlan = mkal-stlan
stlal = mkal-stlal
verid = mkal-verid
TABLES
stb = t_stb_aux
EXCEPTIONS
alt_not_found = 1
call_invalid = 2
material_not_found = 3
missing_authorization = 4
no_bom_found = 5
no_plant_data = 6
no_suitable_bom_found = 7
conversion_error = 8
OTHERS = 9.
DELETE t_stb_aux WHERE kzkup IS INITIAL.
CHECK t_stb_aux[] IS NOT INITIAL.
APPEND INITIAL LINE TO t_version ASSIGNING FIELD-SYMBOL(<version>).
MOVE-CORRESPONDING mkal TO <version>.
LOOP AT t_stb_aux ASSIGNING FIELD-SYMBOL(<stb>).
<stb>-mnglg = 0. " we will use this field for MRP available quantity result
CALL FUNCTION 'BAPI_MATERIAL_STOCK_REQ_LIST'
EXPORTING
material = <stb>-idnrk
plant = <stb>-werks
TABLES
mrp_ind_lines = t_mrp.
DELETE t_mrp WHERE avail_date GT im_date.
CHECK t_mrp[] IS NOT INITIAL.
DATA(index) = lines( t_mrp ).
DATA(mrp) = t_mrp[ index ]. " last entry for the date will be the one with the actual available quantity
<stb>-mnglg = mrp-avail_qty1.
IF <stb>-mnglg LT 0. " positive values will be discarded for version selection
ADD <stb>-mnglg TO <version>-menge.
APPEND <stb> TO t_coproducts. " just for informative purpose
ENDIF.
ENDLOOP.
ENDLOOP.
CHECK t_version[] IS NOT INITIAL.
SORT t_version BY menge ASCENDING.
DATA(version) = t_version[ 1 ]. " selected version will be the one with the lowest available quantity (considering just shortages)
ch_verid = version-verid.
ch_changed = 'X'.
ELSE.
EXIT.
ENDIF.
ENDIF.
ENDMETHOD.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello @cvivo_pelzer
It is all but impossible to analyze the code from a posting. However, what struck me is the you use stock/requirements list to check components availability. That's not correct. You should use BAPI_MATERIAL_AVAILABILITY to verify components availability. Stock/requirements list and ATP has different logic - the former shows stock levels, the latter - stock availability. To explain that let's consider a very simple example:
Now if you check the stock level on 10.06.2024 with stock/requirements list, you'll get the value of 1 PC. However if you check stock availability on 10.06.2024 with ATP, you'll get the value of 0 PC, because the current stock is already allocated (confirmed) to the sales order.
Besides, what you are trying to achieve is complex to implement in the context of MRP run. The logic might work for the 1st planned order, but then when you check again components availability for the next planned order, you need to take into account the product version and its components already select for the 1st planned order and do the same for all subsequent planned orders. If you consider that MRP run can be parallelized and a component can be shared across multiple product, you realize the complexity of the task.
Instead consider, manual selection of product version with a customized search help that I've described previously. That has an added benefit, that a production version can be selected just before releasing a production order thus verifying the most recent availability situation of the components.
Best regards
Dominik Tylczynski
Hello @cvivo_pelzer
I don't think you can implement such a requirement in standard. You'd need to put version selection logic into the MD_MODIFY_PRODVERS BAdI enhancement.
Once I faced a similar requirement - a customer wanted manual production version selection in production order based on components availability. I had to develop a custom search help for the production version field. The search looped through all production versions, exploded their BOMs, checked availability of components and presented the results in a nice ALV tree list. Then a user could select a version, which components were available.
Best regards
Dominik Tylczynski
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
5 | |
4 | |
4 | |
3 | |
2 | |
2 | |
2 | |
1 | |
1 | |
1 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.