SAP SCM Core Interface Function (CIF) Training
SAP SCM-APO Master Data Core
Interface Enhancements / User Exits
ABAP Code for SAP SCM-APO Core Interface (CIF) Custom Enhancements /
User Exits for bringing Master Data from SAP ECC to SAP SCM-APO Server.
This Document gives the ABAP Program Code for the SAP User Exit Enhancements done to the
SAP SCM-APO and ECC/R3 System for APO related Master Data for bringing via the Core
Interface Function (CIF) from ECC to SCM-APO for use in APO Supply Planning SAP Modules like
SNP, PPDS, GATP … etc. User-Exits of Product Master, Location Master, PPM Master data and
Stock data are present in this document.
Ambrish Mathur
SAP SCM Core Interface Function (CIF) Training SAP SCM-APO Master-data CIF ABAP Enhancements / User-Exits
SAP System : SAP SCM-APO Server
User-Exit Enhancement CMOD : LOCINBD , Enhancement : APOCF001
ABAP Include : ZXCIFUSERU06 – Modify Location data Incoming into SCM-APO
Auto-Populate Location Time-Zone to ’UTC’ if not defined and coming from ECC/R3.
Auto-Populate ATD Receipts Category and ATD Issues Category fields for SNP Deployment functionality if
not setup Manually in the Location.
*&---------------------------------------------------------------------*
*& Include ZXCIFUSERU06
*&---------------------------------------------------------------------*
*& 09/12/2009 - Created Ambrish Mathur - Head SAP SCM CoE
*& 09/12/2010 - Modified Ambrish Mathur - Head SAP SCM CoE
*&---------------------------------------------------------------------*
*& Ambrish Mathur - Put Code Here to Change Location Master Field Values coming
*& from ECC/R3 to SCM-APO via this User-Exit (Customer Enhancement).
*&---------------------------------------------------------------------*
*& Location Master Field Values which contain data coming from ECC/R3 via CIF Integration Model
*& can be Modified in Structures (which contain the values) ...
*& 1. IT_LOC - Location Specific Data (MOST COMMONLY USED)
*& 2. IT_LOCTXT - Location Texts
*& 3. IT_LOCADR - Location Address Data
*&
*& To Change Values coming from ECC/R3 into SCM-APO ... set the Values of the
*& Field in the above Structure (e.g. :- In IT_LOC Structure - Field TZONE is for Time Zone,
*& and similarly in the IT_LOCADR Structure (Address) - Field TIME_ZONE is for the Time Zone.
*& We can set the TimeZone to 'UTC' as a Default if Blank to avoid Time Zone Issues in Planning in SCM-APO.
*& Some Areas of SCM-APO in SNP Module do not plan correct Dates of Planned Receipts unless UTC is used.
*& Another Example is the ATD Receipts (ATDSP) and ATD Issues (ATDDM) Category are Blank (used in SNP
Deployment)
*& then we can set a Default Value to be used.
*&
*& ADDITIONALLY ...
*& THEN ALSO SET the FLAG to 'X' for the Corresponding field in IT_LOCX, IT_LOCTXTX and IT_LOCADRX
*& Structures to tell the System to Update this Field in SCM-APO from the Value specified via this User-Exit
*&
*& EXAMPLE : Some Areas of SCM-APO in SNP do not Plan correct Dates for Planned Receipts unless UTC TimeZone is
Used.
Copyright 2014-2020 : Ambrish Mathur 2
SAP SCM Core Interface Function (CIF) Training SAP SCM-APO Master-data CIF ABAP Enhancements / User-Exits
*& Set the Time Zone to UTC if the Location TimeZones are Blank or not in UTC for DC and Mfg. Plant
Locations.
*& Also if the ATD Receipts and Issues Category is not Specified, set a Default Value.
*&
*& The Code will Look like ...
*&---------------------------------------------------------------------*
*&
TABLES : /SAPAPO/LOC.
DATA : WS_MODIFY(1) TYPE C VALUE ' ',
WS_VALID_LOC(1) TYPE C VALUE ' '.
LOOP AT IT_LOC. "Loop at all Location data coming via CIF in each RFC Queue. There will be many Records.
WS_MODIFY = ' '.
WS_VALID_LOC = ' '.
IF ( IT_LOC-LOCTYPE = '1001' ) OR "If Location Type is a Plant
( IT_LOC-LOCTYPE = '1002' ) OR "If Location Type is a Distribution Center
( IT_LOC-LOCTYPE = '1040' ) OR "If Location Type is a Store (Retail)
( IT_LOC-LOCTYPE = '1010' ) OR "If Location Type is a VMI Customer
( IT_LOC-LOCTYPE = '1011' ) OR "If Location Type is a Vendor
( IT_LOC-LOCTYPE = '1050' ). "If Location Type is a Sub-Contractor
** CLEAR /SAPAPO/LOC.
** Read Location from APO Location Master data table
SELECT SINGLE * FROM /SAPAPO/LOC WHERE
LOCNO = IT_LOC-EXT_LOCNO.
IF SY-SUBRC EQ 0.
WS_VALID_LOC = 'X'. "Existing Location from ECC/R3 to APO.
ELSE.
WS_VALID_LOC = '1'. "First Time Transfer from ECC/R3 to APO.
ENDIF.
** IF IT_LOC-TZONE+0(3) NE 'UTC'. "If TimeZone of Location does not start with UTC
IF IT_LOC-TZONE+0(3) EQ ''. "If TimeZone of Location is Blank
MOVE 'UTC' TO IT_LOC-TZONE. "Value coming from ECC/R3 via CIF is Initialized and Not Updated in SCM-APO
MOVE 'X' TO WS_MODIFY.
ENDIF.
IF WS_VALID_LOC = '1'.
Copyright 2014-2020 : Ambrish Mathur 3
SAP SCM Core Interface Function (CIF) Training SAP SCM-APO Master-data CIF ABAP Enhancements / User-Exits
IF IT_LOC-ATDSP EQ ''. "If No ATD Receipts Category Group has been Specified, Set a Default
MOVE 'ZTR' TO IT_LOC-ATDSP.
MOVE 'X' TO WS_MODIFY.
ENDIF.
IF IT_LOC-ATDDM EQ ''. "If No ATD Issues Category Group has been Specified, Set a Default
MOVE 'ZTI' TO IT_LOC-ATDDM.
MOVE 'X' TO WS_MODIFY.
ENDIF.
ELSE.
IF /SAPAPO/LOC-ATDSP EQ ''. "If No ATD Receipts Category Group has been Specified, Set a Default
MOVE 'ZTR' TO IT_LOC-ATDSP.
MOVE 'X' TO WS_MODIFY.
ENDIF.
IF /SAPAPO/LOC-ATDDM EQ ''. "If No ATD Issues Category Group has been Specified, Set a Default
MOVE 'ZTI' TO IT_LOC-ATDDM.
MOVE 'X' TO WS_MODIFY.
ENDIF.
ENDIF.
IF WS_MODIFY = 'X'.
MODIFY IT_LOC INDEX SY-TABIX. "Update the Internal LOC Table
ENDIF.
** Set the Field Update Flags in LOCX Structure if any Field was Modified
IF WS_MODIFY = 'X'.
LOOP AT IT_LOCX. "Loop at all Locations where TimeZone, ATD Receipts and ATD Issues was changed
IF IT_LOC-EXT_LOCNO = IT_LOCX-EXT_LOCNO. "If Location Address Record is of Same Location
MOVE 'X' TO IT_LOCX-TZONE. "Set the Flag to Update Time Zone in SCM-APO Location
MOVE 'X' TO IT_LOCX-ATDSP. "Set the Flag to Update ATD Receipts Category in SCM-APO Location
MOVE 'X' TO IT_LOCX-ATDDM. "Set the Flag to Update ATD Issues Category in SCM-APO Location
MODIFY IT_LOCX INDEX SY-TABIX. "Update the Internal LOCX Table
ENDIF.
ENDLOOP. "Loop at all Location ADDRESS data coming via CIF in each RFC Queue. There will be many Records.
LOOP AT IT_LOCADR. "Loop at all Location ADDRESS data coming via CIF in each RFC Queue. There will be many
Records.
IF IT_LOC-EXT_LOCNO = IT_LOCADR-EXT_LOCNO. "If Location Address Record is of Same Location
*** IF IT_LOCADR-TIME_ZONE+0(3) NE 'UTC'. "If TimeZone of Location does Start with UTC then Change
IF IT_LOCADR-TIME_ZONE+0(3) EQ ''. "If TimeZone of Location is Blank
Copyright 2014-2020 : Ambrish Mathur 4
SAP SCM Core Interface Function (CIF) Training SAP SCM-APO Master-data CIF ABAP Enhancements / User-Exits
MOVE IT_LOC-TZONE TO IT_LOCADR-TIME_ZONE. "Value coming from ECC/R3 via CIF is Initialized and Not
Updated in SCM-APO
MODIFY IT_LOCADR INDEX SY-TABIX. "Update the Internal LOCADR Table
ENDIF.
ENDIF.
ENDLOOP. "Loop at all Location ADDRESS data coming via CIF in each RFC Queue. There will be many Records.
ENDIF.
ENDIF.
WS_MODIFY = ' '.
ENDLOOP. "Loop at all Location data coming via CIF in each RFC Queue. There will be many Records.
Copyright 2014-2020 : Ambrish Mathur 5
SAP SCM Core Interface Function (CIF) Training SAP SCM-APO Master-data CIF ABAP Enhancements / User-Exits
SAP System : SAP SCM-APO Server
User-Exit Enhancement CMOD : PRODINBD , Enhancement : APOCF005
ABAP Include : ZXCIFUSERU08 – Modify Products data Incoming into SCM-APO
Do not Update Safety Stock or Safety Time coming from ECC/R3 into SCM-APO if Advanced Safety Stock
Planning Calculations are set in SCM-APO for Products.
*&---------------------------------------------------------------------*
*& Include ZXCIFUSERU08
*&---------------------------------------------------------------------*
*& 09/12/2009 - Ambrish Mathur - Head SAP SCM CoE - Initial Development
*& 08/09/2010 - Ambrish Mathur - Head SAP SCM Solutions - Do not bring GR time from R3 for Production Plants
*& 11/09/2010 - Ambrish Mathur - Head SAP SCM Solutions - For FG1 to FG9 Set Procurement type to "P" (Ext. Plng.)
*& as they will not be Planned in SCM-APO
*& 14/09/2010 - Ambrish Mathur - Head SAP SCM Solutions - This Hardcoding was removed, as User Exit CIFMAT01
*& in ECC was Set for Materials not Relevant to APO
Planning.
*& 22/12/2010 - Ambrish Mathur - Head SAP SCM Solutions - Do not Update Safety Stock METHOD field. Correct Bug.
*&---------------------------------------------------------------------*
*& Ambrish Mathur - Put Code Here to Change Material Master Field Values coming
*& from ECC/R3 to SCM-APO via this User-Exit (Customer Enhancement).
*&---------------------------------------------------------------------*
*& Material Master Field Values which contain data coming from ECC/R3 via CIF Integration Model
*& can be Modified in Structures (which contain the values) ...
*& 1. IT_MATLOC - Product-Location Specific Data (MOST COMMONLY USED)
*& 2. IT_MATKEY - Products Header Data
*& 3. IT_MARM - Product Unit Of Measure Conversion Factors for Alternative Units
*& 4. IT_MATVERS - Products Version-Specific Data
*& 5. IT_PENALTY1 - Product Header Optimizer Non-Delivery Penalty and Delay Costs
*& 6. IT_PENALTY2 - Product Location Specific Optimizer Non-Delivery Penalty and Delay Costs
*&
*& To Change Values coming from ECC/R3 into SCM-APO ... set the Values of the
*& Field in the above Structure (e.g. :- In IT_MATLOC Structure - Field SAFTY is for Safety Stock,
*& Field SVTTY for Safety Days Supply and these Values can be Blocked from coming from ECC to SCM-APO
*& if we are doing Advanced Safety Stock Planning in SCM-APO to Calculate Safety Stock Values.
*& Other Examples are Field PLANNER_PPS can be updated via ECC MRP Controller automatically,
*& Field PEG_STRATEGY for Updating Pegging Strategy in Demand View based on PP/DS Planning Procedure
Copyright 2014-2020 : Ambrish Mathur 6
SAP SCM Core Interface Function (CIF) Training SAP SCM-APO Master-data CIF ABAP Enhancements / User-Exits
*& Field PEG_PAST_ALERT to Update Max. Days for Pegging Alerts in Demand View ... etc.
*&
*& ADDITIONALLY ...
*& THEN ALSO SET the FLAG to 'X' for the Corresponding field in IT_MATLOCX, IT_MATKEYX, IT_MATVERX,
*& IT_PENALTY1X, IT_PENALTY2X and IT_MARMX Structures to tell the System to Update this Field in SCM-APO
*& from the Value specified via this User-Exit
*&
*& EXAMPLE : If we are doing Safety Stock Calculations automatically in SCM-APO via
*& SNP module Advanced Safety Stock Planning Features, then we need to Block the
*& Safety Stock and Safety Time to come in Automatically from ECC/R3 Material Master (MRP2) via CIF.
*& However the Lot-Sizes (Min Lot Size, Max Lot Size, Lot Procedure, Rounding Values
*& will still come from the ECC/R3 Material Master field values in MRP1, MRP2 views.
*&
*& EXAMPLE2 : Since PPDS Planning for Repetitive Manufacturing Products requires that GR Processing time should
*& be 0 in Manufacturing Location as the PPDS REM/Wave Heuristic does not Support it, Code has been put
*& to NOT UPDATE the GR Processing time in SCM-APO for PP/DS. This is actually applicable to only
*& automated Production Planning of PPDS REM (Repetitive Manufacturing) Products.
*&
*& The Code will Look like ...
*&
*** TABLES : /SAPAPO/LOC,
TABLES : /SAPAPO/MATKEY,
/SAPAPO/MATLOC,
/SAPAPO/MATLOTSZ.
DATA : w_matloc_ss_method like it_matloc-msdp_sb_method,
w_skip_ss_method_check type c value 'X'.
LOOP AT IT_MATLOC. "Loop at all Material-Location data coming via CIF in each RFC Queue. There will be many
Records.
CLEAR : w_matloc_ss_method, w_skip_ss_method_check.
* Validate LOC Table for the Product Location
SELECT SINGLE * FROM /SAPAPO/LOC WHERE LOCNO = IT_MATLOC-EXT_LOCNO.
IF SY-SUBRC NE 0.
MOVE 'X' to w_skip_ss_method_check. "Do not Check Product Location SS Method. This is First Time Transfer
into SCM-APO
ENDIF.
Copyright 2014-2020 : Ambrish Mathur 7
SAP SCM Core Interface Function (CIF) Training SAP SCM-APO Master-data CIF ABAP Enhancements / User-Exits
* Validate MATKEY Table for the Product Location
SELECT SINGLE * FROM /SAPAPO/MATKEY WHERE MATNR = IT_MATLOC-EXT_MATNR.
IF SY-SUBRC NE 0.
MOVE 'X' to w_skip_ss_method_check. "Do not Check Product Location SS Method. This is First Time Transfer
into SCM-APO
ENDIF.
* Validate MATLOC Table for the Product Location
SELECT SINGLE * FROM /SAPAPO/MATLOC WHERE LOCID = /SAPAPO/LOC-LOCID
AND MATID = /SAPAPO/MATKEY-MATID.
*** AND LVORM = ' '.
IF SY-SUBRC NE 0.
MOVE 'X' to w_skip_ss_method_check. "Do not Check Product Location SS Method. This is First Time Transfer
into SCM-APO
ENDIF.
* Validate MATLOTSZ Table for the Product Location Lot Sizes and Find Safety Stock Method
SELECT SINGLE * FROM /SAPAPO/MATLOTSZ WHERE LSZID = /SAPAPO/MATLOC-LSZID.
IF SY-SUBRC NE 0.
* MOVE 'X' to w_skip_ss_method_check. "Do not Check Product Location SS Method. This is First Time Transfer
into SCM-APO
ENDIF.
IF w_skip_ss_method_check = 'X'.
* MOVE IT_MATLOC-MSDP_SB_METHOD TO W_MATLOC_SS_METHOD.
CLEAR W_MATLOC_SS_METHOD.
ELSE.
* Move MATLOC Safety Stock Method to Internal Variable.
MOVE /SAPAPO/MATLOC-MSDP_SB_METHOD TO W_MATLOC_SS_METHOD.
ENDIF.
IF ( W_MATLOC_SS_METHOD = 'BS' ) OR "If APO Safety Stock Planning Method = BS (Beta Service Level, Reorder
Point)
( W_MATLOC_SS_METHOD = 'BT' ) OR "If APO Safety Stock Planning Method = BT (Beta Service Level, Reorder
Cycle)
( W_MATLOC_SS_METHOD = 'AS' ) OR "If APO Safety Stock Planning Method = AS (Alpha Service Level, Reorder
Point)
( W_MATLOC_SS_METHOD = 'AT' ) OR "If APO Safety Stock Planning Method = AT (Alpha Service Level, Reorder
Cycle)
Copyright 2014-2020 : Ambrish Mathur 8
SAP SCM Core Interface Function (CIF) Training SAP SCM-APO Master-data CIF ABAP Enhancements / User-Exits
( W_MATLOC_SS_METHOD = 'MB' ) OR "If APO Safety Stock Planning Method = MB (Time Based Manual Safety Stock
Maintenance in APO)
( W_MATLOC_SS_METHOD = 'MZ' ) OR "If APO Safety Stock Planning Method = MZ (Time Based Manual Safety Days
Supply Maintenance in APO)
( W_MATLOC_SS_METHOD = ' ' ). "No APO SS Method comes from ECC/R3 (i.e : Safety Stock or Safety Time in
ECC not defined)
CLEAR IT_MATLOC-SAFTY. "Value coming from ECC/R3 via CIF is Initialized and Not Updated in SCM-APO
CLEAR IT_MATLOC-SVTTY. "Value coming from ECC/R3 via CIF is Initialized and Not Updated in SCM-APO
CLEAR IT_MATLOC-MSDP_SB_METHOD. "Do not Update Safety Stock Method in SCM-APO
MODIFY IT_MATLOC INDEX SY-TABIX. "Update the Internal MATLOC Table
READ TABLE IT_MATLOCX WITH KEY
EXT_MATNR = IT_MATLOC-EXT_MATNR
EXT_LOCNO = IT_MATLOC-EXT_LOCNO.
IF SY-SUBRC EQ 0.
CLEAR IT_MATLOCX-SAFTY. "Value coming from ECC/R3 via CIF is Initialized and Not Updated in SCM-APO
CLEAR IT_MATLOCX-SVTTY. "Value coming from ECC/R3 via CIF is Initialized and Not Updated in SCM-APO
CLEAR IT_MATLOCX-MSDP_SB_METHOD. "Do not Update Safety Stock Method in SCM-APO
MODIFY IT_MATLOCX INDEX SY-TABIX. "Update the Internal MATLOCX Table
ENDIF.
ENDIF.
*& For Manufacturing Locations Do Not Update the GR Processing from ECC/R3 into SCM-APO Product Master
*& for Repetitive Manufacturing Products which are likely to use the PPDS REM Heuristic.
*& This Hardcoding was removed, as User Exit CIFMAT01 in ECC was Set for Materials not Relevant to APO Planning.
* IF ( /SAPAPO/LOC-LOCTYPE = '1001' ) AND "Location is a Manufacturing Plant
* ( ( IT_MATLOC-BESKZ = 'E' ) OR ( IT_MATLOC-BESKZ = 'X' ) ) AND "Product is Inhouse Produced
* ( IT_MATLOC-CONVH > 0 ). "PP/DS Production Horizon is defined = PPDS is used
*
* IF ( ( IT_MATLOC-EXT_MATNR+0(3) = 'FG1' ) OR "Hard-Coded Repetitive Manufacturing FG & SFG Products
* ( IT_MATLOC-EXT_MATNR+0(3) = 'FG2' ) OR
* ( IT_MATLOC-EXT_MATNR+0(3) = 'FG7' ) OR "Expand this HardCoded List as More REM Products are Added
* ( IT_MATLOC-EXT_MATNR+0(4) = 'SFG1' ) OR
* ( IT_MATLOC-EXT_MATNR+0(4) = 'SFG2' ) OR
* ( IT_MATLOC-EXT_MATNR+0(4) = 'SFG7' ) ). "Hard-Coded Repetitive Manufacturing FG & SFG Products
*
* CLEAR IT_MATLOC-GRPRT. "Clear the GR Processing time coming from ECC/R3 into SCM-APO
* MODIFY IT_MATLOC INDEX SY-TABIX. "Update the Internal MATLOC Table
* READ TABLE IT_MATLOCX WITH KEY
* EXT_MATNR = IT_MATLOC-EXT_MATNR
* EXT_LOCNO = IT_MATLOC-EXT_LOCNO.
Copyright 2014-2020 : Ambrish Mathur 9
SAP SCM Core Interface Function (CIF) Training SAP SCM-APO Master-data CIF ABAP Enhancements / User-Exits
* IF SY-SUBRC EQ 0.
* CLEAR IT_MATLOCX-GRPRT. "Value coming from ECC/R3 via CIF is Initialized and Not Updated in SCM-APO
* MODIFY IT_MATLOCX INDEX SY-TABIX. "Update the Internal MATLOCX Table
* ENDIF.
*
* ENDIF.
* ENDIF.
*
*& For Products FG1 to FG9 Set Procurement Type in APO to "P" = No Planning in SCM-APO
*& This Hardcoding was removed, as User Exit CIFMAT01 in ECC was Set for Materials not Relevant to APO Planning.
* IF ( ( IT_MATLOC-EXT_MATNR = 'FG1' ) OR "Hard-Coded FG Products for No Planning in SCM-APO
* ( IT_MATLOC-EXT_MATNR = 'FG2' ) OR
* ( IT_MATLOC-EXT_MATNR = 'FG3' ) OR
* ( IT_MATLOC-EXT_MATNR = 'FG4' ) OR
* ( IT_MATLOC-EXT_MATNR = 'FG5' ) OR
* ( IT_MATLOC-EXT_MATNR = 'FG6' ) OR
* ( IT_MATLOC-EXT_MATNR = 'FG7' ) OR
* ( IT_MATLOC-EXT_MATNR = 'FG8' ) OR
* ( IT_MATLOC-EXT_MATNR = 'FG9' ) OR
* ( IT_MATLOC-EXT_MATNR = 'FG10' ) ).
*
* IT_MATLOC-BESKZ = 'P'. "Set Procurement Type to P = No Planning in SCM-APO
* MODIFY IT_MATLOC INDEX SY-TABIX. "Update the Internal MATLOC Table
*
* ENDIF.
ENDLOOP. "Loop at all Material-Location data coming via CIF in each RFC Queue. There will be many Records.
*&
*& The Above Code can be CONDITIONALLY done for Specific Types of Product Types, Location Types ... etc.
*& for which we'd have to Put the ABAP CODE for the CONDITION under which the Data must be Modified.
*&
Copyright 2014-2020 : Ambrish Mathur 10
SAP SCM Core Interface Function (CIF) Training SAP SCM-APO Master-data CIF ABAP Enhancements / User-Exits
SAP System : SAP SCM-APO Server
User-Exit Enhancement CMOD : PPMINBD , Enhancement : APOCF012
ABAP Include : ZXCIFUSERU16 – Modify PPMs data Incoming into SCM-APO
Set the Sequence Dependent Setup Flag in PPMs if Setup Matrix for PPDS PPM Operation if it has been
defined and Initialize the Setup Time in PPM.
For PPMs containing Mixed Resources relevant to SNP, Auto-Populate Bucket Capacities from Time Continuous
Capacities in PPDS PPM for Planning Production in SNP.
Auto-Populate Mode Priority from Mode Value in PPDS PPMs.
*&----------------------------------------------------------------------------------------------------------------
------*
*& Include ZXCIFUSERU16
*&----------------------------------------------------------------------------------------------------------------
------*
*& 24/09/2010 - Ambrish Mathur - Head SAP SCM Solutions and Delivery
*& In PPMs coming Inbound from ECC to APO
*& Changes done in ECC Refresh in APO the PPM Operation Activity 'Setup'
*& indicator for Sequence Dependent Setup determined via SETUP MATRIX.
*& This User-Exit will prevent the Automatic Change of resetting the Flag
*& if Setup Group/Key has been maintained to allow Sequence-Dependent Setup.
*& ALSO it will Reset the FIXED BUCKET Consumption of a "Mixed" Resource to 0
*& as it is not required to be defined when 'Setup' Flag is set.
*&
*& 25/09/2010 - Ambrish Mathur - Head SAP SCM Solutions and Delivery
*& For Activities of Type 'Produce' & 'Setup' BOTH the User-Exit also AUTO-POPULATES
the
*& Activity Mode BUCKET Variable Capacity to the same as Activity Mode Variable
Capacity
*& and the BUCKET Fixed Capacity to the same as Activity Mode Fixed Capacity.
*& ALSO for Produce Activity do not Update Sequence-Dependent Setup Flag from data
*& coming from ECC as it may be Manually Maintained in APO directly in PPM.
*&
*& 23/11/2010 - Ambrish Mathur - Head SAP SCM Solutions and Delivery
*& Continuing on Modification for ECC, we find that PPMs for Process Industry (PP-
PI)
*& have Multiple Modes, but Mode Priority is always 'A'. This Enhancement will
change
Copyright 2014-2020 : Ambrish Mathur 11
SAP SCM Core Interface Function (CIF) Training SAP SCM-APO Master-data CIF ABAP Enhancements / User-Exits
*& Mode 2=Priority B, Mode 3 = Priority C ... Mode 15 = Prority O, Mode 16++ =
Priority Z
*& ONLY if the Modes Priorities coming from ECC do not Match with above Rule.
*& For Discrete & Repetitive Manufacturing PPM Mode Priorities coming from ECC are
OK
*& & will not be modified. This impacts PPMs coming from Recipes for Process
Industry.
*& Part-II addition is ...
*& ALSO Sets the BUCKET Capacity Update Flags for Secondary Resources which are not
in Modes.
*&
*& 21/04/2011 - Ambrish Mathur - Head SAP SCM Solutions and Delivery
*& For New PPMs, Adding Logic to Check Setup Key coming via CIF & not just
*& past PPM Operation data (for new PPMs). This was a Error in past code.
*&
*& DEC-2010 or LATER ... to be done via the ECC Outbound PPM User-Exit (not here)
*& Also for RECIPE coming from ECC, we find that the Alternate Resources Mode 2,3
... etc.
*& have the same Line Speeds / Durations as the Mode 1 resource.
*& This is a SAP ECC & APO PPDS Limitation in the CIF (Resource Classification used
in ECC)
*& Have to Investigate a CIF Userexit to Populate a different Line Speed / Duration
*& for Alternate Resources in the PPM for Process Industry Products
*& A Solution Lies in looking at RECIPES where Alternate Resources are PRIMARY
Resources
*& the Code of this has to be designed still.
*&----------------------------------------------------------------------------------------------------------------
------*
*& Ambrish Mathur - Put Code Here to Change PPM Master Field Values coming
*& from ECC/R3 to SCM-APO via this User-Exit (Customer Enhancement).
*&----------------------------------------------------------------------------------------------------------------
------*
*& PPM Master Field Values which contain data coming from ECC/R3 via CIF Integration Model
*& can be Modified in Structures (which contain the values) ...
*& 1. IT_CIF_PLANOPR - PPM Operations data
*& 2. IT_CIF_PLANACT - PPM Operation Activities
*& 3. IT_CIF_MODE - PPM Operation Activity Modes
*& 4. IT_CIF_REQCAP - PPM Operation Activity Modes Capacity - Resource Bucket Capacity duration
*&
*& ADDITIONALLY ...
Copyright 2014-2020 : Ambrish Mathur 12
SAP SCM Core Interface Function (CIF) Training SAP SCM-APO Master-data CIF ABAP Enhancements / User-Exits
*& THEN ALSO SET the FLAG to 'X' for the Corresponding field in IT_CIF_PLANOPRX, IT_CIF_PLANACTX, IT_CIF_MODEX,
*& IT_CIF_REQCAPX ... etc. to tell the System to Update this Field in SCM-APO from the Value specified via this
UExit.
*&
*&----------------------------------------------------------------------------------------------------------------
------*
*&
* TABLES : /SAPAPO/LOC,
* /SAPAPO/MATKEY,
* /SAPAPO/MATLOC,
* /SAPAPO/MATLOTSZ,
TABLES : /SAPAPO/PLAN,
/SAPAPO/PLANOPR,
/SAPAPO/SET_ID,
/SAPAPO/PLANACT,
/SAPAPO/MODE,
/SAPAPO/RES_HEAD,
/SAPAPO/RESKEY.
DATA : WA_PPMACTMODE_DURVARIABLE LIKE IT_CIF_MODE-DUR1,
WA_PPMACTMODE_DURUNIT LIKE IT_CIF_MODE-UNIT,
WA_PPMACTMODE_DURFIXED LIKE IT_CIF_MODE-DUR2.
DATA: L_PRIO_STRING(16) TYPE C,
WS_MODE_NUMBER TYPE I,
WS_MODE_OFFSET TYPE I,
WS_ECC_MODE_PRIO LIKE IT_CIF_MODE-MODE_PRIO,
WS_APO_MODE_PRIO LIKE IT_CIF_MODE-MODE_PRIO.
***-----------------------------------------------------------------------------------------------
L_PRIO_STRING = 'ABCDEFGHIJKLMNOZ'.
LOOP AT IT_CIF_PLANACT. "Begin of LOOP thru all the PPM Activities
CLEAR : WA_PPMACTMODE_DURVARIABLE, WA_PPMACTMODE_DURUNIT, WA_PPMACTMODE_DURFIXED.
** Loop thru all the PPM Operation Activities and Read the Operation data for the PPM Activity
CLEAR IT_CIF_PLANOPR.
READ TABLE IT_CIF_PLANOPR WITH KEY
EXT_PLANNR = IT_CIF_PLANACT-EXT_PLANNR
Copyright 2014-2020 : Ambrish Mathur 13
SAP SCM Core Interface Function (CIF) Training SAP SCM-APO Master-data CIF ABAP Enhancements / User-Exits
VORNR = IT_CIF_PLANACT-VORNR.
IF SY-SUBRC EQ 0.
** Read PPM Plan from SCM-APO Master data table
SELECT SINGLE * FROM /SAPAPO/PLAN WHERE
PLANNR = IT_CIF_PLANOPR-EXT_PLANNR.
IF SY-SUBRC EQ 0 AND
/SAPAPO/PLAN-PL_USAGE = 'P'. "Update Sequence Dep. Setup Flag in PPDS PPMs only
*** /SAPAPO/PLAN-STATE = '1'. "PPM is Active = 1 (Inactive = 0)
*** Disable Active PPM check to allow change for First-time Transfer of Inactive PPM from ECC to SCM-APO.
** Read PPM Plan Operation for the Activity from SCM-APO Master data table
SELECT SINGLE * FROM /SAPAPO/PLANOPR WHERE
PLANID = /SAPAPO/PLAN-PLANID AND
VORNR = IT_CIF_PLANOPR-VORNR.
IF SY-SUBRC EQ 0.
***---------------------------------------------------------------------------------------------------------------
-----*
*** PART-I of the USER-EXIT - AUTO-POPULATE BUCKET CAPACITY for PRODUCE & SETUP ACTIVITIES & do not Update
Setup
*** - Also Update the Mode Priorities in line with Mode Numbers - Process Industry
***---------------------------------------------------------------------------------------------------------------
-----*
** If Activity Type is of Type Produce OR Setup, check if Resource is "Single-Mixed" in Activity Mode, then
** Autoset the Bucket Capacity Durations from the Resource Mode's Variable & Fixed Capacity Durations
*** :)) To understand Code, see all the Error Messages in CHECK of Fresh PPM from ECC : e.g. - FG3_APO_10 @ MFG1.
IF IT_CIF_PLANACT-ACTTYPE = 'P' OR "BEGIN FOR - PRODUCE AND SETUP ACTIVITY
IT_CIF_PLANACT-ACTTYPE = 'S'.
*** Firstly do not Update Sequence-Dependent Setup Flag from ECC data as it could be MANUALLY Set in APO
*** This Flag will usually not have been set for data coming from ECC for Most Cases
READ TABLE IT_CIF_PLANACT_X WITH KEY
EXT_PLANNR = IT_CIF_PLANACT-EXT_PLANNR
VORNR = IT_CIF_PLANACT-VORNR
ACTNR = IT_CIF_PLANACT-ACTNR.
IF SY-SUBRC EQ 0 AND
Copyright 2014-2020 : Ambrish Mathur 14
SAP SCM Core Interface Function (CIF) Training SAP SCM-APO Master-data CIF ABAP Enhancements / User-Exits
IT_CIF_PLANACT_X-SETUP = 'X'. "This Condition will Usually NOT be True for data coming from ECC
IT_CIF_PLANACT_X-SETUP = ' '. "Not to Update Sequence Dependent Setup Flag in APO PPM from ECC data
MODIFY IT_CIF_PLANACT_X INDEX SY-TABIX.
ENDIF.
*** Secondly Update the Bucket Capacity Durations in Mode Calendar Resource Capacities from Mode Primary Resource
Capacity
LOOP AT IT_CIF_MODE "Begin of LOOP thru all the PPM Activity Modes
WHERE EXT_PLANNR = IT_CIF_PLANACT-EXT_PLANNR AND
VORNR = IT_CIF_PLANACT-VORNR AND
ACTNR = IT_CIF_PLANACT-ACTNR.
CLEAR : /SAPAPO/RES_HEAD, /SAPAPO/RESKEY.
IF IT_CIF_MODE-RESNAME <> ''.
SELECT SINGLE * FROM /SAPAPO/RES_HEAD WHERE NAME = IT_CIF_MODE-RESNAME AND
SIMVERSID = '000'.
ELSE.
SELECT SINGLE * FROM /SAPAPO/RESKEY WHERE R3KAPID = IT_CIF_MODE-KAPID.
IF SY-SUBRC EQ 0.
SELECT SINGLE * FROM /SAPAPO/RES_HEAD WHERE NAME = /SAPAPO/RESKEY-NAME AND
SIMVERSID = '000'.
ENDIF.
ENDIF.
IF SY-SUBRC EQ 0.
*** PART I-A - Setup Bucket Capacities for PPM if Resources are Mixed Resources - 25/09/2010 - Ambrish
IF ( /SAPAPO/RES_HEAD-TYPE = 04 OR "Only Single-Mixed (4) Resources OR
/SAPAPO/RES_HEAD-TYPE = 05 ). "Multi-Mixed(5) Resources have Bucket Capacity
*** /SAPAPO/RES_HEAD-TYPE = 08 ). "Transport(8) Resources also have Bucket Capacity, but not
used in Production
CLEAR : WA_PPMACTMODE_DURVARIABLE, WA_PPMACTMODE_DURUNIT, WA_PPMACTMODE_DURFIXED.
WA_PPMACTMODE_DURVARIABLE = IT_CIF_MODE-DUR1.
WA_PPMACTMODE_DURFIXED = IT_CIF_MODE-DUR2.
WA_PPMACTMODE_DURUNIT = IT_CIF_MODE-UNIT.
LOOP AT IT_CIF_REQCAP "Begin of LOOP thru all the PPM Activity Mode Capacities
WHERE EXT_PLANNR = IT_CIF_MODE-EXT_PLANNR AND
VORNR = IT_CIF_MODE-VORNR AND
Copyright 2014-2020 : Ambrish Mathur 15
SAP SCM Core Interface Function (CIF) Training SAP SCM-APO Master-data CIF ABAP Enhancements / User-Exits
ACTNR = IT_CIF_MODE-ACTNR AND
MODUS = IT_CIF_MODE-MODUS AND
KAPID = IT_CIF_MODE-KAPID.
"This Updates for Primary
Resources only present in MODE
*** RESNAME = IT_CIF_MODE-RESNAME. "Update Bucket Cap. for PRIMARY Resources
in Mode ONLY.
*** Update Bucket Capacity for Only the CALENDAR Resource (Primary Resource) from the Mode Resource which is
Primary
*** The above Read will Read REQCAP from MODE for only Primary Resources. Secondary Resources would be left
unupdated
*** as there are no Records for Secondary Resources in MODE as it is only for Primary Resources.
*** If Bucket Capacity is Not the same as Mode Capacity, Update and SYNCH Values from the PPM ACTIVITY MODE
IF IT_CIF_REQCAP-BCAP1 <> WA_PPMACTMODE_DURVARIABLE OR
IT_CIF_REQCAP-BCAP2 <> WA_PPMACTMODE_DURFIXED OR
IT_CIF_REQCAP-BUNIT <> WA_PPMACTMODE_DURUNIT.
IT_CIF_REQCAP-BCAP1 = WA_PPMACTMODE_DURVARIABLE. "Set the Variable Fixed Duration from Mode.
IT_CIF_REQCAP-BCAP2 = WA_PPMACTMODE_DURFIXED. "Set the Bucket Fixed Duration from Mode.
IT_CIF_REQCAP-BUNIT = WA_PPMACTMODE_DURUNIT. "Set the Unit for Bucket Capacity from Mode.
MODIFY IT_CIF_REQCAP INDEX SY-TABIX.
READ TABLE IT_CIF_REQCAP_X WITH KEY
EXT_PLANNR = IT_CIF_REQCAP-EXT_PLANNR
VORNR = IT_CIF_REQCAP-VORNR
ACTNR = IT_CIF_REQCAP-ACTNR
MODUS = IT_CIF_REQCAP-MODUS
KAPID = IT_CIF_REQCAP-KAPID.
IF SY-SUBRC EQ 0.
IT_CIF_REQCAP_X-BCAP2 = 'X'.
IT_CIF_REQCAP_X-BCAP1 = 'X'.
IT_CIF_REQCAP_X-BUNIT = 'X'.
MODIFY IT_CIF_REQCAP_X INDEX SY-TABIX.
ENDIF.
ENDIF.
ENDLOOP. "End of LOOP thru all the PPM Activity Mode Capacities
Copyright 2014-2020 : Ambrish Mathur 16
SAP SCM Core Interface Function (CIF) Training SAP SCM-APO Master-data CIF ABAP Enhancements / User-Exits
ENDIF.
*** END PART I-A
***-----------------------------------------------------------------------------------------------
*** Part I-B - Code for Determing PPM Mode Priorities from Mode Number if do not Match - Process Industries
***-----------------------------------------------------------------------------------------------
*** PART I-B - Modify Mode Priority to Match Mode Number if they do not match - 22/11/2010 - Ambrish
WS_MODE_NUMBER = IT_CIF_MODE-MODUS.
WS_MODE_OFFSET = WS_MODE_NUMBER - 1.
WS_ECC_MODE_PRIO = IT_CIF_MODE-MODE_PRIO.
WS_APO_MODE_PRIO = WS_ECC_MODE_PRIO.
IF WS_MODE_NUMBER >= 2 AND "Check Mode Nos 2 to 16 only. Skip Mode 1.
WS_MODE_NUMBER <= 16.
WS_APO_MODE_PRIO = L_PRIO_STRING+WS_MODE_OFFSET(1). "Determine APO Mode Priority
***** If ECC Mode Priority is EQUAL to 'A' for Modes >= 2, than Mode Priority determined for APO, then change
APO Mode Priority
IF WS_ECC_MODE_PRIO = 'A' AND "Should be True for only Process Industry Recipe PPMs
WS_ECC_MODE_PRIO < WS_APO_MODE_PRIO AND "Should be True for only Process Industry Recipe
PPMs
WS_MODE_NUMBER >= 2. "Should be True for only Process Industry Recipe PPMs
IT_CIF_MODE-MODE_PRIO = WS_APO_MODE_PRIO.
MODIFY IT_CIF_MODE INDEX SY-TABIX.
READ TABLE IT_CIF_MODE_X WITH KEY
EXT_PLANNR = IT_CIF_MODE-EXT_PLANNR
VORNR = IT_CIF_MODE-VORNR
ACTNR = IT_CIF_MODE-ACTNR
MODUS = IT_CIF_MODE-MODUS
METHOD = IT_CIF_MODE-METHOD
KAPID = IT_CIF_MODE-KAPID.
IF SY-SUBRC EQ 0.
IT_CIF_MODE_X-MODE_PRIO = 'X'.
MODIFY IT_CIF_MODE_X INDEX SY-TABIX.
ENDIF.
*** END PART I-B
ENDIF.
ENDIF.
ENDIF.
ENDLOOP. "End of LOOP thru all the PPM Activity Modes
Copyright 2014-2020 : Ambrish Mathur 17
SAP SCM Core Interface Function (CIF) Training SAP SCM-APO Master-data CIF ABAP Enhancements / User-Exits
ENDIF. "END FOR - PRODUCE OR SETUP ACTIVITY
***---------------------------------------------------------------------------------------------------------------
-----*
*** PART-II of the USER-EXIT - Set the Bucket Capacities Update Flag - For Secondary Resources in MODES (Others
should be set)
***---------------------------------------------------------------------------------------------------------------
-----*
LOOP AT IT_CIF_REQCAP.
IF IT_CIF_REQCAP-BCAP1 > 0 OR
IT_CIF_REQCAP-BCAP2 > 0.
READ TABLE IT_CIF_REQCAP_X WITH KEY
EXT_PLANNR = IT_CIF_REQCAP-EXT_PLANNR
VORNR = IT_CIF_REQCAP-VORNR
ACTNR = IT_CIF_REQCAP-ACTNR
MODUS = IT_CIF_REQCAP-MODUS
KAPID = IT_CIF_REQCAP-KAPID.
IF SY-SUBRC EQ 0.
IF ( IT_CIF_REQCAP-BCAP1 > 0 AND
IT_CIF_REQCAP_X-BCAP1 <> 'X' ) OR
( IT_CIF_REQCAP-BCAP2 > 0 AND
IT_CIF_REQCAP_X-BCAP2 <> 'X' ).
IT_CIF_REQCAP_X-BCAP1 = 'X'.
IT_CIF_REQCAP_X-BCAP2 = 'X'.
IT_CIF_REQCAP_X-BUNIT = 'X'.
MODIFY IT_CIF_REQCAP_X INDEX SY-TABIX.
ENDIF.
ENDIF.
ENDIF.
ENDLOOP.
***---------------------------------------------------------------------------------------------------------------
-----*
Copyright 2014-2020 : Ambrish Mathur 18
SAP SCM Core Interface Function (CIF) Training SAP SCM-APO Master-data CIF ABAP Enhancements / User-Exits
*** PART-III of the USER-EXIT - For SETUP Activity if Setup Group defined, Set Sequence-Dependent Setup Flag &
Reset Bucket Capacity
***---------------------------------------------------------------------------------------------------------------
-----*
** If Activity Type is of Type SETUP, check if Setup Group/Key is defined and if so, then Set the
** Sequence-Dependent Setup Flag. If Resource in Activity-Mode is "Mixed" reset the Bucket Capacities.
IF IT_CIF_PLANACT-ACTTYPE = 'S'. "BEGIN FOR - SETUP ACTIVITY
* Find if the Setup Group / Setup Key is Populated in the PPM and if so then Set Sequence-Dependent Setup Flag
*** IF IT_CIF_PLANACT-SETUP = ' ' AND "If Sequence Dependent Setup Flag is not Set
IF IT_CIF_PLANACT-ACTTYPE = 'S' AND "If It is a Setup Activity
( /SAPAPO/PLANOPR-SETUP_ID >= 1 OR "If Setup Group defined & Setup Indicator not set, then Set it.
IT_CIF_PLANOPR-SETUP_KEY <> ' ' ). "If Setup Group is coming via CIF for New PPMs - Added 21-4-2011
** Added 21-April-2011 : Check if Setup Key is coming via CIF for New PPMs not yet created in APO
IF IT_CIF_PLANOPR-SETUP_KEY = ' '.
IF /SAPAPO/PLANOPR-SETUP_ID >= 1.
SELECT SINGLE * FROM /SAPAPO/SET_ID WHERE SETUP_ID = /SAPAPO/PLANOPR-SETUP_ID.
ENDIF.
ELSE.
SY-SUBRC = 0. "Since Setup Key is already coming via CIF for New PPMs
ENDIF.
** Added 21-April-2011 : Check if Setup Key is coming via CIF for New PPMs not yet created in APO
IF SY-SUBRC EQ 0. "Is a Valid Setup Group
* Set the Sequence Dependent 'Setup' Flag for the PPM Operation Activity of type Setup where Setup Group is
defined
IT_CIF_PLANACT-SETUP = 'X'.
MODIFY IT_CIF_PLANACT INDEX SY-TABIX.
READ TABLE IT_CIF_PLANACT_X WITH KEY
EXT_PLANNR = IT_CIF_PLANACT-EXT_PLANNR
VORNR = IT_CIF_PLANACT-VORNR
ACTNR = IT_CIF_PLANACT-ACTNR.
IF SY-SUBRC EQ 0.
IT_CIF_PLANACT_X-SETUP = 'X'.
MODIFY IT_CIF_PLANACT_X INDEX SY-TABIX.
Copyright 2014-2020 : Ambrish Mathur 19
SAP SCM Core Interface Function (CIF) Training SAP SCM-APO Master-data CIF ABAP Enhancements / User-Exits
IF SY-SUBRC EQ 0.
* Under the Mode for the Activities when Sequence Dependent Setup has been SET for the Setup Activity ...
* AND if the Resource is of type SINGLE-MIXED Resource which contains BUCKET Capacity, then
* the BUCKET Fixed Duration & Unit on the Primary & Secondary Resource should be Made Blank.
LOOP AT IT_CIF_MODE "Begin of LOOP thru all the PPM Activity Modes
WHERE EXT_PLANNR = IT_CIF_PLANACT-EXT_PLANNR AND
VORNR = IT_CIF_PLANACT-VORNR AND
ACTNR = IT_CIF_PLANACT-ACTNR.
CLEAR : /SAPAPO/RES_HEAD, /SAPAPO/RESKEY.
IF IT_CIF_MODE-RESNAME <> ''.
SELECT SINGLE * FROM /SAPAPO/RES_HEAD WHERE NAME = IT_CIF_MODE-RESNAME AND
SIMVERSID = '000'.
ELSE.
SELECT SINGLE * FROM /SAPAPO/RESKEY WHERE R3KAPID = IT_CIF_MODE-KAPID.
IF SY-SUBRC EQ 0.
SELECT SINGLE * FROM /SAPAPO/RES_HEAD WHERE NAME = /SAPAPO/RESKEY-NAME AND
SIMVERSID = '000'.
ENDIF.
ENDIF.
IF SY-SUBRC EQ 0 AND
( /SAPAPO/RES_HEAD-TYPE = 04 OR "Only Single-Mixed (4) Resources OR
/SAPAPO/RES_HEAD-TYPE = 05 ). "Multi-Mixed(5) Resources have Bucket Capacity
*** /SAPAPO/RES_HEAD-TYPE = 08 ). "Transport(8) Resources also have Bucket Capacity, but
not used in Production
CLEAR : WA_PPMACTMODE_DURVARIABLE, WA_PPMACTMODE_DURUNIT, WA_PPMACTMODE_DURFIXED.
WA_PPMACTMODE_DURVARIABLE = IT_CIF_MODE-DUR1.
WA_PPMACTMODE_DURFIXED = IT_CIF_MODE-DUR2.
WA_PPMACTMODE_DURUNIT = IT_CIF_MODE-UNIT.
LOOP AT IT_CIF_REQCAP "Begin of LOOP thru all the PPM Activity Mode Capacities
WHERE EXT_PLANNR = IT_CIF_MODE-EXT_PLANNR AND
VORNR = IT_CIF_MODE-VORNR AND
ACTNR = IT_CIF_MODE-ACTNR AND
MODUS = IT_CIF_MODE-MODUS.
Copyright 2014-2020 : Ambrish Mathur 20
SAP SCM Core Interface Function (CIF) Training SAP SCM-APO Master-data CIF ABAP Enhancements / User-Exits
*** KAPID = IT_CIF_MODE-KAPID. "Reset Bucket Cap. for Sec.
Resources in Mode too.
*** RESNAME = IT_CIF_MODE-RESNAME. "Reset Bucket Cap. for Sec.
Resources in Mode too.
IF IT_CIF_REQCAP-BCAP2 > 0 OR "If Bucket Capacity is Entered, Reset it
IT_CIF_REQCAP-BUNIT <> ' '.
IT_CIF_REQCAP-BCAP2 = 0. "Make the Bucket Fixed Duration as Zero.
IT_CIF_REQCAP-BCAP1 = 0. "The Bucket VarDur should already be Zero, but make it anyway
IT_CIF_REQCAP-BUNIT = ''. "Initialize the Unit for Bucket Capacity
MODIFY IT_CIF_REQCAP INDEX SY-TABIX.
READ TABLE IT_CIF_REQCAP_X WITH KEY
EXT_PLANNR = IT_CIF_REQCAP-EXT_PLANNR
VORNR = IT_CIF_REQCAP-VORNR
ACTNR = IT_CIF_REQCAP-ACTNR
MODUS = IT_CIF_REQCAP-MODUS
KAPID = IT_CIF_REQCAP-KAPID.
IF SY-SUBRC EQ 0.
IT_CIF_REQCAP_X-BCAP2 = 'X'.
IT_CIF_REQCAP_X-BCAP1 = 'X'.
IT_CIF_REQCAP_X-BUNIT = 'X'.
MODIFY IT_CIF_REQCAP_X INDEX SY-TABIX.
ENDIF.
ENDIF.
ENDLOOP. "End of LOOP thru all the PPM Activity Mode Capacities
ENDIF.
ENDLOOP. "End of LOOP thru all the PPM Activity Modes
ENDIF.
ENDIF.
ENDIF.
ENDIF. "End for Check of Setup Group/Key Defined
ENDIF. "END FOR - SETUP ACTIVITY
Copyright 2014-2020 : Ambrish Mathur 21
SAP SCM Core Interface Function (CIF) Training SAP SCM-APO Master-data CIF ABAP Enhancements / User-Exits
ENDIF.
ENDIF.
ENDIF.
ENDLOOP. "End of LOOP thru all the PPM Activities
*&----------------------------------------------------------------------------------------------------------------
------*
Copyright 2014-2020 : Ambrish Mathur 22
SAP SCM Core Interface Function (CIF) Training SAP SCM-APO Master-data CIF ABAP Enhancements / User-Exits
SAP System : SAP ECC / R3 Server (ERP)
User-Exit Enhancement CMOD : ZAPOPROD , Enhancement : CIFMAT01
ABAP Include : ZXCIFU01 – Modify Products data Outbound from ECC / R3
Flag Procurement Type as ‘P’ (not planned in APO) for Materials sent to APO, but are being Planned in ECC
/ R3 in MRP.
Initialize GR Processing Time field from being sent to SCM-APO for Repetitive Manufacturing Products for
APO-PPDS REM Heuristic.
*&---------------------------------------------------------------------*
*& Include ZXCIFU01
*&---------------------------------------------------------------------*
*& 14-SEP-2010 : CIF UserExit Code put by
* - Ambrish Mathur - Head SAP SCM CoE
*& to ensure CIF Sends Materials not Planned in APO via CIF as Planned
*& Externally (Procurement Type = P). ALso for Repetitive Manufacturing
*& Materials the GR Processing time in Manufacturing Plants should not be
*& sent to SCM-APO for PPDS REM Heuristic which does not support it.
*&---------------------------------------------------------------------*
tables : MARA, MARC, MARM, MKAL, T001W.
DATA : w_tabix type sy-tabix.
LOOP AT CT_CIF_MATLOC.
MOVE SY-TABIX TO W_TABIX.
SELECT SINGLE * FROM MARA WHERE MATNR = CT_CIF_MATLOC-MATNR.
IF SY-SUBRC EQ 0.
** IF ( MARA-MTART = 'FERT' ) OR "Check FG, Semi-FG, Raw, Packing and Configurable Materials only
** ( MARA-MTART = 'HALB' ) OR
** ( MARA-MTART = 'ROH' ) OR
** ( MARA-MTART = 'VERP' ) OR
** ( MARA-MTART = 'KMAT' ).
SELECT SINGLE * FROM MARC WHERE MATNR = CT_CIF_MATLOC-MATNR and
WERKS = CT_CIF_MATLOC-LOCNO.
IF SY-SUBRC EQ 0.
IF MARC-DISMM <> 'X0' OR "If Material is not to be Planned in APO, then Change Procurement Type to P
*** MARC-MMSTA+0(1) = 'Z' OR "Material Blocked for Inventory Movement, Planning and Procurement
Copyright 2014-2020 : Ambrish Mathur 23
SAP SCM Core Interface Function (CIF) Training SAP SCM-APO Master-data CIF ABAP Enhancements / User-Exits
MARC-MMSTA = 'Z1' OR "Material Blocked for Inventory Movement, Planning and Procurement
MARC-MMSTA = 'Z2' OR "Material Blocked for Routing, BOM setup and Planning
MARC-MMSTA = 'Z3' OR "Material Blocked for Inventory Movement
MARC-MMSTA = 'Z5' OR "Material Blocked for Routing, BOM setup
MARC-MMSTA = 'Z7' OR "Material Blocked for Inventory Movement
MARC-MMSTA = '01' OR "Material Blocked for Inventory Movement, Planning and Procurement
MARC-MMSTA = '02'. "Material Blocked for Planning and Planning Master data
* IF ( ( CT_CIF_MATLOC-BESKZ <> '' ) OR ( IT_MARC-BESKZ <> '' ) ).
CT_CIF_MATLOC-BESKZ = 'P'. "If Not Relevant to APO Planning or Material Status Blocked. Set Proc type
to P.
MODIFY CT_CIF_MATLOC INDEX W_TABIX. "Update the Internal MATLOC Table.
READ TABLE CT_CIF_MATLOCX WITH KEY
MATNR = CT_CIF_MATLOC-MATNR
LOCNO = CT_CIF_MATLOC-LOCNO.
IF SY-SUBRC EQ 0.
CT_CIF_MATLOCX-BESKZ = 'X'.
MODIFY CT_CIF_MATLOCX INDEX SY-TABIX.
ENDIF.
* ENDIF.
ELSE.
* Set Procurement Type from Material Master
IF MARC-BESKZ <> ''. "Set Value of Procurement type in ECC/R3 into SCM-APO Product Master
MOVE MARC-BESKZ TO CT_CIF_MATLOC-BESKZ.
MODIFY CT_CIF_MATLOC INDEX W_TABIX. "Update the Internal MATLOC Table.
READ TABLE CT_CIF_MATLOCX WITH KEY
MATNR = CT_CIF_MATLOC-MATNR
LOCNO = CT_CIF_MATLOC-LOCNO.
IF SY-SUBRC EQ 0.
CT_CIF_MATLOCX-BESKZ = 'X'.
MODIFY CT_CIF_MATLOCX INDEX SY-TABIX.
ENDIF.
ENDIF.
* Remove GR Processing time for Repetitive Materials being Planned in APO for PPDS REM Heuristic.
CLEAR T001W.
SELECT SINGLE * FROM T001W WHERE WERKS = CT_CIF_MATLOC-LOCNO.
IF ( MARC-SAUFT = 'X' OR MARC-SFEPR <> '' ) AND "If APO Material with Repetitive Mfg. Remove GR Proc
Time
( T001W-NODETYPE = 'PL' ). "If Node is a Production Plant, then Remove GR Proc. Plant.
Copyright 2014-2020 : Ambrish Mathur 24
SAP SCM Core Interface Function (CIF) Training SAP SCM-APO Master-data CIF ABAP Enhancements / User-Exits
CLEAR CT_CIF_MATLOC-GRPRT. "Value coming from ECC/R3 via CIF is Not Sent to SCM-APO for Repetitive
Mfg. Matls.
MODIFY CT_CIF_MATLOC INDEX W_TABIX. "Update the Internal MATLOC Table.
READ TABLE CT_CIF_MATLOCX WITH KEY
MATNR = CT_CIF_MATLOC-MATNR
LOCNO = CT_CIF_MATLOC-LOCNO.
IF SY-SUBRC EQ 0.
CT_CIF_MATLOCX-BESKZ = 'X'.
CT_CIF_MATLOCX-GRPRT = 'X'.
MODIFY CT_CIF_MATLOCX INDEX SY-TABIX.
ENDIF.
ENDIF.
ENDIF.
ENDIF.
** ENDIF.
ENDIF.
ENDLOOP.
Copyright 2014-2020 : Ambrish Mathur 25
SAP SCM Core Interface Function (CIF) Training SAP SCM-APO Master-data CIF ABAP Enhancements / User-Exits
SAP System : SAP ECC / R3 Server (ERP)
User-Exit Enhancement CMOD : ZAPOPPM , Enhancement : CIFPPM01
ABAP Include : ZXPGSEU01 – Modify PPM data Outbound from ECC / R3
Apply Note 217210 for Transferring Alternate Sequences in Discrete Manufacturing Routings master data as
PPM Modes.
Determine Mode Priorities from Production Versions for Repetitive Manufacturing.
Update Bucket Capacities automatically in APO for Mixed Resources in PPDS PPMs for Planning Production in
SNP.
*&----------------------------------------------------------------------------------------------------------------
------*
*& Include ZXPGSEU01
*&----------------------------------------------------------------------------------------------------------------
------*
*& 16/09/2010 - Ambrish Mathur - Head SCM CoE
*& Applied Note 217210 Applied for Discrete Manufacturing
*& for Transferring Alternate Sequences in Routings (Discrete only).
*&
*& 05/10/2010 - Ambrish Mathur - Head SCM CoE
*& For Repetitive Manufacturing Derive Mode Priorities from PPM
*& Production Version Number (PP01=Mode A, PP02=Mode B, PP03=Mode C ... etc.)
*& Decide based on the Last 2 Characters which are to be NUMBERs.
*& Mode Priorities are from A to O(15), P(16) to Z (26). So PP16 & above are all Priority Z.
*&
*& Code Below also Supports the Production Version Format XXXn where only last n is a Number (e.g :
VER3 = MODE C)
*&
*& - Update the PPM Procurement Priority field as well
*&
*& 23/11/2010 - Update the BUCKET Capacity Update Flags if Bucket Capacities are Populated
*&
*& DEC-2010 or LATER ... to be done via the ECC Outbound PPM User-Exit (not here)
*& Also for RECIPE coming from ECC, we find that the Alternate Resources Mode 2,3
... etc.
*& have the same Line Speeds / Durations as the Mode 1 resource.
*& This is a SAP ECC & APO PPDS Limitation in the CIF (Resource Classification used
in ECC)
Copyright 2014-2020 : Ambrish Mathur 26
SAP SCM Core Interface Function (CIF) Training SAP SCM-APO Master-data CIF ABAP Enhancements / User-Exits
*& Have to Investigate a CIF Userexit to Populate a different Line Speed / Duration
*& for Alternate Resources in the PPM for Process Industry Products
*& A Solution Lies in looking at RECIPES where Alternate Resources are PRIMARY
Resources
*& the Code of this has to be designed still.
*&
*&----------------------------------------------------------------------------------------------------------------
------*
*&
* local data definitions
DATA: LT_MLST LIKE MLSTD OCCURS 0,
LT_PLAB LIKE PLAB OCCURS 0,
LT_PLAS LIKE PLAS OCCURS 0 WITH HEADER LINE,
LT_PLFH LIKE PLFH OCCURS 0,
LT_PLFL LIKE PLFL OCCURS 0 WITH HEADER LINE,
LT_PLFT LIKE PLFT OCCURS 0,
LT_PLFV LIKE PLFV OCCURS 0,
LT_PLKO LIKE PLKO OCCURS 0,
LT_PLMZ LIKE PLMZ OCCURS 0,
LT_PLPO LIKE COPLPO OCCURS 0 WITH HEADER LINE,
LT_PLTX LIKE PLTXD OCCURS 0.
DATA: LT_STD_OPR LIKE COPLPO OCCURS 0 WITH HEADER LINE,
LT_ALT_OPR LIKE COPLPO OCCURS 0 WITH HEADER LINE,
LT_ALT_MODE LIKE CIF_MODE OCCURS 0 WITH HEADER LINE,
LT_ALT_REQCAP LIKE CIF_REQCAP OCCURS 0 WITH HEADER LINE,
LT_CRCA LIKE CRCA OCCURS 0 WITH HEADER LINE,
LS_CRHD LIKE CRHD,
LS_KAKO LIKE KAKO,
L_TABIX LIKE SY-TABIX,
L_TABIX_BEG LIKE SY-TABIX,
L_TABIX_END LIKE SY-TABIX,
L_NUM_STD_OPR TYPE I,
L_NUM_ALT_OPR TYPE I,
L_MODE_NAME LIKE SY-TABIX,
L_SUBRC LIKE SY-SUBRC,
l_quantity like cstmat-bmeng,
L_MODE_PRIORITY LIKE CIF_MODE-MODE_PRIO,
L_PRIO_STRING(16) TYPE C,
L_APO_RELEVANT LIKE RC27X-FLG_SEL,
L_VORNR_CIF LIKE CIF_PLNAC-VORNR_EX,
Copyright 2014-2020 : Ambrish Mathur 27
SAP SCM Core Interface Function (CIF) Training SAP SCM-APO Master-data CIF ABAP Enhancements / User-Exits
L_VORNR_PRE LIKE CIF_PLNAC-VORNR_EX,
L_PLNKN LIKE COPLPO-PLNKN.
DATA: LS_PPMKEY LIKE PPM_KEY.
DATA: BEGIN OF LS_VER_KEY,
MATNR LIKE PPM_KEY-MATNR,
WERKS LIKE PPM_KEY-WERKS,
VERID LIKE PPM_KEY-VERID,
READ_DAY LIKE PPM_KEY-ADATU,
PLNTY LIKE PPM_KEY-PLNTY,
PLNNR LIKE PPM_KEY-PLNNR,
ALNAL LIKE PPM_KEY-ALNAL,
STLAL LIKE PPM_KEY-STLAL,
STLAN LIKE PPM_KEY-STLAN,
END OF LS_VER_KEY.
DATA: BEGIN OF LS_VORNR_EX,
VORNR LIKE PLPO-VORNR,
PLNKN LIKE PLPO-PLNKN,
END OF LS_VORNR_EX.
DATA: LT_CIF_PRODVER LIKE CIF_PRODVR OCCURS 0 WITH HEADER LINE.
DATA: LS_MODEX LIKE CIFMODEX,
LS_REQCAPX LIKE CIFREQCAPX.
TABLES: MARC.
DATA: L_CUOBJ LIKE MARC-CUOBJ,
LV_MARM_UMREN LIKE MARM-UMREN,
LV_MARM_UMREZ LIKE MARM-UMREZ,
LS_PLKO LIKE PLKO,
LS_MARA LIKE MARA,
LS_MARM LIKE MARM.
DATA: WS_VER_NUM TYPE I VALUE 1,
WS_VER_NUM_OFFSET TYPE I VALUE 1,
WS_VER_NUM1 TYPE I VALUE 1,
WS_VER_NUM2 TYPE I VALUE 0,
WS_VER_CHAR1(1) TYPE C,
WS_VER_CHAR2(1) TYPE C,
WS_VER_CHAR(2) TYPE C,
Copyright 2014-2020 : Ambrish Mathur 28
SAP SCM Core Interface Function (CIF) Training SAP SCM-APO Master-data CIF ABAP Enhancements / User-Exits
WS_REM_MODE_PRIO LIKE CIF_MODE-MODE_PRIO.
***-----------------------------------------------------------------------------------------------
* perform creation of alternative modes only once per routing
LT_CIF_PRODVER[] = OUT_CIF_PRODVER[].
SORT LT_CIF_PRODVER BY PLANKEY PPMKEY_EX.
DELETE ADJACENT DUPLICATES FROM LT_CIF_PRODVER
COMPARING PLANKEY PPMKEY_EX.
LOOP AT OUT_CIF_PRODVERZ.
READ TABLE LT_CIF_PRODVER
WITH KEY PPMKEY_EX = OUT_CIF_PRODVERZ-PPMKEY_EX.
CHECK SY-SUBRC IS INITIAL.
* initializations
REFRESH: LT_PLFL, LT_PLAS, LT_PLPO.
L_MODE_NAME = '1'.
L_PRIO_STRING = 'ABCDEFGHIJKLMNOZ'.
LS_VER_KEY = LT_CIF_PRODVER-PPMKEY_EX.
MOVE-CORRESPONDING LS_VER_KEY TO LS_PPMKEY.
READ TABLE out_cif_ppm_key
WITH KEY matnr = ls_ver_key-matnr
werks = ls_ver_key-werks
verid = ls_ver_key-verid
plnty = ls_ver_key-plnty
plnnr = ls_ver_key-plnnr
alnal = ls_ver_key-alnal
stlal = ls_ver_key-stlal
stlan = ls_ver_key-stlan.
check sy-subrc is initial.
ls_ppmkey-sttag = out_cif_ppm_key-sttag.
* determine MARC-CUOBJ for material variants/configuration
SELECT SINGLE CUOBJ FROM MARC INTO L_CUOBJ
WHERE MATNR = LS_PPMKEY-MATNR
AND WERKS = LS_PPMKEY-WERKS.
IF SY-SUBRC <> 0.
CLEAR L_CUOBJ.
ENDIF.
Copyright 2014-2020 : Ambrish Mathur 29
SAP SCM Core Interface Function (CIF) Training SAP SCM-APO Master-data CIF ABAP Enhancements / User-Exits
* re-read routing
CALL FUNCTION 'CP_EX_PLAN_READ'
EXPORTING
PLNTY_IMP = OUT_CIF_PRODVERZ-PLNTY
PLNNR_IMP = OUT_CIF_PRODVERZ-PLNNR
PLNAL_IMP = OUT_CIF_PRODVERZ-ALNAL
CUOBJ_IMP = L_CUOBJ
STTAG_IMP = ls_ppmkey-sttag
TABLES
MLST_EXP = LT_MLST
PLAB_EXP = LT_PLAB
PLAS_EXP = LT_PLAS
PLFH_EXP = LT_PLFH
PLFL_EXP = LT_PLFL
PLFT_EXP = LT_PLFT
PLFV_EXP = LT_PLFV
PLKO_EXP = LT_PLKO
PLMZ_EXP = LT_PLMZ
PLPO_EXP = LT_PLPO
PLTX_EXP = LT_PLTX
EXCEPTIONS
NOT_FOUND = 1
PLNAL_INITIAL = 2
OTHERS = 3.
CHECK SY-SUBRC IS INITIAL.
* when unit of header material is not equal unit of plan,
* then determine ratio of alternative unit of header material.
CLEAR: LV_MARM_UMREN, LV_MARM_UMREZ.
READ TABLE LT_PLKO INTO LS_PLKO INDEX 1.
IF SY-SUBRC = 0.
SELECT SINGLE * FROM MARA INTO LS_MARA
WHERE MATNR = LT_CIF_PRODVER-MATNR.
IF SY-SUBRC = 0 AND
LS_MARA-MEINS <> LS_PLKO-PLNME.
* Read ratio of alternative unit of header material
SELECT SINGLE * FROM MARM INTO LS_MARM
WHERE MATNR = LT_CIF_PRODVER-MATNR
AND MEINH = LS_PLKO-PLNME.
IF SY-SUBRC = 0 AND
Copyright 2014-2020 : Ambrish Mathur 30
SAP SCM Core Interface Function (CIF) Training SAP SCM-APO Master-data CIF ABAP Enhancements / User-Exits
NOT LS_MARM-UMREZ IS INITIAL AND
NOT LS_MARM-UMREN IS INITIAL.
LV_MARM_UMREN = LS_MARM-UMREN.
LV_MARM_UMREZ = LS_MARM-UMREZ.
ENDIF.
ENDIF.
ENDIF.
***-----------------------------------------------------------------------------------------------
*** Part-I - Code Added for Repetitive Manufacturing for Determing PPM Mode Priorities from Production Version
*** of type XXnn where the Last 2 Characters of the Version are Numeric = 01 to 99 (ASSUMPTION).
*** It is Assumed that PVer01 = Mode A, PVer 02 = Mode B, PVer03 = Mode C ... PVer16-99 = Mode Z.
***-----------------------------------------------------------------------------------------------
IF OUT_CIF_PRODVERZ-PLNTY = 'R'. "BEGIN - If PPM from Repetive Manufacturing
CLEAR : WS_VER_NUM, WS_VER_NUM_OFFSET, WS_VER_CHAR, WS_REM_MODE_PRIO,
WS_VER_CHAR1, WS_VER_CHAR2, WS_VER_NUM1, WS_VER_NUM2.
*** Assumption = Last 2 Characters of Production Version Number is Numeric & Version Priority = Mode Priority.
*** Check the Assumption FIRST. If Assumption is not Met then Exit.
WS_VER_CHAR1 = OUT_CIF_PRODVERZ-VERID+3(1). "First Read the Last Character of PV
WS_VER_CHAR2 = OUT_CIF_PRODVERZ-VERID+2(1). "Second Read the 2nd Last Character of PV
WS_VER_NUM1 = 0.
WS_VER_NUM2 = 0.
IF WS_VER_CHAR1 >= '1' AND WS_VER_CHAR1 <= '9'.
WS_VER_NUM1 = WS_VER_CHAR1. "Convert Last Character to a 1-digit Number
ENDIF.
IF WS_VER_CHAR2 >= '1' AND WS_VER_CHAR2 <= '9'.
WS_VER_NUM2 = WS_VER_CHAR2. "Convert 2nd Last Character to a 1-digit Number
ELSE.
WS_VER_NUM2 = 0.
ENDIF.
IF WS_VER_NUM1 >= 1 AND WS_VER_NUM1 <= 9. "Check the Last Character of PV is a Number.
*** ( WS_VER_NUM2 >= 0 AND WS_VER_NUM2 <= 9 ). "Check the 2nd Last Character of PV is a Number.
IF WS_VER_NUM2 > 0 AND WS_VER_NUM2 <= 9.
WS_VER_CHAR = OUT_CIF_PRODVERZ-VERID+2(2). "Read the Last 2 Characters of the Production Version
ELSE.
WS_VER_CHAR = OUT_CIF_PRODVERZ-VERID+3(1). "Read the Last 1 Characters of the Production Version
ENDIF.
WS_VER_NUM = WS_VER_CHAR. "Convert Last 2 Characters of PV to a 2-digit Number
IF WS_VER_NUM < 01.
Copyright 2014-2020 : Ambrish Mathur 31
SAP SCM Core Interface Function (CIF) Training SAP SCM-APO Master-data CIF ABAP Enhancements / User-Exits
WS_VER_NUM = 01.
ENDIF.
IF WS_VER_NUM > 16.
WS_VER_NUM = 16.
ENDIF.
WS_VER_NUM_OFFSET = WS_VER_NUM - 1.
WS_REM_MODE_PRIO = L_PRIO_STRING+WS_VER_NUM_OFFSET(1). "Read Mode Priority from 16 Chars String = A-O,Z
IF WS_REM_MODE_PRIO < 'A'.
WS_REM_MODE_PRIO = 'A'.
ENDIF.
IF WS_REM_MODE_PRIO > 'Z'.
WS_REM_MODE_PRIO = 'Z'.
ENDIF.
**
** BREAK-POINT ID AMBRISH.
**
READ TABLE OUT_CIF_PRODVER WITH KEY
PPMKEY_EX = OUT_CIF_PRODVERZ-PPMKEY_EX.
IF SY-SUBRC EQ 0.
*** Update Mode Priority
LOOP AT OUT_CIF_MODE WHERE PLANKEY_EX = OUT_CIF_PRODVER-PLANKEY.
IF OUT_CIF_MODE-MODE_PRIO <> WS_REM_MODE_PRIO. "Modify only 2nd Version onwards. 1st Version will
be 'A' already.
OUT_CIF_MODE-MODE_PRIO = WS_REM_MODE_PRIO.
MODIFY OUT_CIF_MODE INDEX SY-TABIX.
READ TABLE OUT_CIF_MODEX WITH KEY
PLANKEY_EX = OUT_CIF_MODE-PLANKEY_EX
VORNR_EX = OUT_CIF_MODE-VORNR_EX
AKTNR_EX = OUT_CIF_MODE-AKTNR_EX
METHOD = OUT_CIF_MODE-METHOD
MODUS = OUT_CIF_MODE-MODUS.
IF SY-SUBRC EQ 0.
OUT_CIF_MODEX-MODE_PRIO = 'X'.
MODIFY OUT_CIF_MODEX INDEX SY-TABIX.
ENDIF.
ENDIF.
ENDLOOP.
*** Update PPM Product Procurement Priority.
Copyright 2014-2020 : Ambrish Mathur 32
SAP SCM Core Interface Function (CIF) Training SAP SCM-APO Master-data CIF ABAP Enhancements / User-Exits
LOOP AT OUT_CIF_TRPROD WHERE
EXT_PLANNR = OUT_CIF_PRODVER-PLANKEY AND
MATNR = OUT_CIF_PRODVER-MATNR AND
LOCNOTO = OUT_CIF_PRODVER-LOCNO.
IF NOT OUT_CIF_TRPROD-SPRIO > 0. "Modify only 2nd Version onwards. 1st Version will be 'A' already.
OUT_CIF_TRPROD-SPRIO = WS_VER_NUM.
MODIFY OUT_CIF_TRPROD INDEX SY-TABIX.
READ TABLE OUT_CIF_TRPRODX WITH KEY
TR_NAME = OUT_CIF_TRPROD-TR_NAME
METHOD = OUT_CIF_TRPROD-METHOD.
* EXT_PLANNR = OUT_CIF_TRPROD-EXT_PLANNR
* MATNR = OUT_CIF_TRPROD-MATNR
* LOCNO = OUT_CIF_MODE-LOCNO.
IF SY-SUBRC EQ 0.
OUT_CIF_TRPRODX-SPRIO = 'X'.
MODIFY OUT_CIF_TRPRODX INDEX SY-TABIX.
ENDIF.
ENDIF.
ENDLOOP.
ENDIF.
ENDIF.
ENDIF. "END - If PPM from Repetive Manufacturing
***-----------------------------------------------------------------------------------------------
***-----------------------------------------------------------------------------------------------
*** Part-II - Code for Discrete Manufacturing for Alternate Sequences Continues below.
***-----------------------------------------------------------------------------------------------
* no need for the following tables
REFRESH: LT_MLST, LT_PLAB, LT_PLFH, LT_PLFT,
LT_PLFV, LT_PLMZ, LT_PLTX, LT_PLKO.
* check if any alternative sequence exists in current routing
READ TABLE LT_PLFL WITH KEY FLGAT = '2'.
CHECK SY-SUBRC IS INITIAL.
* get basic quantity of BOM
perform base_quan_get_bom using ls_ppmkey
changing l_quantity.
Copyright 2014-2020 : Ambrish Mathur 33
SAP SCM Core Interface Function (CIF) Training SAP SCM-APO Master-data CIF ABAP Enhancements / User-Exits
* globalize base quantity in function group PGS1
perform cif_cstmat_set(saplpgs1) using l_quantity.
* get all operations of standard sequence of current routing
PERFORM GET_STANDARD_SEQUENCE TABLES LT_PLFL
LT_PLAS
LT_PLPO
OUT_CIF_PLANOPR
LT_STD_OPR
USING LT_CIF_PRODVER-PLANKEY.
*----------------------------------------------------------------------*
* process alternative sequences for current routing
*----------------------------------------------------------------------*
SORT LT_PLFL BY PLNFL.
LOOP AT LT_PLFL WHERE FLGAT = '2'.
* intializations
CLEAR: L_TABIX_BEG,
L_TABIX_END,
L_TABIX,
L_NUM_STD_OPR,
L_VORNR_PRE.
REFRESH: LT_ALT_OPR,
LT_ALT_MODE,
LT_ALT_REQCAP.
* same modus name per alternative sequence for modus coupling
L_MODE_NAME = L_MODE_NAME + 1.
* check if branch and return operations of the current alternative
* sequence still exist within the standard sequence
IF NOT LT_PLFL-BKNT1 IS INITIAL.
READ TABLE LT_STD_OPR WITH KEY PLNTY = LT_PLFL-PLNTY
PLNNR = LT_PLFL-PLNNR
PLNKN = LT_PLFL-BKNT1.
CHECK SY-SUBRC IS INITIAL.
L_TABIX_BEG = SY-TABIX.
ELSE.
* if bknt1 is initial -> first operation
L_TABIX_BEG = 1.
Copyright 2014-2020 : Ambrish Mathur 34
SAP SCM Core Interface Function (CIF) Training SAP SCM-APO Master-data CIF ABAP Enhancements / User-Exits
ENDIF.
READ TABLE LT_STD_OPR WITH KEY PLNTY = LT_PLFL-PLNTY
PLNNR = LT_PLFL-PLNNR
PLNKN = LT_PLFL-BKNT2.
CHECK SY-SUBRC IS INITIAL.
L_TABIX_END = SY-TABIX.
* calculate number of operations spanned by alternative sequence
L_NUM_STD_OPR = L_TABIX_END - L_TABIX_BEG + 1.
* get all operations within alternative sequences
LOOP AT LT_PLAS WHERE PLNTY = LT_PLFL-PLNTY
AND PLNNR = LT_PLFL-PLNNR
AND PLNAL = LT_PLFL-PLNAL
AND PLNFL = LT_PLFL-PLNFL.
READ TABLE LT_PLPO WITH KEY PLNTY = LT_PLAS-PLNTY
PLNNR = LT_PLAS-PLNNR
PLNKN = LT_PLAS-PLNKN.
CHECK SY-SUBRC IS INITIAL.
* check if operation is APO relevant
PERFORM OPR_CHECK_APO_RELEVANT USING LT_PLPO
CHANGING L_APO_RELEVANT.
IF L_APO_RELEVANT = 'X'.
* collect operations of alternative sequence
APPEND LT_PLPO TO LT_ALT_OPR.
ENDIF.
ENDLOOP. " at lt_plas
DESCRIBE TABLE LT_ALT_OPR LINES L_NUM_ALT_OPR.
* check if number of operations within alternative sequence equals
* number of operations withins standard sequence spanned by alt.seq.
CHECK L_NUM_ALT_OPR = L_NUM_STD_OPR.
* when referenced standard routing is set then the number of task
* list node is replaced by referenced node and the referenced
* node is replaced by task list node to determine the relationship.
clear l_plnkn.
LOOP AT LT_ALT_OPR WHERE NOT refkn IS INITIAL.
l_plnkn = lt_alt_opr-plnkn.
lt_alt_opr-plnkn = lt_alt_opr-refkn.
Copyright 2014-2020 : Ambrish Mathur 35
SAP SCM Core Interface Function (CIF) Training SAP SCM-APO Master-data CIF ABAP Enhancements / User-Exits
lt_alt_opr-refkn = l_plnkn.
modify lt_alt_opr.
ENDLOOP.
* create modes for each operation within alternative sequence
SORT LT_ALT_OPR BY VORNR.
L_TABIX = L_TABIX_BEG.
LOOP AT LT_ALT_OPR.
* read workcenter
REFRESH LT_CRCA.
PERFORM CIF_WORKCENTER_INFO_READ(SAPLPGS1)
TABLES LT_CRCA
USING LT_ALT_OPR-ARBID
LS_PPMKEY
LT_ALT_OPR
CHANGING LS_CRHD
LS_KAKO.
* get corresponding operation of standard sequence
READ TABLE LT_STD_OPR INDEX L_TABIX.
CHECK SY-SUBRC IS INITIAL.
LS_VORNR_EX-VORNR = LT_STD_OPR-VORNR.
LS_VORNR_EX-PLNKN = LT_STD_OPR-PLNKN.
* when referenced standard routing is set then the number of
* referenced node is taken to read the valid activity.
IF NOT LT_STD_OPR-REFKN IS INITIAL.
LS_VORNR_EX-PLNKN = LT_STD_OPR-REFKN.
ENDIF.
L_VORNR_CIF = LS_VORNR_EX.
* create alternative modes for each activity
LOOP AT OUT_CIF_PLANACT
WHERE PLANKEY_EX = LT_CIF_PRODVER-PLANKEY
AND VORNR_EX = L_VORNR_CIF.
* initializations
CLEAR L_SUBRC.
* create mode and reqcaps
PERFORM CIF_MODE_CREATE(SAPLPGS1)
TABLES LT_ALT_MODE
LT_ALT_REQCAP
LT_CRCA
Copyright 2014-2020 : Ambrish Mathur 36
SAP SCM Core Interface Function (CIF) Training SAP SCM-APO Master-data CIF ABAP Enhancements / User-Exits
USING
LT_ALT_OPR
OUT_CIF_PLANACT
L_MODE_NAME
CHANGING LS_CRHD
LS_KAKO
L_SUBRC.
* if any mode could not be created cancel the whole sequence !
IF NOT L_SUBRC IS INITIAL.
REFRESH: LT_ALT_MODE,
LT_ALT_REQCAP.
EXIT.
ENDIF.
ENDLOOP. " at out_cif_planact
IF NOT L_SUBRC IS INITIAL.
EXIT.
ENDIF.
* create modus coupling for activities between operations
* within an alternative sequence
IF NOT L_VORNR_PRE IS INITIAL.
* a predecessor operation exists within alternative sequence
* -> create modus coupling
READ TABLE OUT_CIF_ACTREL
WITH KEY PLKEY_EX_P = LT_CIF_PRODVER-PLANKEY
OPKEY_EX_P = L_VORNR_PRE
PLKEY_EX_S = LT_CIF_PRODVER-PLANKEY
OPKEY_EX_S = L_VORNR_CIF.
IF SY-SUBRC IS INITIAL.
OUT_CIF_ACTREL-MODE_REL_T = 3.
MODIFY OUT_CIF_ACTREL INDEX SY-TABIX.
ENDIF.
ENDIF.
L_TABIX = L_TABIX + 1.
L_VORNR_PRE = L_VORNR_CIF.
ENDLOOP. " at lt_alt_opr
IF NOT L_SUBRC IS INITIAL.
CONTINUE.
ENDIF.
Copyright 2014-2020 : Ambrish Mathur 37
SAP SCM Core Interface Function (CIF) Training SAP SCM-APO Master-data CIF ABAP Enhancements / User-Exits
* modify priority of mode depending on current sequence
SHIFT L_PRIO_STRING.
L_MODE_PRIORITY = L_PRIO_STRING.
* when the number of alternate sequences greather than 15,
* then the priotity is always set equal 'Z' as very low priority
* for the all alternate sequences greather than 15.
IF L_MODE_PRIORITY IS INITIAL.
L_MODE_PRIORITY = 'Z'.
ENDIF.
LOOP AT LT_ALT_MODE.
LT_ALT_MODE-MODE_PRIO = L_MODE_PRIORITY.
* determinate variable duration when MARM-UMREN and MARM-UMREN
* not equal ZERO.
IF NOT LV_MARM_UMREN IS INITIAL AND
NOT LV_MARM_UMREZ IS INITIAL.
LT_ALT_MODE-DUR1 = LT_ALT_MODE-DUR1 *
LV_MARM_UMREN / LV_MARM_UMREZ.
ENDIF.
MODIFY LT_ALT_MODE.
PERFORM FILL_MODE_X(SAPLPGSX) USING LT_ALT_MODE
CHANGING LS_MODEX.
APPEND LS_MODEX TO OUT_CIF_MODEX.
ENDLOOP.
LOOP AT LT_ALT_REQCAP.
PERFORM FILL_REQCAP_X(SAPLPGSX) USING LT_ALT_REQCAP
CHANGING LS_REQCAPX.
APPEND LS_REQCAPX TO OUT_CIF_REQCAPX.
ENDLOOP.
* finally append modes and reqcaps to exported APO tables
APPEND LINES OF LT_ALT_MODE TO OUT_CIF_MODE.
APPEND LINES OF LT_ALT_REQCAP TO OUT_CIF_REQCAP.
ENDLOOP. " at lt_plfl
ENDLOOP. " at lt_cif_prodverz
***---------------------------------------------------------------------------------------------------------------
-----*
*** PART-III - Set the Bucket Capacities Update Flag - For Secondary Resources in MODES based on Calculated Values
Copyright 2014-2020 : Ambrish Mathur 38
SAP SCM Core Interface Function (CIF) Training SAP SCM-APO Master-data CIF ABAP Enhancements / User-Exits
*** This is needed because Form FILL_REQCAP_X above does not update it. Code below does exactly that.
***---------------------------------------------------------------------------------------------------------------
-----*
LOOP AT OUT_CIF_REQCAP.
IF OUT_CIF_REQCAP-BCAP1 > 0 OR
OUT_CIF_REQCAP-BCAP2 > 0.
READ TABLE OUT_CIF_REQCAPX WITH KEY
PLANKEY_EX = OUT_CIF_REQCAP-PLANKEY_EX
VORNR_EX = OUT_CIF_REQCAP-VORNR_EX
AKTNR_EX = OUT_CIF_REQCAP-AKTNR_EX
MODUS = OUT_CIF_REQCAP-MODUS
KAPID = OUT_CIF_REQCAP-KAPID.
IF SY-SUBRC EQ 0.
IF ( OUT_CIF_REQCAP-BCAP1 > 0 AND
OUT_CIF_REQCAPX-BCAP1 <> 'X' ) OR
( OUT_CIF_REQCAP-BCAP2 > 0 AND
OUT_CIF_REQCAPX-BCAP2 <> 'X' ).
OUT_CIF_REQCAPX-BCAP1 = 'X'.
OUT_CIF_REQCAPX-BCAP2 = 'X'.
OUT_CIF_REQCAPX-BUNIT = 'X'.
MODIFY OUT_CIF_REQCAPX INDEX SY-TABIX.
ENDIF.
ENDIF.
ENDIF.
ENDLOOP.
Copyright 2014-2020 : Ambrish Mathur 39
SAP SCM Core Interface Function (CIF) Training SAP SCM-APO Master-data CIF ABAP Enhancements / User-Exits
SAP System : SAP ECC / R3 Server (ERP)
User-Exit Enhancement CMOD : ZAPOPPM , Enhancement : CIFPPM01
ABAP Include : ZXPGSEU03 – Modify PPM data Outbound from ECC / R3
Calculate Bucket Capacities automatically in APO for Mixed Resources in PPDS PPMs for Planning Production
in SNP.
*&----------------------------------------------------------------------------------------------------------------
------*
*& Include ZXPGSEU03
*&----------------------------------------------------------------------------------------------------------------
------*
*& 23/11/2010 - Ambrish Mathur - Head SAP SCM Solutions and Delivery
*& For Alternate Modes of Routing / Recipe coming from ECC, we find that the
*& the BUCKET durations of MODE B, C, D ... for the Resources the Variable and Fixed
*& BUCKET durations are not Populated. This User-Exit will Populate those Fields.
*& - Logic has been put to Convert Routing Operation Quantity into the UOM of BOM Base Quantity
*&----------------------------------------------------------------------------------------------------------------
------*
TABLES : CRHD, CRCA, KAKO, MAPL, PLKO, PLAS, PLPO, MKAL, MAST, STKO, STPO.
DATA: T_BMSCH TYPE PLKO-BMSCH,
W_BMSCH TYPE PLKO-BMSCH.
** AMBRISH - If Bucket Capacities are Already Populated - Exit this Logic.
IF C_CIF_REQCAP-BCAP1 > 0 OR
C_CIF_REQCAP-BCAP2 > 0.
EXIT.
RETURN.
ENDIF.
* Get the base quantity.
IF NOT I_PLPO IS INITIAL.
W_BMSCH = 0.
W_BMSCH = I_PLPO-BMSCH.
IF I_PLPO-UMREN > 0.
Copyright 2014-2020 : Ambrish Mathur 40
SAP SCM Core Interface Function (CIF) Training SAP SCM-APO Master-data CIF ABAP Enhancements / User-Exits
W_BMSCH = I_PLPO-BMSCH * I_PLPO-UMREZ / I_PLPO-UMREN. "Convert Operation Quantity to Routing Base Quantity
ENDIF.
** AMBRISH : Find BOM Base Quantity from Routing and Production Version to BOM Master
T_BMSCH = 0.
SELECT SINGLE * FROM PLAS
WHERE PLNTY = I_PLPO-PLNTY
AND PLNNR = I_PLPO-PLNNR
AND PLNKN = I_PLPO-PLNKN
AND ZAEHL = I_PLPO-ZAEHL.
IF SY-SUBRC EQ 0.
SELECT SINGLE * FROM PLKO
WHERE PLNTY = PLAS-PLNTY
AND PLNNR = PLAS-PLNNR
AND PLNAL = PLAS-PLNAL
AND WERKS = I_PLPO-WERKS.
IF SY-SUBRC EQ 0.
IF PLKO-UMREN > 0.
W_BMSCH = W_BMSCH * PLKO-UMREZ / PLKO-UMREN. "Convert Operation Quantity to Material & BOM Base
Quantity
ENDIF.
SELECT SINGLE * FROM MKAL
WHERE PLNTY = PLAS-PLNTY
AND PLNNR = PLAS-PLNNR
AND ALNAL = PLAS-PLNAL
AND WERKS = I_PLPO-WERKS
AND ADATU <= SY-DATUM
AND BDATU >= SY-DATUM.
IF SY-SUBRC EQ 0.
SELECT SINGLE * FROM MAST
WHERE MATNR = MKAL-MATNR
AND WERKS = MKAL-WERKS
AND STLAL = MKAL-STLAL
AND STLAN = MKAL-STLAN.
IF SY-SUBRC EQ 0.
SELECT SINGLE * FROM STKO
WHERE STLTY = 'M'
AND STLNR = MAST-STLNR
AND STLAL = MAST-STLAL.
Copyright 2014-2020 : Ambrish Mathur 41
SAP SCM Core Interface Function (CIF) Training SAP SCM-APO Master-data CIF ABAP Enhancements / User-Exits
*** AND DATUV >= SY-DATUM.
IF SY-SUBRC EQ 0.
*** IF I_PLPO-MEINH = STKO-BMEIN. "Assume Routing UOM, Operation UOM and BOM Base UOM are all Same. If not
Conversion Logic is needed.
T_BMSCH = STKO-BMENG. "BOM Base Quantity is in Material Base UOM
*** ENDIF.
ENDIF.
ENDIF.
ENDIF.
ENDIF.
ENDIF.
** AMBRISH : Hardcoded the Base Quantity to 1000 if BOM could not be found from Production Version.
IF T_BMSCH <= 0.
T_BMSCH = 1000. "Assumes Routing UOM, Operation UOM and BOM Base UOM are all Same. If not Conversion Logic is
needed.
ENDIF.
IF SY-SUBRC EQ 0 AND
W_BMSCH > 0.
IF ( I_PLPO-VGW01 > 0 ) OR
( I_PLPO-VGW02 > 0 ) OR
( I_PLPO-VGW03 > 0 ).
CLEAR : C_CIF_REQCAP-BCAP1, C_CIF_REQCAP-BCAP2, C_CIF_REQCAP-BUNIT.
** AM ** If Setup is defined Calculate Fixed Bucket Capacity
IF I_PLPO-VGW01 > 0 AND
I_PLANACT-ACTTYPE = 'S'.
** AM VGW01 is Setup hence is Fixed Consumption
C_CIF_REQCAP-BCAP2 = I_PLPO-VGW01. "For Setup Activity Duration is not Dependent on Base Quantity
C_CIF_REQCAP-BUNIT = I_PLPO-VGE01.
** AM
ENDIF.
** AM ** Read Capacity and Work Center Details
IF I_PLANACT-ACTTYPE = 'P'.
Copyright 2014-2020 : Ambrish Mathur 42
SAP SCM Core Interface Function (CIF) Training SAP SCM-APO Master-data CIF ABAP Enhancements / User-Exits
SELECT SINGLE * FROM KAKO WHERE KAPID = C_CIF_REQCAP-KAPID.
IF SY-SUBRC EQ 0.
SELECT SINGLE * FROM CRCA WHERE KAPID = KAKO-KAPID.
IF SY-SUBRC EQ 0.
SELECT SINGLE * FROM CRHD WHERE OBJTY = CRCA-OBJTY AND
OBJID = CRCA-OBJID.
ENDIF.
** AM ** Depending on Capacity Category Calculate Variable Bucket Capacity for Machine or Person/Labour
IF KAKO-KAPAR EQ '001'. "If Capacity Category is MACHINE
C_CIF_REQCAP-BCAP1 = ( I_PLPO-VGW02 * T_BMSCH / W_BMSCH ). "Assume Operation Quantity has been
Converted to BOM Base Quantity UOM
C_CIF_REQCAP-BUNIT = I_PLPO-VGE02.
ENDIF.
IF KAKO-KAPAR EQ '002'. "If Capacity Category is PERSON / LABOUR
C_CIF_REQCAP-BCAP1 = ( I_PLPO-VGW03 * T_BMSCH / W_BMSCH ). "Assume Operation Quantity has been
Converted to BOM Base Quantity UOM
C_CIF_REQCAP-BUNIT = I_PLPO-VGE03.
ENDIF.
ENDIF.
ENDIF.
ENDIF.
ENDIF.
ENDIF.
Copyright 2014-2020 : Ambrish Mathur 43
SAP SCM Core Interface Function (CIF) Training SAP SCM-APO Master-data CIF ABAP Enhancements / User-Exits
SAP System : SAP ECC / R3 Server (ERP)
User-Exit Enhancement CMOD : ZAPOPROD , Enhancement : CIFMAT02
ABAP Include : ZXCIFU26 – Modify Products data Outbound from ECC / R3
Flag Procurement Type as ‘P’ (not planned in APO) for Materials sent to APO, but are being Planned in ECC
/ R3 in MRP.
Initialize GR Processing Time field from being sent to SCM-APO for Repetitive Manufacturing Products for
APO-PPDS REM Heuristic.
*&---------------------------------------------------------------------*
*& Include ZXCIFU26
*&---------------------------------------------------------------------*
*& 14-SEP-2010 : CIF UserExit Code put by
* - Ambrish Mathur - Head SAP SCM CoE
*& to ensure CIF Sends Materials not Planned in APO via CIF as Planned
*& Externally (Procurement Type = P). ALso for Repetitive Manufacturing
*& Materials the GR Processing time in Manufacturing Plants should not be
*& sent to SCM-APO for PPDS REM Heuristic which does not support it.
*&---------------------------------------------------------------------*
* tables : MARA, MARC, MARM, MKAL, T001W.
DATA : w_tabix type sy-tabix.
LOOP AT CT_CIF_MATLOC.
MOVE SY-TABIX TO W_TABIX.
SELECT SINGLE * FROM MARA WHERE MATNR = CT_CIF_MATLOC-MATNR.
IF SY-SUBRC EQ 0.
** IF ( MARA-MTART = 'FERT' ) OR "Check FG, Semi-FG, Raw, Packing and Configurable Materials only
** ( MARA-MTART = 'HALB' ) OR
** ( MARA-MTART = 'ROH' ) OR
** ( MARA-MTART = 'VERP' ) OR
** ( MARA-MTART = 'KMAT' ).
SELECT SINGLE * FROM MARC WHERE MATNR = CT_CIF_MATLOC-MATNR and
WERKS = CT_CIF_MATLOC-LOCNO.
IF SY-SUBRC EQ 0.
IF MARC-DISMM <> 'X0' OR "If Material is not to be Planned in APO, then Change Procurement Type to P
*** MARC-MMSTA+0(1) = 'Z' OR "Material Blocked for Inventory Movement, Planning and Procurement
Copyright 2014-2020 : Ambrish Mathur 44
SAP SCM Core Interface Function (CIF) Training SAP SCM-APO Master-data CIF ABAP Enhancements / User-Exits
MARC-MMSTA = 'Z1' OR "Material Blocked for Inventory Movement, Planning and Procurement
MARC-MMSTA = 'Z2' OR "Material Blocked for Routing, BOM setup and Planning
MARC-MMSTA = 'Z3' OR "Material Blocked for Inventory Movement
MARC-MMSTA = 'Z5' OR "Material Blocked for Routing, BOM setup
MARC-MMSTA = 'Z7' OR "Material Blocked for Inventory Movement
MARC-MMSTA = '01' OR "Material Blocked for Inventory Movement, Planning and Procurement
MARC-MMSTA = '02'. "Material Blocked for Planning and Planning Master data
* IF ( ( CT_CIF_MATLOC-BESKZ <> '' ) OR ( IT_MARC-BESKZ <> '' ) ).
CT_CIF_MATLOC-BESKZ = 'P'. "If Not Relevant to APO Planning or Material Status Blocked. Set Proc type
to P.
MODIFY CT_CIF_MATLOC INDEX W_TABIX. "Update the Internal MATLOC Table.
READ TABLE CT_CIF_MATLOCX WITH KEY
MATNR = CT_CIF_MATLOC-MATNR
LOCNO = CT_CIF_MATLOC-LOCNO.
IF SY-SUBRC EQ 0.
CT_CIF_MATLOCX-BESKZ = 'X'.
MODIFY CT_CIF_MATLOCX INDEX SY-TABIX.
ENDIF.
* ENDIF.
ELSE.
* Set Procurement Type from Material Master
IF MARC-BESKZ <> ''. "Set Value of Procurement type in ECC/R3 into SCM-APO Product Master
MOVE MARC-BESKZ TO CT_CIF_MATLOC-BESKZ.
MODIFY CT_CIF_MATLOC INDEX W_TABIX. "Update the Internal MATLOC Table.
READ TABLE CT_CIF_MATLOCX WITH KEY
MATNR = CT_CIF_MATLOC-MATNR
LOCNO = CT_CIF_MATLOC-LOCNO.
IF SY-SUBRC EQ 0.
CT_CIF_MATLOCX-BESKZ = 'X'.
MODIFY CT_CIF_MATLOCX INDEX SY-TABIX.
ENDIF.
ENDIF.
* Remove GR Processing time for Repetitive Materials being Planned in APO for PPDS REM Heuristic.
CLEAR T001W.
SELECT SINGLE * FROM T001W WHERE WERKS = CT_CIF_MATLOC-LOCNO.
IF ( MARC-SAUFT = 'X' OR MARC-SFEPR <> '' ) AND "If APO Material with Repetitive Mfg. Remove GR Proc
Time
( T001W-NODETYPE = 'PL' ). "If Node is a Production Plant, then Remove GR Proc. Plant.
Copyright 2014-2020 : Ambrish Mathur 45
SAP SCM Core Interface Function (CIF) Training SAP SCM-APO Master-data CIF ABAP Enhancements / User-Exits
CLEAR CT_CIF_MATLOC-GRPRT. "Value coming from ECC/R3 via CIF is Not Sent to SCM-APO for Repetitive
Mfg. Matls.
MODIFY CT_CIF_MATLOC INDEX W_TABIX. "Update the Internal MATLOC Table.
READ TABLE CT_CIF_MATLOCX WITH KEY
MATNR = CT_CIF_MATLOC-MATNR
LOCNO = CT_CIF_MATLOC-LOCNO.
IF SY-SUBRC EQ 0.
CT_CIF_MATLOCX-BESKZ = 'X'.
CT_CIF_MATLOCX-GRPRT = 'X'.
MODIFY CT_CIF_MATLOCX INDEX SY-TABIX.
ENDIF.
ENDIF.
ENDIF.
ENDIF.
** ENDIF.
ENDIF.
ENDLOOP.
Copyright 2014-2020 : Ambrish Mathur 46
SAP SCM Core Interface Function (CIF) Training SAP SCM-APO Master-data CIF ABAP Enhancements / User-Exits
SAP System : SAP ECC / R3 Server (ERP)
User-Exit Enhancement CMOD : ZAPOSTCK , Enhancement : CIFSTK01
ABAP Include : ZXCIFU13 – Modify Stock data Outbound from ECC / R3 to SCM-APO
Custom Table ZGATPEXCLSTORLOC - has Records that contain Plant-Storage Locations of Material Types for
which Stock is NOT to be transferred from ECC/R3 to SCM-APO. This is Maintained Manually via Transaction
SM31. The Structure of the Table is shown below.
Stock Data for these Excluded Storage Locations-Material Type is NOT to be transferred via CIF from
ECC/R3 to SCM-APO. This Functionality is needed for ATP Checks in GATP to exclude certain Storage
Locations and Material Type’s with Unrestricted Stock and Quality Inspection Stock in them to be not
taken into account by ATP Check (Standard behavior of GATP is to include all UR and QI Stock, but Blocked
Stock is excluded). This Code below will exclude the Storage Location if Plant-Storage Location-Material
Type Record defined in above Table. In case the Material Group is also maintained in the Table which is
a Non-Key field, then only Stock of Material of that Material Group within the Storage-Location and
Material Type will not be transferred to SCM-APO, however if the Material Group is BLANK then Stock of
all the Materials within that Material Type for that Storage Location will not be transferred.
Copyright 2014-2020 : Ambrish Mathur 47
SAP SCM Core Interface Function (CIF) Training SAP SCM-APO Master-data CIF ABAP Enhancements / User-Exits
Copyright 2014-2020 : Ambrish Mathur 48
SAP SCM Core Interface Function (CIF) Training SAP SCM-APO Master-data CIF ABAP Enhancements / User-Exits
Copyright 2014-2020 : Ambrish Mathur 49
SAP SCM Core Interface Function (CIF) Training SAP SCM-APO Master-data CIF ABAP Enhancements / User-Exits
Copyright 2014-2020 : Ambrish Mathur 50
SAP SCM Core Interface Function (CIF) Training SAP SCM-APO Master-data CIF ABAP Enhancements / User-Exits
Copyright 2014-2020 : Ambrish Mathur 51
SAP SCM Core Interface Function (CIF) Training SAP SCM-APO Master-data CIF ABAP Enhancements / User-Exits
*&-------------------------------------------------------------------------------*
*& Include ZXCIFU13
*&-------------------------------------------------------------------------------*
*& 08-OCT-2012 : CIF UserExit Code for CMOD - ZAPOSTCK - Coed put by User
* -Ambrish Mathur-Head SAP SCM-APO Solutions CoE
*& to Limit the Transfer of Stock for some Storage Locations
*& containing Unrestricted Stock (UR) to SCM-APO for
*& SCM Planning and ATP Check in GATP as the Stock Represents
*& Stock for Re-work and the Business Process in the Customer
*& does not store that as BLOCKED Stock but UR Stock.
*& The Plant-Storage Locations for which Stock has to be
*& Excluded from Transfer from ECC/R3 to SCM-APO are
*& maintained in ZGATPEXCLSTORLOC Custom Table.
*&-------------------------------------------------------------------------------*
*& 12-OCT-2012 : Check made more Granular by Adding Material Type
*& so that Only Stock of that Material Type is Blocked
*& from transfer to SCM-APO. This is needed because we
*& may be doing Re-work for Saleable Finished Products
*& and not needed in APO for ATP or Supply Planning,
*& but Components Stock may be needed for PPDS/MATP/CTP
*& so records in the Z Table now need to be by
*& Plant-Storage Location-Material Type as KEY Fields
*& and additional records can be added for each MatType.
*& If a NON-BLANK Material Group Field is also Maintained
*& in the Table which is a Non-Key Field then Code will
Copyright 2014-2020 : Ambrish Mathur 52
SAP SCM Core Interface Function (CIF) Training SAP SCM-APO Master-data CIF ABAP Enhancements / User-Exits
*& Filter only for those Material Groups within the MatType
*& else all Material Groups will be allowed for the MatType.
*& ALSO Exclusion Rule Validity Dates Logic was Added.
*&-------------------------------------------------------------------------------*
tables : T001L, ZGATPEXCLSTORLOC.
DATA : w_tabix type sy-tabix,
w_tabix2 type sy-tabix.
CLEAR : W_TABIX, W_TABIX2.
*&-------------------------------------------------------------------------------*
** Loop thru all Material-Plant-Storage Location STOCKs
LOOP AT IT_MARD. "Start Looping thru Records in IT_MARD Structure
CLEAR : W_TABIX, W_TABIX2.
MOVE SY-TABIX TO W_TABIX.
SELECT SINGLE * FROM MARA WHERE MATNR = IT_MARD-MATNR.
IF SY-SUBRC EQ 0.
** IF ( MARA-MTART = 'FERT' ) OR "Check FG, Semi-FG, Raw, Packing and Configurable Materials only
** ( MARA-MTART = 'HALB' ) OR
** ( MARA-MTART = 'ROH' ) OR
** ( MARA-MTART = 'VERP' ) OR
** ( MARA-MTART = 'KMAT' ).
SELECT SINGLE * FROM MARC WHERE MATNR = IT_MARD-MATNR and
WERKS = IT_MARD-WERKS.
IF SY-SUBRC EQ 0.
IF MARC-DISMM <> 'X0'. "If Material is not to be Planned in APO, then Skip Record
CONTINUE.
ELSE.
*** Check Whether this Plant-Storage Location-Matl. Type Stock is to be Excluded from Transfer to APO via CIF
*** Check Z Table Exclusion Rule Validity Dates as compared to Todays Posting Date
SELECT SINGLE * FROM ZGATPEXCLSTORLOC WHERE WERKS = IT_MARD-WERKS AND
LGORT = IT_MARD-LGORT AND
MTART = MARA-MTART AND
VALIDFROM <= SY-DATUM AND
VALIDTO >= SY-DATUM.
Copyright 2014-2020 : Ambrish Mathur 53
SAP SCM Core Interface Function (CIF) Training SAP SCM-APO Master-data CIF ABAP Enhancements / User-Exits
IF SY-SUBRC EQ 0. "Record Found in ZGATP Table to Exclude Storage Location Stock.
IF ZGATPEXCLSTORLOC-LVORM = ' ' AND "Deletion Flag is not Set in ZGATP Table
( IT_MARD-LABST > 0 OR "Has Valid UR Stock Quantity
IT_MARD-INSME > 0 OR "Has Valid QI Stock Quantity
IT_MARD-SPEME > 0 ). "Has Valid BL Stock Quantity
IF ZGATPEXCLSTORLOC-MATKL = ' ' OR "Material Group is Not specified OR
( ZGATPEXCLSTORLOC-MATKL <> ' ' AND "Material Group is Specified and it
MARA-MATKL = ZGATPEXCLSTORLOC-MATKL ). "matches with the Order Item Material Group
MOVE SY-TABIX TO W_TABIX2.
**AM** DELETE IT_MARD INDEX W_TABIX. "Delete CIF Storage Location Stock to Not Transfer to APO
IT_MARD-LABST = 0. "Make UR Stock Quantity as Zero for Excluded Storage Location
IT_MARD-INSME = 0. "Make QI Stock Quantity as Zero for Excluded Storage Location
IT_MARD-SPEME = 0. "Make BL Stock Quantity as Zero for Excluded Storage Location
MODIFY IT_MARD INDEX W_TABIX. "Update the Internal IT_STOCK Table.
* READ TABLE IT_MARDX WITH KEY
* MATNR = IT_MARD-MATNR
* WERKS = IT_MARD-WERKS
* LGORT = IT_MARD-LGORT. .
* IF SY-SUBRC EQ 0.
* IT_MARDX-LABST = ' '.
* IT_MARDX-INSME = ' '.
* IT_MARDX-SPEME = ' '.
* MODIFY IT_MARDX INDEX SY-TABIX.
* ENDIF.
ENDIF.
ENDIF.
ENDIF.
ENDIF.
ENDIF.
** ENDIF.
ENDIF.
ENDLOOP. "End Looping of Records in IT_MARD Structure
*&-------------------------------------------------------------------------------*
Copyright 2014-2020 : Ambrish Mathur 54
SAP SCM Core Interface Function (CIF) Training SAP SCM-APO Master-data CIF ABAP Enhancements / User-Exits
** Loop thru all Material-Plant-Storage Location-BATCH STOCKs
LOOP AT IT_MCHB. "Start Looping thru Records in IT_MCHB Structure
CLEAR : W_TABIX, W_TABIX2.
MOVE SY-TABIX TO W_TABIX.
SELECT SINGLE * FROM MARA WHERE MATNR = IT_MCHB-MATNR.
IF SY-SUBRC EQ 0.
** IF ( MARA-MTART = 'FERT' ) OR "Check FG, Semi-FG, Raw, Packing and Configurable Materials only
** ( MARA-MTART = 'HALB' ) OR
** ( MARA-MTART = 'ROH' ) OR
** ( MARA-MTART = 'VERP' ) OR
** ( MARA-MTART = 'KMAT' ).
SELECT SINGLE * FROM MARC WHERE MATNR = IT_MCHB-MATNR and
WERKS = IT_MCHB-WERKS.
IF SY-SUBRC EQ 0.
IF MARC-DISMM <> 'X0'. "If Material is not to be Planned in APO, then Skip Record
CONTINUE.
ELSE.
*** Check Whether this Plant-Storage Location-Matl. Type Stock is to be Excluded from Transfer to APO via CIF
*** Check Z Table Exclusion Rule Validity Dates as compared to Todays Posting Date
SELECT SINGLE * FROM ZGATPEXCLSTORLOC WHERE WERKS = IT_MCHB-WERKS AND
LGORT = IT_MCHB-LGORT AND
MTART = MARA-MTART AND
VALIDFROM <= SY-DATUM AND
VALIDTO >= SY-DATUM.
IF SY-SUBRC EQ 0. "Record Found in ZGATP Table to Exclude Storage Location Stock.
IF ZGATPEXCLSTORLOC-LVORM = ' ' AND "Deletion Flag is not Set in ZGATP Table
( IT_MCHB-CLABS > 0 OR "Has Valid BATCH UR Stock Quantity
IT_MCHB-CINSM > 0 OR "Has Valid BATCH QI Stock Quantity
IT_MCHB-CSPEM > 0 ). "Has Valid BATCH BL Stock Quantity
IF ZGATPEXCLSTORLOC-MATKL = ' ' OR "Material Group is Not specified OR
( ZGATPEXCLSTORLOC-MATKL <> ' ' AND "Material Group is Specified and it
MARA-MATKL = ZGATPEXCLSTORLOC-MATKL ). "matches with the Order Item Material Group
MOVE SY-TABIX TO W_TABIX2.
**AM** DELETE IT_STOCK INDEX W_TABIX. "Delete CIF Storage Location Stock to Not Transfer to APO
Copyright 2014-2020 : Ambrish Mathur 55
SAP SCM Core Interface Function (CIF) Training SAP SCM-APO Master-data CIF ABAP Enhancements / User-Exits
IT_MCHB-CLABS = 0. "Make BATCH UR Stock Quantity as Zero for Excluded Storage
Location
IT_MCHB-CINSM = 0. "Make BATCH QI Stock Quantity as Zero for Excluded Storage
Location
IT_MCHB-CSPEM = 0. "Make BATCH BL Stock Quantity as Zero for Excluded Storage
Location
MODIFY IT_MARD INDEX W_TABIX. "Update the Internal IT_STOCK Table.
* READ TABLE IT_MCHBX WITH KEY
* MATNR = IT_MCHB-MATNR
* WERKS = IT_MCHB-WERKS
* LGORT = IT_MCHB-LGORT. .
* IF SY-SUBRC EQ 0.
* IT_MCHBX-CLABS = ' '.
* IT_MCHBX-CINSM = ' '.
* IT_MCHBX-CSPEM = ' '.
* MODIFY IT_MCHBX INDEX SY-TABIX.
* ENDIF.
ENDIF.
ENDIF.
ENDIF.
ENDIF.
ENDIF.
** ENDIF.
ENDIF.
ENDLOOP. "End Looping of Records in IT_MARD Structure
*&-------------------------------------------------------------------------------*
** Loop thru all Material-Plant-Storage Location SPECIAL STOCKs in IT_STOCK
LOOP AT IT_STOCK. "Start Looping thru Records in IT_STOCK Structure
CLEAR : W_TABIX, W_TABIX2.
MOVE SY-TABIX TO W_TABIX.
SELECT SINGLE * FROM MARA WHERE MATNR = IT_STOCK-EXT_MATNR.
IF SY-SUBRC EQ 0.
** IF ( MARA-MTART = 'FERT' ) OR "Check FG, Semi-FG, Raw, Packing and Configurable Materials only
** ( MARA-MTART = 'HALB' ) OR
** ( MARA-MTART = 'ROH' ) OR
** ( MARA-MTART = 'VERP' ) OR
** ( MARA-MTART = 'KMAT' ).
Copyright 2014-2020 : Ambrish Mathur 56
SAP SCM Core Interface Function (CIF) Training SAP SCM-APO Master-data CIF ABAP Enhancements / User-Exits
SELECT SINGLE * FROM MARC WHERE MATNR = IT_STOCK-EXT_MATNR and
WERKS = IT_STOCK-EXT_LOCNO.
IF SY-SUBRC EQ 0.
IF MARC-DISMM <> 'X0'. "If Material is not to be Planned in APO, then Skip Record
CONTINUE.
ELSE.
*** Check Whether this Plant-Storage Location-Matl. Type Stock is to be Excluded from Transfer to APO via CIF
*** Check Z Table Exclusion Rule Validity Dates as compared to Todays Posting Date
SELECT SINGLE * FROM ZGATPEXCLSTORLOC WHERE WERKS = IT_STOCK-EXT_LOCNO AND
LGORT = IT_STOCK-STORAGELOC AND
MTART = MARA-MTART AND
VALIDFROM <= SY-DATUM AND
VALIDTO >= SY-DATUM.
IF SY-SUBRC EQ 0. "Record Found in ZGATP Table to Exclude Storage Location Stock.
IF ZGATPEXCLSTORLOC-LVORM = ' ' AND "Deletion Flag is not Set in ZGATP Table
IT_STOCK-QUANTITY > 0 AND "Has Valid Stock Quantity
( IT_STOCK-ATPCAT = 'CC' OR "Un-restricted (UR) Stock
IT_STOCK-ATPCAT = 'CI' OR "Quality Inspection (QI) Stock
IT_STOCK-ATPCAT = 'CF' ). "Blocked (BL) Stock
IF ZGATPEXCLSTORLOC-MATKL = ' ' OR "Material Group is Not specified OR
( ZGATPEXCLSTORLOC-MATKL <> ' ' AND "Material Group is Specified and it
MARA-MATKL = ZGATPEXCLSTORLOC-MATKL ). "matches with the Order Item Material Group
MOVE SY-TABIX TO W_TABIX2.
**AM** DELETE IT_STOCK INDEX W_TABIX. "Delete CIF Storage Location Stock to Not Transfer to APO
IT_STOCK-QUANTITY = 0. "Make Stock Quantity as Zero for Excluded Storage Location
MODIFY IT_STOCK INDEX W_TABIX. "Update the Internal IT_STOCK Table.
* READ TABLE IT_STOCKX WITH KEY
* MATNR = IT_STOCK-EXT_MATNR
* LOCNO = IT_STOCK-EXT_LOCNO
* STORAGELOC = IT_STOCK-STORAGELOC. .
* IF SY-SUBRC EQ 0.
* IT_STOCKX-QUANTITY = ' '.
* MODIFY IT_STOCKX INDEX SY-TABIX.
Copyright 2014-2020 : Ambrish Mathur 57
SAP SCM Core Interface Function (CIF) Training SAP SCM-APO Master-data CIF ABAP Enhancements / User-Exits
* ENDIF.
ENDIF.
ENDIF.
ENDIF.
ENDIF.
ENDIF.
** ENDIF.
ENDIF.
ENDLOOP. "End Looping of Records in IT_STOCK Structure
*&-------------------------------------------------------------------------------*
** Loop thru all Material-Plant-Storage Location NEW STOCKs in IT_STOCKN
LOOP AT IT_STOCKN. "Start Looping thru Records in IT_STOCKN Structure
CLEAR : W_TABIX, W_TABIX2.
MOVE SY-TABIX TO W_TABIX.
SELECT SINGLE * FROM MARA WHERE MATNR = IT_STOCKN-EXT_MATNR.
IF SY-SUBRC EQ 0.
** IF ( MARA-MTART = 'FERT' ) OR "Check FG, Semi-FG, Raw, Packing and Configurable Materials only
** ( MARA-MTART = 'HALB' ) OR
** ( MARA-MTART = 'ROH' ) OR
** ( MARA-MTART = 'VERP' ) OR
** ( MARA-MTART = 'KMAT' ).
SELECT SINGLE * FROM MARC WHERE MATNR = IT_STOCKN-EXT_MATNR and
WERKS = IT_STOCKN-EXT_LOCNO.
IF SY-SUBRC EQ 0.
IF MARC-DISMM <> 'X0'. "If Material is not to be Planned in APO, then Skip Record
CONTINUE.
ELSE.
*** Check Whether this Plant-Storage Location-Matl. Type Stock is to be Excluded from Transfer to APO via CIF
*** Check Z Table Exclusion Rule Validity Dates as compared to Todays Posting Date
SELECT SINGLE * FROM ZGATPEXCLSTORLOC WHERE WERKS = IT_STOCKN-EXT_LOCNO AND
LGORT = IT_STOCKN-STORAGELOC AND
MTART = MARA-MTART AND
VALIDFROM <= SY-DATUM AND
VALIDTO >= SY-DATUM.
IF SY-SUBRC EQ 0. "Record Found in ZGATP Table to Exclude Storage Location Stock.
IF ZGATPEXCLSTORLOC-LVORM = ' ' AND "Deletion Flag is not Set in ZGATP Table
Copyright 2014-2020 : Ambrish Mathur 58
SAP SCM Core Interface Function (CIF) Training SAP SCM-APO Master-data CIF ABAP Enhancements / User-Exits
IT_STOCKN-QUANTITY > 0 AND "Has Valid Stock Quantity
( IT_STOCKN-ATPCAT = 'CC' OR "Un-restricted (UR) Stock
IT_STOCKN-ATPCAT = 'CI' OR "Quality Inspection (QI) Stock
IT_STOCKN-ATPCAT = 'CF' ). "Blocked (BL) Stock
IF ZGATPEXCLSTORLOC-MATKL = ' ' OR "Material Group is Not specified OR
( ZGATPEXCLSTORLOC-MATKL <> ' ' AND "Material Group is Specified and it
MARA-MATKL = ZGATPEXCLSTORLOC-MATKL ). "matches with the Order Item Material Group
MOVE SY-TABIX TO W_TABIX2.
**AM** DELETE IT_STOCK INDEX W_TABIX. "Delete CIF Storage Location Stock to Not Transfer to APO
IT_STOCKN-QUANTITY = 0. "Make Stock Quantity as Zero for Excluded Storage Location
MODIFY IT_STOCKN INDEX W_TABIX. "Update the Internal IT_STOCK Table.
* READ TABLE IT_STOCKNX WITH KEY
* MATNR = IT_STOCKN-EXT_MATNR
* LOCNO = IT_STOCKN-EXT_LOCNO
* STORAGELOC = IT_STOCKN-STORAGELOC. .
* IF SY-SUBRC EQ 0.
* IT_STOCKNX-QUANTITY = ' '.
* MODIFY IT_STOCKNX INDEX SY-TABIX.
* ENDIF.
ENDIF.
ENDIF.
ENDIF.
ENDIF.
ENDIF.
** ENDIF.
ENDIF.
ENDLOOP. "End Looping of Records in IT_STOCKN Structure
*&-------------------------------------------------------------------------------*
Copyright 2014-2020 : Ambrish Mathur 59