SAP CA01/CA02 创建及更新工艺路线BAPI
前言
最近需要做一个routing的批导,初步查过资料后,发现下面几个BAPI:
BAPI_ROUTING_CREATE:最常用的BAPI,只支持创建,没有对应的CHANGE BAPI;
ROUTING_MAINTAIN:不支持创建,只支持更改;
CPCC_S_TASK_LIST_MAINTAIN:同时支持创建及更改。
刚好项目上的需求是既需要创建也需要变更,所以简单测试了下CPCC_S_TASK_LIST_MAINTAIN该如何传参来支持创建及更新。
正文
一开始写批导函数的时候,使用的是ROUTING_MAINTAIN,发现该函数没有提供task_maintain_mode参数,所以无法进行创建routing,但是里面调用的函数CPCC_S_TASK_LIST_MAINTAIN是支持这个参数的,所以就改用该函数来实现routing的创建及变更,关于函数的一些说明,也可以查看官方note:1558192。
测试的时候发现有几个小的注意点:
- task_maintain_mode(C创建,M变更,D删除);
- 如果是变更,需要给对应结构中的FLAG_BAR_POINTER字段赋值(如果有);
- sequence_no需要赋值000000;
- 工序字段operations-activity,如果要变更工序的编号(PLPO-VORNR),比如将10改为20,则需要给activity赋值为20,activity_old赋值为10,同时给activity打上'X'标记,否则无需打'X'标记,不然程序会判定以activity_old的值去找历史数据,如果未给activity_old传值的话就会报错;
- material_task_allocations结构是将物料工厂和工序绑定,需要传值,否则MAPL表中不会有数据。
工序相关底表
MAPL:分配工序给物料
PLKO:工序表头
PLAS:工序选择
PLPO :工序明细
测试源码
*&---------------------------------------------------------------------*
*& Form FRM_ROUTING_MAINTAIN
*&---------------------------------------------------------------------*
*& Using BAPI to maintain routing
*&---------------------------------------------------------------------*
FORM frm_routing_maintain USING us_req TYPE zprppsrouting_in
CHANGING cs_resp TYPE zprbcsrest_out.
DATA:
lv_maintain_mode TYPE cp_task_list_maint_mode,
lv_flag_bar TYPE cp_task_list_maint_pointer,
lv_change_no TYPE cps_task_list_maint_hdr-change_no,
lv_key_date TYPE cps_task_list_maint_hdr-key_date,
lv_task_list_group TYPE cps_task_list_maint_hdr-task_list_group,
lv_group_counter TYPE cps_task_list_maint_hdr-group_counter,
lv_material TYPE cps_task_list_maint_hdr-material,
lv_plant TYPE cps_task_list_maint_hdr-plant,
ls_task TYPE cps_task_list_maint_tsk,
ls_task_x TYPE cps_task_list_maint_tsk_x,
lv_bom_usage TYPE stlan,
lt_material_task TYPE cpt_task_list_maint_mtk,
ls_material_task TYPE cps_task_list_maint_mtk,
lt_material_task_x TYPE cpt_task_list_maint_mtk_x,
ls_material_task_x TYPE cps_task_list_maint_mtk_x,
lt_operations TYPE cpt_task_list_maint_opr,
ls_operations TYPE cps_task_list_maint_opr,
lt_operations_x TYPE cpt_task_list_maint_opr_x,
ls_operations_x TYPE cps_task_list_maint_opr_x,
lt_return TYPE bapiret2_t,
ls_return TYPE bapiret2.
* Head data
lv_change_no = us_req-head-aennr.
lv_key_date = us_req-head-datuv.
lv_task_list_group = us_req-head-plnnr.
lv_group_counter = us_req-head-plnal.
lv_material = us_req-head-matnr.
lv_plant = us_req-head-werks.
IF us_req-head-plnnr IS INITIAL.
lv_maintain_mode = 'C'.
ELSE.
lv_maintain_mode = 'M'.
ENDIF.
IF us_req-head-verwe IS NOT INITIAL.
ls_task-task_list_usage = us_req-head-verwe.
ls_task_x-task_list_usage = abap_true.
ENDIF.
IF us_req-head-werks IS NOT INITIAL.
ls_task-plant = us_req-head-werks.
ls_task_x-plant = abap_true.
ENDIF.
IF us_req-head-statu IS NOT INITIAL.
ls_task-task_list_status = us_req-head-statu.
ls_task_x-task_list_status = abap_true.
ENDIF.
IF us_req-head-plnme IS NOT INITIAL.
ls_task-task_measure_unit = us_req-head-plnme.
ls_task_x-task_measure_unit = abap_true.
ENDIF.
IF us_req-head-ktext IS NOT INITIAL.
ls_task-description = us_req-head-ktext.
ls_task_x-description = abap_true.
ENDIF.
IF us_req-head-loekz_plko IS NOT INITIAL.
ls_task-del_flag = us_req-head-loekz_plko.
ls_task_x-del_flag = abap_true.
ENDIF.
ls_task-lot_size_to = '99999999'.
ls_task_x-lot_size_to = abap_true.
IF lv_maintain_mode = 'C'.
CLEAR ls_task_x.
* Material routing assignment
ls_material_task-maintain_mode = lv_maintain_mode.
ls_material_task-material = us_req-head-matnr.
ls_material_task-plant = us_req-head-werks.
APPEND ls_material_task TO lt_material_task.
ENDIF.
* Operations
LOOP AT us_req-operations INTO DATA(ls_operations_in).
ls_operations-maintain_mode = ls_operations_in-maintain_mode.
ls_operations-sequence_no = '000000'.
IF ls_operations_in-maintain_mode = 'M'.
ADD 1 TO lv_flag_bar.
ls_operations-flag_bar_pointer = lv_flag_bar.
ENDIF.
* If the maintain_mode was 'M', and you set the flag abap_true for it,
* The system considers the current activity is new value,at the same time,
* You nedd set the original value for the fields 'ACTIVITY_OLD'
ls_operations-activity = ls_operations_in-vornr.
IF ls_operations_in-arbpl IS NOT INITIAL.
ls_operations-work_cntr = ls_operations_in-arbpl.
ls_operations_x-work_cntr = abap_true.
ENDIF.
IF us_req-head-werks IS NOT INITIAL.
ls_operations-plant = us_req-head-werks.
ls_operations_x-plant = abap_true.
ENDIF.
IF ls_operations_in-steus IS NOT INITIAL.
ls_operations-control_key = ls_operations_in-steus.
ls_operations_x-control_key = abap_true.
ENDIF.
IF ls_operations_in-ktsch IS NOT INITIAL.
ls_operations-standard_text_key = ls_operations_in-ktsch.
ls_operations_x-standard_text_key = abap_true.
ENDIF.
IF ls_operations_in-ltxa1 IS NOT INITIAL.
ls_operations-description = ls_operations_in-ltxa1.
ls_operations_x-description = abap_true.
ENDIF.
IF ls_operations_in-vgw01 IS NOT INITIAL.
ls_operations-std_unit_01 = ls_operations_in-vge01.
ls_operations_x-std_unit_01 = abap_true.
ls_operations-std_value_01 = ls_operations_in-vgw01.
ls_operations_x-std_value_01 = abap_true.
ENDIF.
IF ls_operations_in-vgw02 IS NOT INITIAL.
ls_operations-std_unit_02 = ls_operations_in-vge01.
ls_operations_x-std_unit_02 = abap_true.
ls_operations-std_value_02 = ls_operations_in-vgw02.
ls_operations_x-std_value_02 = abap_true.
ENDIF.
IF ls_operations_in-vgw03 IS NOT INITIAL.
ls_operations-std_unit_03 = ls_operations_in-vge01.
ls_operations_x-std_unit_03 = abap_true.
ls_operations-std_value_03 = ls_operations_in-vgw03.
ls_operations_x-std_value_03 = abap_true.
ENDIF.
IF ls_operations_in-vgw04 IS NOT INITIAL.
ls_operations-std_unit_04 = ls_operations_in-vge01.
ls_operations_x-std_unit_04 = abap_true.
ls_operations-std_value_04 = ls_operations_in-vgw04.
ls_operations_x-std_value_04 = abap_true.
ENDIF.
IF ls_operations_in-vgw05 IS NOT INITIAL.
ls_operations-std_unit_05 = ls_operations_in-vge01.
ls_operations_x-std_unit_05 = abap_true.
ls_operations-std_value_05 = ls_operations_in-vgw05.
ls_operations_x-std_value_05 = abap_true.
ENDIF.
IF ls_operations_in-vgw06 IS NOT INITIAL.
ls_operations-std_unit_06 = ls_operations_in-vge01.
ls_operations_x-std_unit_06 = abap_true.
ls_operations-std_value_06 = ls_operations_in-vgw06.
ls_operations_x-std_value_06 = abap_true.
ENDIF.
IF ls_operations_in-bmsch IS NOT INITIAL.
ls_operations-base_quantity = ls_operations_in-bmsch.
ls_operations_x-base_quantity = abap_true.
ENDIF.
IF ls_operations_in-meinh IS NOT INITIAL.
ls_operations-operation_measure_unit = ls_operations_in-meinh.
ls_operations_x-operation_measure_unit = abap_true.
ENDIF.
IF ls_operations_in-umren IS NOT INITIAL.
ls_operations-denominator = ls_operations_in-umren.
ls_operations_x-denominator = abap_true.
ENDIF.
IF ls_operations_in-umrez IS NOT INITIAL.
ls_operations-nominator = ls_operations_in-umrez.
ls_operations_x-nominator = abap_true.
ENDIF.
IF ls_operations_in-infnr IS NOT INITIAL.
ls_operations-info_rec = ls_operations_in-infnr.
ls_operations_x-info_rec = abap_true.
ENDIF.
IF ls_operations_in-ekorg IS NOT INITIAL.
ls_operations-purch_org = ls_operations_in-ekorg.
ls_operations_x-purch_org = abap_true.
ENDIF.
IF ls_operations_in-plifz IS NOT INITIAL.
ls_operations-plnd_delry = ls_operations_in-plifz.
ls_operations_x-plnd_delry = abap_true.
ENDIF.
IF ls_operations_in-sortl IS NOT INITIAL.
ls_operations-sorted_by = ls_operations_in-sortl.
ls_operations_x-sorted_by = abap_true.
ENDIF.
IF ls_operations_in-matkl IS NOT INITIAL.
ls_operations-matl_group = ls_operations_in-matkl.
ls_operations_x-matl_group = abap_true.
ENDIF.
IF ls_operations_in-ckselkz IS NOT INITIAL.
ls_operations-cost_relevant = ls_operations_in-ckselkz.
ls_operations_x-cost_relevant = abap_true.
ENDIF.
IF ls_operations_in-sakto IS NOT INITIAL.
ls_operations-cost_elem = ls_operations_in-sakto.
ls_operations_x-cost_elem = abap_true.
ENDIF.
IF ls_operations_in-frdlb IS NOT INITIAL.
ls_operations-ext_proc_with_subcontract_ind = ls_operations_in-frdlb.
ls_operations_x-ext_proc_with_subcontract_ind = abap_true.
ENDIF.
APPEND ls_operations TO lt_operations.
APPEND ls_operations_x TO lt_operations_x.
CLEAR:
ls_operations,
ls_operations_x.
ENDLOOP.
**********************************************************************
* Function 'ROUTING_MAINTAIN' can't import maintain_mode,you can only
* use it to modify routing,if you wan't create & change routing,you
* can use below function.
**********************************************************************
CALL FUNCTION 'CPCC_S_TASK_LIST_MAINTAIN'
EXPORTING
change_no = lv_change_no
key_date = lv_key_date
task_list_type = 'N'
task_list_group = lv_task_list_group
group_counter = lv_group_counter
material = lv_material
plant = lv_plant
task_maintain_mode = lv_maintain_mode
task = ls_task
task_x = ls_task_x
* APPLICATION =
* BOM_USAGE =
TABLES
material_task_allocations = lt_material_task
material_task_allocations_x = lt_material_task_x
* SEQUENCES =
* SEQUENCES_X =
operations = lt_operations
operations_x = lt_operations_x
* SUBOPERATIONS =
* SUBOPERATIONS_X =
* PRODUCTION_RESOURCES_TOOLS =
* PRODUCTION_RESOURCES_TOOLS_X =
* COMPONENT_ALLOCATIONS =
* COMPONENT_ALLOCATIONS_X =
* INSPECTION_CHARACTERISTICS =
* INSPECTION_CHARACTERISTICS_X =
* INSPECTION_VALUES =
* INSPECTION_VALUES_X =
* REFERENCED_OPERATIONS =
* TEXT =
* TEXT_ALLOCATIONS =
return = lt_return
* SEGMENT_TASK_MAINTAIN =
.
LOOP AT lt_return INTO ls_return
WHERE type CA 'EAX'.
cs_resp-msgty = 'E'.
CONCATENATE cs_resp-msgtx ls_return-message INTO cs_resp-msgtx.
ENDLOOP.
IF cs_resp-msgtx IS INITIAL.
cs_resp-msgty = 'S'.
LOOP AT lt_return INTO ls_return
WHERE type = 'S'
AND ( number = '059' OR number = '068' ).
cs_resp-msgtx = ls_return-message.
EXIT.
ENDLOOP.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = 'X'.
ELSE.
CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
ENDIF.
ENDFORM.