SAP PREFERENCE_COSTING_KMAT Function Module for NOTRANSL: Präferenzkalkualtion
PREFERENCE_COSTING_KMAT is a standard preference costing kmat SAP function module available within SAP R/3 or S/4 Hana systems, depending on your version and release level. It is used for NOTRANSL: Präferenzkalkualtion processing and below is the pattern details for this FM, showing its interface including any import and export parameters, exceptions etc. there is also a full "cut and paste" ABAP pattern code example, along with implementation ABAP coding, documentation and contribution comments specific to this or related objects.
See here to view full function module documentation and code listing for preference costing kmat FM, simply by entering the name PREFERENCE_COSTING_KMAT into the relevant SAP transaction such as SE37 or SE38.
Function Group: PREF
Program Name: SAPLPREF
Main Program: SAPLPREF
Appliation area: V
Release date: N/A
Mode(Normal, Remote etc): Normal Function Module
Update:

Function PREFERENCE_COSTING_KMAT pattern details
In-order to call this FM within your sap programs, simply using the below ABAP pattern details to trigger the function call...or see the full ABAP code listing at the end of this article. You can simply cut and paste this code into your ABAP progrom as it is, including variable declarations.CALL FUNCTION 'PREFERENCE_COSTING_KMAT'"NOTRANSL: Präferenzkalkualtion.
EXPORTING
P_WERKS = "Plant
P_VBELN2 = "Sales and Distribution Document Number
P_POSNR2 = "Sales document item
* P_UPDATE = ' ' "Checkbox
* P_MDMPS = ' ' "Checkbox
TOPMAT = "Start Material Display for BOM Explosions
* P_ALPAUF = ' ' "Explode Alternative Assemblies
* P_PWLEN = 4 "Order level
* P_PROZEN = 0 "Security percent
P_LAND1 = "Country
P_PWGGR = "Preference plant group
IMPORTING
W_MARC = "Plant Data for Material
KZ_NO_MATSTAMM_UPDATE = "Checkbox
KZ_NO_CONDITION_INSERT = "Checkbox
KP_PROZEN = "Security percent
TABLES
STB = "BOM Item (Enhanced for Preference Determination)
BG_WERTEKMAT = "Preference KMAT results configurable assemblies
BG_KONDKMAT2 = "
MATCAT = "BOM Explosion: Materials
T_MATWERTE = "Preference:Transfer Struct.for Mat.Values by Preference Zone
DATA_LOG = "Preference: Transfer Structure for Data Log/Error Log
ERROR_LOG = "Preference: Transfer Structure for Data Log/Error Log
K_TAB = "Preference: Transfer components for each customs area
INT_MAPE = "Material Master: Export Control File
REGELTAB = "Preference: Transmit Procedure Result for Material/Zone
PWGGR_WERKS = "
EXCEPTIONS
HS_OPCODE_FAILURE = 1 NO_PLANT = 2 NO_STAWN = 3 NO_RULE_DEFINED = 4 NO_PROCEDURE_DEFINED = 5 FAILURE_READ_TAB = 6 FAILURE_READ_MARC = 7 FAILURE_MOD_TAB = 8 FAILURE_KOMPONENTE = 9
Customer Function user exits
Below is a list of CUSTOMER FUNCTION exit user exits that are available within this program and maybe relevant for this FM.EXIT_SAPLPREF_001 Customer enhancement margin of safety for planned price
EXIT_SAPLPREF_002 Customer enhancement security surcharge for components cost/standard price
IMPORTING Parameters details for PREFERENCE_COSTING_KMAT
P_WERKS - Plant
Data type: T001W-WERKSOptional: No
Call by Reference: No ( called with pass by value option)
P_VBELN2 - Sales and Distribution Document Number
Data type: VBAP-VBELNOptional: No
Call by Reference: Yes
P_POSNR2 - Sales document item
Data type: VBAP-POSNROptional: No
Call by Reference: Yes
P_UPDATE - Checkbox
Data type: CSDATA-XFELDDefault: SPACE
Optional: Yes
Call by Reference: No ( called with pass by value option)
P_MDMPS - Checkbox
Data type: CSDATA-XFELDDefault: SPACE
Optional: Yes
Call by Reference: No ( called with pass by value option)
TOPMAT - Start Material Display for BOM Explosions
Data type: CSTMATOptional: No
Call by Reference: No ( called with pass by value option)
P_ALPAUF - Explode Alternative Assemblies
Data type: CSDATA-XFELDDefault: SPACE
Optional: Yes
Call by Reference: No ( called with pass by value option)
P_PWLEN - Order level
Data type: STPOX-AUFSTDefault: 4
Optional: Yes
Call by Reference: No ( called with pass by value option)
P_PROZEN - Security percent
Data type: RVSEL-P_PROZENOptional: Yes
Call by Reference: No ( called with pass by value option)
P_LAND1 - Country
Data type: T604WGG-LAND1Optional: No
Call by Reference: No ( called with pass by value option)
P_PWGGR - Preference plant group
Data type: T604WGG-PWGGROptional: No
Call by Reference: No ( called with pass by value option)
EXPORTING Parameters details for PREFERENCE_COSTING_KMAT
W_MARC - Plant Data for Material
Data type: MARCOptional: No
Call by Reference: No ( called with pass by value option)
KZ_NO_MATSTAMM_UPDATE - Checkbox
Data type: CSDATA-XFELDOptional: No
Call by Reference: No ( called with pass by value option)
KZ_NO_CONDITION_INSERT - Checkbox
Data type: CSDATA-XFELDOptional: No
Call by Reference: No ( called with pass by value option)
KP_PROZEN - Security percent
Data type: RVSEL-P_PROZENOptional: No
Call by Reference: No ( called with pass by value option)
TABLES Parameters details for PREFERENCE_COSTING_KMAT
STB - BOM Item (Enhanced for Preference Determination)
Data type: RL0PRE_2Optional: No
Call by Reference: No ( called with pass by value option)
BG_WERTEKMAT - Preference KMAT results configurable assemblies
Data type: RL0PRE_6Optional: No
Call by Reference: No ( called with pass by value option)
BG_KONDKMAT2 -
Data type:Optional: No
Call by Reference: Yes
MATCAT - BOM Explosion: Materials
Data type: CSCMATOptional: No
Call by Reference: No ( called with pass by value option)
T_MATWERTE - Preference:Transfer Struct.for Mat.Values by Preference Zone
Data type: RL0PRE_1Optional: No
Call by Reference: No ( called with pass by value option)
DATA_LOG - Preference: Transfer Structure for Data Log/Error Log
Data type: RL0PRE_3Optional: No
Call by Reference: No ( called with pass by value option)
ERROR_LOG - Preference: Transfer Structure for Data Log/Error Log
Data type: RL0PRE_3Optional: No
Call by Reference: No ( called with pass by value option)
K_TAB - Preference: Transfer components for each customs area
Data type: RL0PRE_4Optional: No
Call by Reference: No ( called with pass by value option)
INT_MAPE - Material Master: Export Control File
Data type: MAPEOptional: No
Call by Reference: No ( called with pass by value option)
REGELTAB - Preference: Transmit Procedure Result for Material/Zone
Data type: RL0PRE_5Optional: No
Call by Reference: No ( called with pass by value option)
PWGGR_WERKS -
Data type:Optional: No
Call by Reference: No ( called with pass by value option)
EXCEPTIONS details
HS_OPCODE_FAILURE - DE-EN-LANG-SWITCH-NO-TRANSLATION
Data type:Optional: No
Call by Reference: No ( called with pass by value option)
NO_PLANT - DE-EN-LANG-SWITCH-NO-TRANSLATION
Data type:Optional: No
Call by Reference: No ( called with pass by value option)
NO_STAWN - DE-EN-LANG-SWITCH-NO-TRANSLATION
Data type:Optional: No
Call by Reference: No ( called with pass by value option)
NO_RULE_DEFINED - DE-EN-LANG-SWITCH-NO-TRANSLATION
Data type:Optional: No
Call by Reference: No ( called with pass by value option)
NO_PROCEDURE_DEFINED - DE-EN-LANG-SWITCH-NO-TRANSLATION
Data type:Optional: No
Call by Reference: No ( called with pass by value option)
FAILURE_READ_TAB - DE-EN-LANG-SWITCH-NO-TRANSLATION
Data type:Optional: No
Call by Reference: No ( called with pass by value option)
FAILURE_READ_MARC - DE-EN-LANG-SWITCH-NO-TRANSLATION
Data type:Optional: No
Call by Reference: No ( called with pass by value option)
FAILURE_MOD_TAB - DE-EN-LANG-SWITCH-NO-TRANSLATION
Data type:Optional: No
Call by Reference: No ( called with pass by value option)
FAILURE_KOMPONENTE -
Data type:Optional: No
Call by Reference: No ( called with pass by value option)
Copy and paste ABAP code example for PREFERENCE_COSTING_KMAT Function Module
The ABAP code below is a full code listing to execute function module POPUP_TO_CONFIRM including all data declarations. The code uses the original data declarations rather than the latest in-line data DECLARATION SYNTAX but I have included an ABAP code snippet at the end to show how declarations would look using the newer method of declaring data variables on the fly. This will allow you to compare and fully understand the new inline method. Please note some of the newer syntax such as the @DATA is not available until a later 4.70 service pack (SP8), which i why i have stuck to the origianl for this example.| DATA: | ||||
| lt_stb | TYPE STANDARD TABLE OF RL0PRE_2, " | |||
| lv_w_marc | TYPE MARC, " | |||
| lv_p_werks | TYPE T001W-WERKS, " | |||
| lv_hs_opcode_failure | TYPE T001W, " | |||
| lv_p_vbeln2 | TYPE VBAP-VBELN, " | |||
| lt_bg_wertekmat | TYPE STANDARD TABLE OF RL0PRE_6, " | |||
| lv_p_posnr2 | TYPE VBAP-POSNR, " | |||
| lt_bg_kondkmat2 | TYPE STANDARD TABLE OF VBAP, " | |||
| lt_matcat | TYPE STANDARD TABLE OF CSCMAT, " | |||
| lv_no_plant | TYPE CSCMAT, " | |||
| lv_p_update | TYPE CSDATA-XFELD, " SPACE | |||
| lv_kz_no_matstamm_update | TYPE CSDATA-XFELD, " | |||
| lv_p_mdmps | TYPE CSDATA-XFELD, " SPACE | |||
| lv_no_stawn | TYPE CSDATA, " | |||
| lt_t_matwerte | TYPE STANDARD TABLE OF RL0PRE_1, " | |||
| lv_kz_no_condition_insert | TYPE CSDATA-XFELD, " | |||
| lv_topmat | TYPE CSTMAT, " | |||
| lt_data_log | TYPE STANDARD TABLE OF RL0PRE_3, " | |||
| lv_kp_prozen | TYPE RVSEL-P_PROZEN, " | |||
| lv_no_rule_defined | TYPE RVSEL, " | |||
| lv_p_alpauf | TYPE CSDATA-XFELD, " SPACE | |||
| lt_error_log | TYPE STANDARD TABLE OF RL0PRE_3, " | |||
| lv_no_procedure_defined | TYPE RL0PRE_3, " | |||
| lt_k_tab | TYPE STANDARD TABLE OF RL0PRE_4, " | |||
| lv_p_pwlen | TYPE STPOX-AUFST, " 4 | |||
| lv_failure_read_tab | TYPE STPOX, " | |||
| lt_int_mape | TYPE STANDARD TABLE OF MAPE, " | |||
| lv_p_prozen | TYPE RVSEL-P_PROZEN, " 0 | |||
| lv_failure_read_marc | TYPE RVSEL, " | |||
| lv_p_land1 | TYPE T604WGG-LAND1, " | |||
| lt_regeltab | TYPE STANDARD TABLE OF RL0PRE_5, " | |||
| lv_failure_mod_tab | TYPE RL0PRE_5, " | |||
| lv_p_pwggr | TYPE T604WGG-PWGGR, " | |||
| lt_pwggr_werks | TYPE STANDARD TABLE OF T604WGG, " | |||
| lv_failure_komponente | TYPE T604WGG. " |
|   CALL FUNCTION 'PREFERENCE_COSTING_KMAT' "NOTRANSL: Präferenzkalkualtion |
| EXPORTING | ||
| P_WERKS | = lv_p_werks | |
| P_VBELN2 | = lv_p_vbeln2 | |
| P_POSNR2 | = lv_p_posnr2 | |
| P_UPDATE | = lv_p_update | |
| P_MDMPS | = lv_p_mdmps | |
| TOPMAT | = lv_topmat | |
| P_ALPAUF | = lv_p_alpauf | |
| P_PWLEN | = lv_p_pwlen | |
| P_PROZEN | = lv_p_prozen | |
| P_LAND1 | = lv_p_land1 | |
| P_PWGGR | = lv_p_pwggr | |
| IMPORTING | ||
| W_MARC | = lv_w_marc | |
| KZ_NO_MATSTAMM_UPDATE | = lv_kz_no_matstamm_update | |
| KZ_NO_CONDITION_INSERT | = lv_kz_no_condition_insert | |
| KP_PROZEN | = lv_kp_prozen | |
| TABLES | ||
| STB | = lt_stb | |
| BG_WERTEKMAT | = lt_bg_wertekmat | |
| BG_KONDKMAT2 | = lt_bg_kondkmat2 | |
| MATCAT | = lt_matcat | |
| T_MATWERTE | = lt_t_matwerte | |
| DATA_LOG | = lt_data_log | |
| ERROR_LOG | = lt_error_log | |
| K_TAB | = lt_k_tab | |
| INT_MAPE | = lt_int_mape | |
| REGELTAB | = lt_regeltab | |
| PWGGR_WERKS | = lt_pwggr_werks | |
| EXCEPTIONS | ||
| HS_OPCODE_FAILURE = 1 | ||
| NO_PLANT = 2 | ||
| NO_STAWN = 3 | ||
| NO_RULE_DEFINED = 4 | ||
| NO_PROCEDURE_DEFINED = 5 | ||
| FAILURE_READ_TAB = 6 | ||
| FAILURE_READ_MARC = 7 | ||
| FAILURE_MOD_TAB = 8 | ||
| FAILURE_KOMPONENTE = 9 | ||
| . " PREFERENCE_COSTING_KMAT | ||
ABAP code using 7.40 inline data declarations to call FM PREFERENCE_COSTING_KMAT
The below ABAP code uses the newer in-line data declarations. This allows you to see the coding differences/benefits of the later inline syntax. Please note some of the newer syntax below, such as the @DATA is not available until 4.70 EHP 8.| "SELECT single WERKS FROM T001W INTO @DATA(ld_p_werks). | ||||
| "SELECT single VBELN FROM VBAP INTO @DATA(ld_p_vbeln2). | ||||
| "SELECT single POSNR FROM VBAP INTO @DATA(ld_p_posnr2). | ||||
| "SELECT single XFELD FROM CSDATA INTO @DATA(ld_p_update). | ||||
| DATA(ld_p_update) | = ' '. | |||
| "SELECT single XFELD FROM CSDATA INTO @DATA(ld_kz_no_matstamm_update). | ||||
| "SELECT single XFELD FROM CSDATA INTO @DATA(ld_p_mdmps). | ||||
| DATA(ld_p_mdmps) | = ' '. | |||
| "SELECT single XFELD FROM CSDATA INTO @DATA(ld_kz_no_condition_insert). | ||||
| "SELECT single P_PROZEN FROM RVSEL INTO @DATA(ld_kp_prozen). | ||||
| "SELECT single XFELD FROM CSDATA INTO @DATA(ld_p_alpauf). | ||||
| DATA(ld_p_alpauf) | = ' '. | |||
| "SELECT single AUFST FROM STPOX INTO @DATA(ld_p_pwlen). | ||||
| DATA(ld_p_pwlen) | = 4. | |||
| "SELECT single P_PROZEN FROM RVSEL INTO @DATA(ld_p_prozen). | ||||
| "SELECT single LAND1 FROM T604WGG INTO @DATA(ld_p_land1). | ||||
| "SELECT single PWGGR FROM T604WGG INTO @DATA(ld_p_pwggr). | ||||
Search for further information about these or an SAP related objects