2014 Jul 01 5:33 PM
I'm desperately trying to create a simple BOM using 'CSAP_MAT_BOM_CREATE' but I'm just getting nowhere! The only thing this FM is creating is a headache. I'm hoping someone can help me!!!
At the moment, I am using:
...But it's always returning 1 😞
When I'm debugging I'm always getting upto: "PERFORM mc29s_fuellen_01 USING mtl_matnr mtl_werks ini_bwkey." (LCSDIFAS - Line 88). Here's where it seems to fail. Inside this it's always trying to do a "call function 'MATERIAL_READ'" on the MATNR I want to create, but obviously it doesn't exist yet, so it always fails. It therefore sets FLG_API_ERROR = 'X' and fails everytime.
I've looked through all 157 search results on this forum, seemingly all of Google, and the documentation hasn't helped at all either 😞
Can someone please provide me with either some suggestions, or some example code (Using the actual values you're populating parameters with instead of other variable names so I can see what's going on)?
Many thanks.
2014 Jul 01 10:13 PM
Hi,
Material have to exist before call this function.
This function needs parameters in outer format. Before You fill parametrs converse every parameter (material index and mat. index of components, units, quantity) to outer format (ex. using WRITE).
For material You can also use function CONVERSION_EXIT_MATN2_OUTPUT.
Regards
Jarek
I'm desperately trying to create a simple BOM using 'CSAP_MAT_BOM_CREATE' but I'm just getting nowhere! The only thing this FM is creating is a headache. I'm hoping someone can help me!!!
At the moment, I am using:
...But it's always returning 1 😞
When I'm debugging I'm always getting upto: "PERFORM mc29s_fuellen_01 USING mtl_matnr mtl_werks ini_bwkey." (LCSDIFAS - Line 88). Here's where it seems to fail. Inside this it's always trying to do a "call function 'MATERIAL_READ'" on the MATNR I want to create, but obviously it doesn't exist yet, so it always fails. It therefore sets FLG_API_ERROR = 'X' and fails everytime.
I've looked through all 157 search results on this forum, seemingly all of Google, and the documentation hasn't helped at all either 😞
Can someone please provide me with either some suggestions, or some example code (Using the actual values you're populating parameters with instead of other variable names so I can see what's going on)?
Many thanks.
2014 Jul 01 10:13 PM
Hi,
Material have to exist before call this function.
This function needs parameters in outer format. Before You fill parametrs converse every parameter (material index and mat. index of components, units, quantity) to outer format (ex. using WRITE).
For material You can also use function CONVERSION_EXIT_MATN2_OUTPUT.
Regards
Jarek
2014 Jul 02 6:53 AM
Hi,
As Jarek mentined , pls check the material existency and then convert the material in to internal format , moreover pls check the mandatory parameters .
CALL FUNCTION 'CSAP_MAT_BOM_CREATE'
EXPORTING
material = material "2000000001
plant = plant "1001
bom_usage = '05'
valid_from = valid_from 'Date
i_stko = ls_stko "Structure of header
* FL_NO_CHANGE_DOC = ' '
* FL_COMMIT_AND_WAIT = ' '
* FL_CAD = ' '
fl_default_values = ' '
IMPORTING
fl_warning = fl_warning
bom_no = bom_no
TABLES
t_stpo = lt_stpo[]
* T_DEP_DATA =
* T_DEP_DESCR =
* T_DEP_ORDER =
* T_DEP_SOURCE =
* T_DEP_DOC =
* T_LTX_LINE =
* T_STPU =
EXCEPTIONS
error = 1
OTHERS = 2.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID
* TYPE SY-MSGTY
* NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
why can't you use the below function module :
* call function to create bill fo materail by using
* the previously declared local internal tables
DATA : lit_bomgroup TYPE STANDARD TABLE OF bapi1080_bgr_c,
wa_bomgroup TYPE bapi1080_bgr_c,
lv_bom_text TYPE string,
lv_plant TYPE ztbom_header-werks,
lit_variants TYPE STANDARD TABLE OF bapi1080_bom_c,
wa_variants TYPE bapi1080_bom_c,
lit_items TYPE STANDARD TABLE OF bapi1080_itm_c,
wa_items TYPE bapi1080_itm_c,
lit_matrel TYPE STANDARD TABLE OF bapi1080_mbm_c,
wa_matrel TYPE bapi1080_mbm_c,
lit_itemas TYPE STANDARD TABLE OF bapi1080_rel_itm_bom_c,
wa_itemas TYPE bapi1080_rel_itm_bom_c.
wa_bomgroup-bom_group_identification = 'BAPI_SMP_COL1'.
wa_bomgroup-object_type = 'BGR'.
wa_bomgroup-object_id = 'SIMPLE1'.
wa_bomgroup-bom_usage = wa_bom_h-stlan.
wa_bomgroup-created_in_plant = wa_bom_h-werks.
wa_bomgroup-ltxt_lang = sy-langu.
wa_bomgroup-technical_type = ' '.
wa_bomgroup-bom_text = lv_bom_text.
APPEND wa_bomgroup TO lit_bomgroup.
*-->Check BOM Existency
*-->Convert Material
wa_bom_h-datuv = sy-datum.
wa_bom_h-stlst = '01'.
*-->Convert UOM
*--Get Alt BOM based on Material and Plantand pass the next Alt BOM which we have to create
*-->Variants
wa_variants-bom_group_identification = 'BAPI_SMP_COL1'.
wa_variants-object_type = 'BOM'.
wa_variants-object_id = 'SIMPLE1'.
wa_variants-alternative_bom = wa_bom_h-stlal.
wa_variants-bom_status = wa_bom_h-stlst.
wa_variants-base_qty = wa_bom_h-bmeng.
wa_variants-base_unit = wa_bom_h-bmein. " base unit
wa_variants-alt_text = wa_bom_h-alternate_text. " alternative text
wa_variants-valid_from_date = wa_bom_h-datuv.
wa_variants-function = 'NEW'.
APPEND wa_variants TO lit_variants.
CALL FUNCTION 'CONVERSION_EXIT_CUNIT_INPUT'
EXPORTING
input = wa_bom_h-bmein
IMPORTING
output = wa_bom_h-bmein
EXCEPTIONS
unit_not_found = 1
OTHERS = 2.
*--> Pass Items
SORT lit_items BY object_id valid_from_date.
CALL FUNCTION 'BAPI_MATERIAL_BOM_GROUP_CREATE'
EXPORTING
all_error = 'X'
TABLES
bomgroup = lit_bomgroup
variants = lit_variants
items = lit_items
materialrelations = lit_matrel
itemassignments = lit_itemas
return = e_return.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'.
2014 Jul 02 6:56 AM
Hi,
As Jarek mentined , pls check the material existency and then convert the material in to internal format , moreover pls check the mandatory parameters .
CALL FUNCTION 'CSAP_MAT_BOM_CREATE'
EXPORTING
material = material "2000000001
plant = plant "1001
bom_usage = '05'
valid_from = valid_from 'Date
i_stko = ls_stko "Structure of header
* FL_NO_CHANGE_DOC = ' '
* FL_COMMIT_AND_WAIT = ' '
* FL_CAD = ' '
fl_default_values = ' '
IMPORTING
fl_warning = fl_warning
bom_no = bom_no
TABLES
t_stpo = lt_stpo[]
* T_DEP_DATA =
* T_DEP_DESCR =
* T_DEP_ORDER =
* T_DEP_SOURCE =
* T_DEP_DOC =
* T_LTX_LINE =
* T_STPU =
EXCEPTIONS
error = 1
OTHERS = 2.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID
* TYPE SY-MSGTY
* NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
why can't you use the below function module :
* call function to create bill fo materail by using
* the previously declared local internal tables
DATA : lit_bomgroup TYPE STANDARD TABLE OF bapi1080_bgr_c,
wa_bomgroup TYPE bapi1080_bgr_c,
lv_bom_text TYPE string,
lv_plant TYPE ztbom_header-werks,
lit_variants TYPE STANDARD TABLE OF bapi1080_bom_c,
wa_variants TYPE bapi1080_bom_c,
lit_items TYPE STANDARD TABLE OF bapi1080_itm_c,
wa_items TYPE bapi1080_itm_c,
lit_matrel TYPE STANDARD TABLE OF bapi1080_mbm_c,
wa_matrel TYPE bapi1080_mbm_c,
lit_itemas TYPE STANDARD TABLE OF bapi1080_rel_itm_bom_c,
wa_itemas TYPE bapi1080_rel_itm_bom_c.
wa_bomgroup-bom_group_identification = 'BAPI_SMP_COL1'.
wa_bomgroup-object_type = 'BGR'.
wa_bomgroup-object_id = 'SIMPLE1'.
wa_bomgroup-bom_usage = wa_bom_h-stlan.
wa_bomgroup-created_in_plant = wa_bom_h-werks.
wa_bomgroup-ltxt_lang = sy-langu.
wa_bomgroup-technical_type = ' '.
wa_bomgroup-bom_text = lv_bom_text.
APPEND wa_bomgroup TO lit_bomgroup.
*-->Check BOM Existency
*-->Convert Material
wa_bom_h-datuv = sy-datum.
wa_bom_h-stlst = '01'.
*-->Convert UOM
*--Get Alt BOM based on Material and Plantand pass the next Alt BOM which we have to create
*-->Variants
wa_variants-bom_group_identification = 'BAPI_SMP_COL1'.
wa_variants-object_type = 'BOM'.
wa_variants-object_id = 'SIMPLE1'.
wa_variants-alternative_bom = wa_bom_h-stlal.
wa_variants-bom_status = wa_bom_h-stlst.
wa_variants-base_qty = wa_bom_h-bmeng.
wa_variants-base_unit = wa_bom_h-bmein. " base unit
wa_variants-alt_text = wa_bom_h-alternate_text. " alternative text
wa_variants-valid_from_date = wa_bom_h-datuv.
wa_variants-function = 'NEW'.
APPEND wa_variants TO lit_variants.
CALL FUNCTION 'CONVERSION_EXIT_CUNIT_INPUT'
EXPORTING
input = wa_bom_h-bmein
IMPORTING
output = wa_bom_h-bmein
EXCEPTIONS
unit_not_found = 1
OTHERS = 2.
*--> Pass Items
SORT lit_items BY object_id valid_from_date.
CALL FUNCTION 'BAPI_MATERIAL_BOM_GROUP_CREATE'
EXPORTING
all_error = 'X'
TABLES
bomgroup = lit_bomgroup
variants = lit_variants
items = lit_items
materialrelations = lit_matrel
itemassignments = lit_itemas
return = e_return.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'.
2014 Jul 02 8:04 AM
This CSAP_MAT_BOM_CREATE function is specific. Use external/outer format of material index and other data.
2014 Jul 02 8:54 AM
Hi guys.
Thank you so much for your time in trying to help me out on this one - It's really appreciated.
- The materials that are to be inside my BOM already exist. I'm putting these items in the table for t_stpo. Is this not correct? I thought 'material' would create a MATNR for a BOM made up of the items in t_stpo - Is this not the case?
If the material needs to exist beforehand, do I need to first create a basic material, and then pass that MATNR in to 'material' for it to be converted into a BOM? I'm really confused :S
- Same questions really as above! Although I have also tried using 'BAPI_MATERIAL_BOM_GROUP_CREATE' and got a few other issues. People then recommended using this FM instead as it's (Supposedly!) simpler to use when just creating a simple BOM with no alternatives, etc.
2014 Jul 02 9:00 AM
I'm not sure I understand You. Material indexes for BOM (basic material) and for every position should exist before You call this function.
Material is much more than just BOM.
2014 Jul 02 9:12 AM
Sorry Jaroslaw, maybe I'm using the wrong wording 😞
As I understand it, I'm sending the MATNR for the BOM header that I want to create in the 'material' exporting parameter in 'CSAP_MAT_BOM_CREATE', and then listing all of the components for this BOM (Which already exist) in the 't_stpo' tables parameter.
call function 'CSAP_MAT_BOM_CREATE'
exporting
material = 'ABCDEFG' (This doesn't exist - I wish to create this)
plant = 1000
...
tables
t_stpo = lt_components (All of the materials that should make up this new BOM which do all already exist)
...
I'm not good at explaining myself sorry! Is this not correct? Are you saying that 'ABCDEFG' should already exist?
2014 Jul 02 9:15 AM
2014 Jul 02 9:23 AM
That is where I'm going wrong then! Thank you!
Then, If this BOM should already exist, what am I creating with this FM?
Does 'CSAP_MAT_BOM_CREATE' create a copy of 'ABCDEFG' using the components in t_stpo and assign it another MATNR in the importing 'bom_no' parameter?
2014 Jul 02 9:32 AM
Material should already exist (ex. from trans MM01).
Function CSAP_MAT_BOM_CREATE creates Bill Of Material, like CS01 transaction.
2014 Jul 02 9:46 AM
Thanks for you help Jaroslaw 🙂
However now when I pass in the MATNR of a BOM that already exists I get an error back, because the MATNR already exists!
Inside 'CSAP_MAT_BOM_CREATE' it calls 'CS_BT_MASTB_READ', which then also calls 'GET_MAST' to check if it already exists (Which it does). If sy-subrc eq 0 (It has found the MATNR in MAST), it raises an error.
Where am I going wrong??? 😞
2014 Jul 02 9:56 AM
I can't find where raises error if sy-subrc = 0.
You wrote that matnr exist. Does exist also in plant data (MAST table) ?
2014 Jul 02 10:16 AM
Hi Jaroslaw,
I think I've got it! I've created an entirely new and very basic material for which the BOM was to be made from in MM01, and I think it has worked!
I realise now that if the material already exists as a BOM, then that MATNR can't be used to create a new BOM (Which is what I was testing before - It will exist in MAST), but if I create a very basic material in MM01, it won't exist in MAST and the check to see if it does exist already will fail (Which is correct).
Anyway, where I was originally going wrong was when I expected 'CSAP_MAT_BOM_CREATE' to also create the material you pass in on the exporting 'material' parameter. I now realise I need to create a basic and entirely new material that isn't used anywhere else beforehand which I will do.
Thank you so much for your help Jaroslaw 🙂