2008 May 19 10:04 PM
Hi experts,
I have a BOM with more than one level. Now I want to create a routing with the function module BAPI_ROUTING_CREATE. I can allocate operations to components/materials of the top level of the BOM without problems. But when I want to allocate operations to components/materials that are deeper in the BOM structure I get the message: "The component to be assigned has not been completely specified" (CPCC_DT No. 206).
The table componentallocation has the following information:
OPERATION_ID: the operation number from table OPERATION (alphanumeric)
BOM_NO: BOM number of top material as well as the subordinate BOM numbers
ITEM_ID: the BOM position number as in table STPO
BOM_NO_ROOT: the top BOM number
PATH: the value KANTE as in table STPO
Any help is highly appreciated.
Thanks and regards,
Stefan
2008 May 19 10:28 PM
Hello Stefen,
Try this code :
*&----
**& Author : *
**& Create date : 2007/04/03 *
**& Program type : Report *
**& Report name : ZPPPR_ROUTING_INPUT *
**& Description : ROUTING_INPUT *
**& FINISH ON : *
**& TRANSPROT REQUEST : *
*&----
REPORT zpppr_routing_input MESSAGE-ID zmc95
NO STANDARD PAGE HEADING "输出的报表不使用标准的页标题
LINE-SIZE 500. "输出的报表每页的字符宽度.
*---->define table->bapi
DATA: group TYPE bapi1012_tsk_c-task_list_group,
group_counter TYPE bapi1012_tsk_c-group_counter,
sequence_no TYPE bapi1012_opr_c-sequence_no,
task_list_usage TYPE bapi1012_tsk_c-task_list_usage,
task_list_status TYPE bapi1012_tsk_c-task_list_status,
lot_size_from TYPE bapi1012_tsk_c-lot_size_from,
lot_size_to TYPE bapi1012_tsk_c-lot_size_to,
task_measure_unit TYPE bapi1012_tsk_c-task_measure_unit,
application TYPE bapi1012_control_data-application,
testrun TYPE bapiflag,
profile TYPE bapi1012_control_data-profile,
bomusage TYPE bapi1012_control_data-bom_usage,
task TYPE bapi1012_tsk_c OCCURS 0 WITH HEADER LINE,
materialtaskallocation TYPE bapi1012_mtk_c OCCURS 0 WITH HEADER LINE,
sequence TYPE bapi1012_seq_c OCCURS 0 WITH HEADER LINE,
operation TYPE bapi1012_opr_c OCCURS 0 WITH HEADER LINE,
suboperation TYPE bapi1012_sub_opr_c OCCURS 0 WITH HEADER LINE,
referenceoperation TYPE bapi1012_ref_opr_c OCCURS 0 WITH HEADER LINE,
workcenterreference TYPE bapi1012_wc_ref_opr_c OCCURS 0 WITH HEADER LINE,
componentallocation TYPE bapi1012_com_c OCCURS 0 WITH HEADER LINE,
productionresource TYPE bapi1012_prt_c OCCURS 0 WITH HEADER LINE,
inspcharacteristic TYPE bapi1012_cha_c OCCURS 0 WITH HEADER LINE,
textallocation TYPE bapi1012_txt_hdr_c OCCURS 0 WITH HEADER LINE,
text TYPE bapi1012_txt_c OCCURS 0 WITH HEADER LINE,
return TYPE bapiret2 OCCURS 0 WITH HEADER LINE,
bapi_retn_info LIKE bapiret2 OCCURS 0 WITH HEADER LINE.
*---->message table
DATA: BEGIN OF t_error OCCURS 0.
DATA material LIKE bapi1012_mtk_c-material.
INCLUDE STRUCTURE bapiret2.
DATA: END OF t_error.
*---->inner table
DATA: BEGIN OF itab1 OCCURS 0 ,
material LIKE bapi1012_mtk_c-material,
plant LIKE bapi1012_mtk_c-plant,
description1 LIKE bapi1012_tsk_c-description,
activity LIKE bapi1012_opr_c-activity,
work_cntr LIKE bapi1012_opr_c-work_cntr,
control_key LIKE bapi1012_opr_c-control_key,
description LIKE bapi1012_opr_c-description,
base_quantity LIKE bapi1012_opr_c-base_quantity,
std_value_01 LIKE bapi1012_opr_c-std_value_01,
std_value_02 LIKE bapi1012_opr_c-std_value_02,
max_no_of_splits LIKE bapi1012_opr_c-max_no_of_splits,
FJS(2) TYPE C,
ind_splitting_reqrd LIKE bapi1012_opr_c-ind_splitting_reqrd,
required_overlapping LIKE bapi1012_opr_c-required_overlapping,
min_send_ahead_qty LIKE bapi1012_opr_c-min_send_ahead_qty,
ext_proc_with_subcontract_ind LIKE bapi1012_opr_c-ext_proc_with_subcontract_ind,
info_rec LIKE bapi1012_opr_c-info_rec,
purch_org LIKE bapi1012_opr_c-purch_org,
cost_elem LIKE bapi1012_opr_c-cost_elem,
COST_RELEVANT like bapi1012_opr_c-COST_RELEVANT,
END OF itab1.
DATA: BEGIN OF itab OCCURS 0 ,
material LIKE bapi1012_mtk_c-material,
plant LIKE bapi1012_mtk_c-plant,
description1 LIKE bapi1012_tsk_c-description,
activity LIKE bapi1012_opr_c-activity,
work_cntr LIKE bapi1012_opr_c-work_cntr,
control_key LIKE bapi1012_opr_c-control_key,
description LIKE bapi1012_opr_c-description,
base_quantity LIKE bapi1012_opr_c-base_quantity,
std_value_01 LIKE bapi1012_opr_c-std_value_01,
std_value_02 LIKE bapi1012_opr_c-std_value_02,
max_no_of_splits LIKE bapi1012_opr_c-max_no_of_splits,
ind_splitting_reqrd LIKE bapi1012_opr_c-ind_splitting_reqrd,
required_overlapping LIKE bapi1012_opr_c-required_overlapping,
min_send_ahead_qty LIKE bapi1012_opr_c-min_send_ahead_qty,
ext_proc_with_subcontract_ind LIKE bapi1012_opr_c-ext_proc_with_subcontract_ind,
info_rec LIKE bapi1012_opr_c-info_rec,
purch_org LIKE bapi1012_opr_c-purch_org,
cost_elem LIKE bapi1012_opr_c-cost_elem,
END OF itab.
DATA : gt_itab LIKE itab OCCURS 0 WITH HEADER LINE.
DATA : lv_cancel(1) TYPE c.
*---->upload
CALL FUNCTION 'UPLOAD'
EXPORTING
filename = 'C:\Documents and Settings\Administrator\Desktop\工艺路线.txt'
filetype = 'DAT'
IMPORTING
cancel = lv_cancel
TABLES
data_tab = itab1
EXCEPTIONS
conversion_error = 1
invalid_table_width = 2
invalid_type = 3
no_batch = 4
unknown_error = 5
gui_refuse_filetransfer = 6
OTHERS = 7.
IF lv_cancel EQ 'X'.
LEAVE PROGRAM.
ENDIF.
IF sy-subrc <> 0 .
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ELSEIF sy-subrc = 0.
SORT itab1 BY material plant activity.
LOOP AT ITAB1.
MOVE-CORRESPONDING ITAB1 TO ITAB.
CONDENSE ITAB1-FJS NO-GAPS.
ITAB-max_no_of_splits = ITAB1-FJS.
APPEND ITAB.
ENDLOOP.
SORT ITAB BY MATERIAL PLANT.
LOOP AT itab.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
input = itab-material
IMPORTING
output = itab-material.
MOVE itab TO gt_itab.
APPEND gt_itab.
*-----〉item-sequence
*operation-group_counter = '1'.
operation-activity = itab-activity.
operation-control_key = itab-control_key.
operation-work_cntr = itab-work_cntr.
operation-description = itab-description.
operation-plant = itab-plant.
operation-operation_measure_unit = 'EA'.
operation-denominator = 1.
operation-nominator = 1.
operation-base_quantity = itab-base_quantity.
operation-std_value_01 = itab-std_value_01.
operation-std_value_02 = itab-std_value_02.
operation-ind_splitting_reqrd = itab-ind_splitting_reqrd." 'X'."分解
operation-max_no_of_splits = itab-max_no_of_splits."'1'."分解数
operation-required_overlapping = itab-required_overlapping."'X'."要求重叠
operation-min_send_ahead_qty = itab-min_send_ahead_qty."'10'."最小发送数量
operation-ext_proc_with_subcontract_ind = itab-ext_proc_with_subcontract_ind."'X'.
operation-info_rec = itab-info_rec.
operation-purch_org = itab-purch_org.
operation-cost_elem = itab-cost_elem.
operation-COST_RELEVANT = 'X'."成本核算标示
APPEND operation.
AT END OF material.
*-----〉header
task-task_list_usage = '1'.
task-task_list_status = '4'.
**---->unit
select single MEINS into task-task_measure_unit
from mara
where matnr = gt_itab-material.
task-task_measure_unit = 'EA'.
task-description = gt_itab-description1."'TEST ROUTING'.
task-plant = gt_itab-plant.
task-valid_from = sy-datum.
task-valid_to_date = '99991231'.
APPEND task.
materialtaskallocation-material = gt_itab-material.
materialtaskallocation-plant = gt_itab-plant.
task-valid_from = sy-datum.
task-valid_to_date = '99991231'.
APPEND materialtaskallocation.
CALL FUNCTION 'BAPI_ROUTING_CREATE'
EXPORTING
testrun = testrun
profile = profile
bomusage = bomusage
application = application
IMPORTING
group = group
groupcounter = group_counter
TABLES
task = task
materialtaskallocation = materialtaskallocation
sequence = sequence
operation = operation
suboperation = suboperation
referenceoperation = referenceoperation
workcenterreference = workcenterreference
componentallocation = componentallocation
productionresource = productionresource
inspcharacteristic = inspcharacteristic
textallocation = textallocation
text = text
return = return.
REFRESH task.
REFRESH GT_ITAB.
REFRESH materialtaskallocation.
REFRESH operation.
LOOP AT return.
IF return-type EQ 'E' OR return-type EQ 'A'.
t_error-material = materialtaskallocation-material.
t_error-message = return-message.
APPEND t_error.
ELSE.
COMMIT WORK.
ENDIF.
ENDLOOP.
LOOP AT t_error.
WRITE:/ t_error-material,t_error-message.
ENDLOOP.
ENDAT.
ENDLOOP.
ENDIF.
模板
Link for this code is : http://silverw0396.javaeye.com/blog/90495http://silverw0396.javaeye.com/blog/monthblog/2007-04?show_...
This worked for me.
or
try this thread logic :
use FM BAPI_MATERIAL_BOM_GROUP_CREATE
Hope this answers your question.
Thanks,
Greetson
2008 May 19 10:44 PM
Hi Greetson,
Thanks a lot for your help. Unfortunately that code wouldn't work for me. I think that I need to have the table COMPONENTALLOCATION filled.
Did you ever try the function module CP_BD_DIRECT_INPUT_PLAN? It is mentioned in the thread that you sent me.
Thanks and best regards,
Stefan
2008 May 19 10:54 PM
Hi,
I didn't try that FM . If you fill COMPONENTALLOCATION it will work ...
Thanks,
Greetson
2008 May 19 11:02 PM
Hi Greetson,
That's exactly my problem. I don't know how the table COMPONENTALLOCATION has to be filled. All the operations that I try to allocate to a structure that are not on the top level of the BOM create the error.
I debugged the function module BAPI_ROUTING_CREATE and found out that only the top BOM is read in internal tables. My hope is that I can make the function module to read the complete BOM structure.
Do you have a hint?
Thanks and regards,
Stefan
2008 May 19 11:05 PM
Stefen,
Give a try by sending only the top level BOM to the FM and see what happens..
Greetson
2008 May 19 11:12 PM
Hi Greetson,
I already tried that. It works perfectly. The allocation of operations to components of BOM substructures is the only problem that I have.
Regards,
Stefan
2008 Aug 07 6:17 AM
hi ,Stefan
i have the similar question with you in the funtion
BAPI_ROUTING_CREATE in the component allocation
here i only need to allocate the top bom, but it dosn't work.
the source code :
componentallocation-sequence_no = '000000'.
componentallocation-valid_from = sy-datum.
componentallocation-valid_to_date = '99991230'.
componentallocation-activity = '0010'.
*componentallocation-OPERATION_ID = 'A0000001'.
componentallocation-material = 'R10-10'.
componentallocation-BACKFLUSH = 'X'.
componentallocation-plant = '1000'.
componentallocation-bom_no = '00000007'.
componentallocation-alternative_bom = '1'.
componentallocation-bom_type = 'M'.
componentallocation-COMP_QTY = '1'.
componentallocation-COMP_UNIT = 'EA'.
componentallocation-item_id = '00000001'.
componentallocation-item_no = '0010'.
componentallocation-bom_type_root = '1'.
componentallocation-bom_no_root = '00000007'.
*componentallocation-alternative_bom_root = '1'.
APPEND componentallocation.
could you share me your code ?
thank you in advance
Regards,
Edited by: xia chen on Aug 7, 2008 7:18 AM
2008 Aug 07 9:25 AM
Hi,
I didn't get it to work. So after creating the route I used the direct input function module CP_BD_DIRECT_INPUT_PLMZ to assign the components. It's probably not the best way but it worked. Check it out, maybe you can try it that way.
*&---------------------------------------------------------------------*
*& Form copy_mat_routing_plmz
*&---------------------------------------------------------------------*
* Kopieren der Komponentenzuordnung via Direct-Input
*----------------------------------------------------------------------*
form copy_mat_routing_plmz tables $t_prot type dt_prot
$t_bom_copy type dt_bom_copy
using value($w_plnnr) like mapl-plnnr
value($w_plnal) like mapl-plnal
value($w_mapl) type d_mat_mapl
value($w_color_old) structure t_colors
value($w_color_new) structure t_colors
value($w_matnr_new) like mara-matnr
$w_prot type d_prot
$w_counter type d_count.
data: %w_rc271 like rc271_di,
%w_rc27m like rc27m_di,
%w_save like save_di,
%w_plnnr type rc271-plnnr,
%w_acttyp type acttyp.
data: %w_plmz type plmz,
%w_plpo type plpo.
data: %t_plmz_di type plmz_di occurs 0 with header line,
%t_obj_null_field type obj_nfield occurs 0 with header line,
%t_error_di type error_di occurs 0 with header line,
%t_error type cmfmsg occurs 0 with header line,
%t_error_tmp type cmfmsg occurs 0 with header line.
data: %t_plmz like plmz occurs 0 with header line.
* Es muss eine neue Stückliste angelegt worden sein
check not ( %w_prot_marc_bom-stlnr is initial ).
* Arbeitsplan muss vorhanden sein
select count(*) into sy-dbcnt from plko
where plnty eq 'N'
and plnnr eq $w_plnnr
and plnal eq $w_plnal.
if sy-dbcnt gt 0.
* Es dürfen noch keine Zuordnungen vorhanden sein
select count(*) into sy-dbcnt from plmz
where plnty eq 'N'
and plnnr eq $w_plnnr
and plnal eq $w_plnal.
* Löschen der aktuellen Daten vorbereiten
if sy-dbcnt eq 0.
* Aktivitätstyp
%w_acttyp = 'H'.
* Einstiegsstruktur
clear %w_rc271.
%w_rc271-tcode = 'CA02'.
%w_rc271-sttag = p_stich.
%w_rc271-plnnr = $w_plnnr.
%w_rc271-plnal = $w_plnal.
* Arbeitsplan-Material
clear %w_rc27m.
* %w_rc27m-matnr = $w_matnr_new.
* %w_rc27m-werks = $w_mapl-mapl-werks.
* Save-Informationen
clear %w_save.
%w_save-syn_save = v_yes.
%w_save-no_save = p_test.
* Übergabedaten aufbereiten
* ...Komponentenzuordnung
_initt %t_plmz_di.
loop at $w_mapl-plmz into %w_plmz.
read table $w_mapl-plpo into %w_plpo
with key plnkn = %w_plmz-plnkn.
check sy-subrc eq 0.
%w_plmz-plnnr = $w_plnnr.
%w_plmz-datuv = p_stich.
perform get_new_stlnr tables $t_prot
$t_bom_copy
using $w_color_new
%w_plmz-stlnr
%w_plmz-stlnr.
perform get_new_stlnr tables $t_prot
$t_bom_copy
using $w_color_new
%w_plmz-stlnr_w
%w_plmz-stlnr_w.
clear %t_plmz_di.
move-corresponding %w_plmz to %t_plmz_di.
%t_plmz_di-acttyp = %w_acttyp.
%t_plmz_di-vorkn = %w_plpo-plnkn.
%t_plmz_di-vornr = %w_plpo-vornr.
%t_plmz_di-werks = $w_mapl-mapl-werks.
select idnrk into %t_plmz_di-matnr from stpo
where stlty eq %t_plmz_di-stlty
and stlnr eq %t_plmz_di-stlnr
and stlkn eq %t_plmz_di-stlkn.
endselect.
select matnr stlan into (%t_plmz_di-bomat, %t_plmz_di-stlan)
from mast
where stlnr eq %t_plmz_di-stlnr_w.
endselect.
append %t_plmz_di.
endloop.
* Fehlertabellen intialisieren
_initt: %t_error_di, %t_error.
* Plangruppe initialisieren
_initt %t_error_tmp.
call function 'CP_BD_DIRECT_INPUT_PLNGR'
exporting
rc271_di_imp = %w_rc271
rc27m_di_imp = %w_rc27m
tables
error_tab = %t_error_tmp.
append lines of %t_error_tmp to %t_error.
* Anlegen eines Arbeitsplans
_initt %t_error_tmp.
call function 'CP_BD_DIRECT_INPUT_PLMZ'
tables
plmz_di_tab = %t_plmz_di
null_field_tab = %t_obj_null_field
error_di_tab = %t_error_di
error_tab = %t_error_tmp
exceptions
no_inz = 1
others = 2.
append lines of %t_error_tmp to %t_error.
* Sichern der Zuordnung
_initt %t_error_tmp.
call function 'CP_BD_DIRECT_INPUT_SAVE'
exporting
save_di_imp = %w_save
tables
error_tab = %t_error_tmp
exceptions
no_inz = 1
others = 2.
append lines of %t_error_tmp to %t_error.
endif.
endif.
endform. " copy_mat_routing_plmz
Regards,
Stefan
2011 Sep 01 2:17 PM
Hi Stefan,
how could I download Your program text ? I have a similar problem and 'd like to try it .
Thanks a lot
KR Peter
2011 Sep 01 4:30 PM
Hi Greetson,
how could I download Your program text ? I have a similar problem and 'd like to try it .
Thanks a lot
KR Peter
2008 Oct 07 2:55 AM
Hello Stefen,
I have got it work about the BOM component allocation with more than one level,but there are still some problems that I'm not sure it will be very useful for you.Please check it out by yourself.
Also I created routing with the function module BAPI_ROUTING_CREATE and allocated the component with the direct input function module CP_BD_DIRECT_INPUT_PLMZ you supplied.When allocating the component which on more than one level in BOM,there are two fields in the structure plmz_di you should pay attention to.THAT is STLST and STLWG. This two fields are used to locate the component in the BOM.IF you assign the two fields correctly,the work will be done.And we can observe this two fields in T-CODE cs03->component allocation.But I haven't found how to confirm this two fields or the corresponding sap table they were stored.
Hope it is helpful for you.
Regards,
Leslie
2010 Jan 21 7:58 PM
Sorry for resurrecting an old thread, but has anyone figured out how to programmatically identify the level and path (STLST and STLWG) for a component?
2010 Jan 30 1:42 PM
Hi experts,
I have a requirement to assign the component allocation for routing.. used bapi_routing_create but its giving error..
Pls if you have coding for this let me know..
Thanks
Ramesh Manoharan
2010 Feb 01 3:35 PM
The COMPONENTALLOCATION-PATH field needs to be populated with the STPF-KANTE_K value for the component to be allocated. Unfortunately the STPF table isn't populated until the first time you try to allocate a component. If you call BAPI_ROUTING_CREATE once with COMPONENTALLOCATION-PATH blank you'll get an error but it will populate STPF. Then you can look up the KANTE_K value and call BAPI_ROUTING_CREATE again and it should work.
2010 Nov 15 10:36 AM
Have you populated the MATERIALTASKALLOCATION table?? I have seen at CA02 that without having a material(Here a BOM) allocated to an Operation, you cant allocate the components... Please check & let me know...
~Guru