在PP模块中,关于批量创建工艺路线或者修改的操作我们经常会用到。事务代码是CA01/CA02,
对应的创建BAPI名为:BAPI_ROUTING_CREATE
今天我们一起学习一下这个bapi demo。
导入参数:
参数名称 | 关联类型 | 可选的 | 说明 |
TESTRUN | BAPIFLAG | 可选 | 标记,测试或提交系统 |
PROFILE | BAPI1012_CONTROL_DATA-PROFILE | 可选 | 参数文件 |
BOMUSAGE | BAPI1012_CONTROL_DATA-BOM_USAGE | 可选 | BOM 用途 |
APPLICATION | BAPI1012_CONTROL_DATA-APPLICATION | 可选 | 应用程序 |
表:
参数名称 | 关联类型 | 可选的 | 说明 |
TASK | BAPI1012_TSK_C | 必选 | 任务清单头数据 |
MATERIALTASKALLOCATION | BAPI1012_MTK_C | 可选 | 物料任务清单分配 |
SEQUENCE | BAPI1012_SEQ_C | 可选 | 任务清单序列 |
OPERATION | BAPI1012_OPR_C | 可选 | 工序 |
COMPONENTALLOCATION | BAPI1012_COM_C | 可选 | 组件分配 |
RETURN | BAPIRET2 | 可选 | 返回参数 |
字段名 | 类型 | 简短描述 |
TASK_LIST_GROUP | PLNNR | 任务清单组键值 |
VALID_FROM | DATUV | 有效起始日期 |
VALID_TO_DATE | DATUB | 有效截止日期 |
PLANT | WERKS_D | 工厂 |
TASK_LIST_STATUS | PLNST | 状态 |
TASK_MEASURE_UNIT | PLNME | 任务清单计量单位 |
TASK_MEASURE_UNIT_ISO | ISOCD_UNIT | 计量单位的 ISO 代码 |
LOT_SIZE_FROM | LOSVN | 从批量 |
LOT_SIZE_TO | LOSBS | 到批量 |
DESCRIPTION | PLANTEXT | 描述 |
字段名 | 类型 | 简短描述 |
MATERIAL | MATNR18 | 物料编号(18个字符) |
PLANT | WERKS_D | 工厂 |
VALID_FROM | DATUV | 有效起始日期 |
VALID_TO_DATE | DATUB | 有效截止日期 |
SEQUENCE:
字段名 | 类型 | 简短描述 |
SEQUENCE_NO | PLNFOLGE | 序列 |
VALID_FROM | DATUV | 有效起始日期 |
VALID_TO_DATE | DATUB | 有效截止日期 |
SEQUENCE_CATEGORY | FOLGENART | 顺序类别 |
DESCRIPTION | FLGTEXT | 顺序描述 |
LOT_SZ_MIN | CP_FLGLOSV | 最小批量 |
LOT_SZ_MAX | CP_FLGLOSB | 最大批量 |
TASK_MEASURE_UNIT | PLNME | 任务清单计量单位 |
TASK_MEASURE_UNIT_ISO | ISOCD_UNIT | 计量单位的 ISO 代码 |
ALIGNMENT_KEY_FOR_SCHEDULING | CP_AUSCHL | 计划校准码 |
Operation参数:
字段名 | 类型 | 简短描述 |
SEQUENCE_NO | PLNFOLGE | 序列 |
VALID_FROM | DATUV | 有效起始日期 |
VALID_TO_DATE | DATUB | 有效截止日期 |
ACTIVITY | VORNR | 操作/活动编号 |
CONTROL_KEY | STEUS | 控制码 |
WORK_CNTR | ARBPL | 工作中心 |
PLANT | WERKS_D | 工厂 |
DESCRIPTION | LTXA1 | 工序短文本 |
DENOMINATOR | CP_UMREN | 用于转换工艺路线和工序单位的分母 |
NOMINATOR | CP_UMREZ | 用于转换工艺路线和运营计量单位的分子 |
BASE_QUANTITY | BMSCH | 基本数量 |
STD_VALUE_01 | VGWRT | 标准值 |
IND_SPLITTING_REQRD | SPLITTUNG | 需要拆分 |
MAX_NO_OF_SPLITS | SPLITTANZ | 最大拆分数 |
USERFIELDS_KEYWORD_ID | SLWID | 关键词 ID 用于 PS 用户定义字段 |
USERFIELD_CH20_00 | USRCHAR20 | 20 个字符的用户字段 |
USERFIELD_QUAN_04 | USRQUAN13 | 用户字段数量(长度10.3) |
如下是demo代码,作为HOT583.com的码农,多年前也是SAP ABAP beginners ,最开始学习会有些难度,
到处去找Tutorial for Constant。如下是详细代码:
TABLES:mara,makt,mapl.
************************************************************************
*DATA
*Modified: add group,group_counter into wa_stru.
************************************************************************
TYPES: BEGIN OF ws_stru,
matnr(018) TYPE c,“物料编码
werks(004) TYPE c,“工厂
group(008) TYPE c,“任务清单组码
groupcounter(002) TYPE c,“组计数器
activity(004) TYPE c,“作业序号
control_key(004) TYPE c,“控制##
work_cntr(008) TYPE c,“工作中心
description(40) TYPE c,“工序描述
base_quantity(13) TYPE c,“基本数量
prepare(009) TYPE c,“准备时间
labor(009) TYPE c,“人工工时-排产时间
machine(009) TYPE c,“机器工时-能力时间
power(009) TYPE c,“动力
maintain(009) TYPE c,“维修
other(009) TYPE c,“其他
split(001) TYPE c,“所需分解
split_num(003) TYPE c,“分解数
keyword(007) TYPE c,“字段码
workshop(20) TYPE c,“车间
class1(20) TYPE c,“班组1
class2(10) TYPE c,“班组2
class3(10) TYPE c,“班组3
convers(13) TYPE c,“转换率
END OF ws_stru.
DATA: wt_stru TYPE ws_stru,
wt_itab TYPE TABLE OF ws_stru WITH HEADER LINE.
DATA: wv_string TYPE string.
DATA: BEGIN OF wt_out OCCURS 0,
line(600),
END OF wt_out.
*创建BAPI
DATA: BEGIN OF task OCCURS 0.
INCLUDE STRUCTURE bapi1012_tsk_c.
DATA: END OF task.
DATA: BEGIN OF materialtaskallocation OCCURS 0.
INCLUDE STRUCTURE bapi1012_mtk_c.
DATA: END OF materialtaskallocation.
DATA: BEGIN OF sequence OCCURS 0.
INCLUDE STRUCTURE bapi1012_seq_c.
DATA: END OF sequence.
DATA: BEGIN OF operation OCCURS 0.
INCLUDE STRUCTURE bapi1012_opr_c.
DATA: END OF operation.
DATA: BEGIN OF componentallocation OCCURS 0.
INCLUDE STRUCTURE bapi1012_com_c.
DATA: END OF componentallocation.
DATA: BEGIN OF return OCCURS 0.
INCLUDE STRUCTURE bapiret2.
DATA: END OF return.
DATA: group TYPE bapi1012_tsk_c-task_list_group,
groupcounter TYPE bapi1012_tsk_c-group_counter,
testrun TYPE bapiflag,
profile LIKE bapi1012_control_data-profile,
bomusage LIKE bapi1012_control_data-bom_usage,
application LIKE bapi1012_control_data-application.
DATA: line TYPE i.
DATA: bdcdata LIKE bdcdata OCCURS 0 WITH HEADER LINE.
DATA: messtab LIKE bdcmsgcoll OCCURS 0 WITH HEADER LINE.
************************************************************************
* Selection Screen
************************************************************************
SELECTION-SCREEN BEGIN OF BLOCK block3 WITH FRAME TITLE text-b02.
PARAMETER: p_file LIKE konsparam-pcu40_file OBLIGATORY,
begcol TYPE i DEFAULT 1 NO-DISPLAY,
begrow TYPE i DEFAULT 1 NO-DISPLAY,
endcol TYPE i DEFAULT 100 NO-DISPLAY,
endrow TYPE i DEFAULT 32000 NO-DISPLAY.
SELECTION-SCREEN END OF BLOCK block3.
************************************************************************
* At Selection Screen
************************************************************************
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
*获得导入数据的文本名
PERFORM get_file.
TOP-OF-PAGE.
************************************************************************
* Start of Selection
************************************************************************
START-OF-SELECTION.
* 获取数据从EXCEL文件
PERFORM get_txt. “Upload data into itabwww.hot583.com
* 创建工艺路线
PERFORM bapi_create TABLES wt_itab.
END-OF-SELECTION.
*&———————————————————————*
*& Form GET_TXT
*&———————————————————————*
FORM get_txt .
DATA: BEGIN OF wlt_intab OCCURS 0.
INCLUDE STRUCTURE alsmex_tabline.
DATA: END OF wlt_intab.
CALL FUNCTION ‘UPLOAD’
EXPORTING
filename = p_file
filetype = ‘DAT’
TABLES
data_tab = wt_itab
EXCEPTIONS
conversion_error = 1
invalid_table_width = 2
invalid_type = 3
no_batch = 4
unknown_error = 5
gui_refuse_filetransfer = 6
OTHERS = 7.
IF sy-subrc <> 0.
WRITE:/ ,’上载数据出错’.
ENDIF.
*按工厂与物料排序
SORT wt_itab BY matnr werks.
ENDFORM. “ GET_TXT
*&———————————————————————*
*& Form GET_FILE
*&———————————————————————*
FORM get_file .
CALL FUNCTION ‘WS_FILENAME_GET’ “Get file name
EXPORTING
* DEF_FILENAME = ‘ ‘
* DEF_PATH = ‘ ‘
mask = ‘,*.* ,*.*.’
mode = ‘0’
title = ‘Get File name’
IMPORTING
filename = p_file
* RC =
EXCEPTIONS
inv_winsys = 1
no_batch = 2
selection_cancel = 3
selection_error = 4
OTHERS = 5.
IF sy-subrc <> 0.
* MESSAGE E016 WITH P_PATH.
ENDIF.
ENDFORM. “ GET_FILE
*&———————————————————————*
*& Form GET_DATA
*&———————————————————————*
FORM bapi_create TABLES p_wt_itab STRUCTURE wt_itab.
DATA: unit LIKE mara-meins,
maktx LIKE makt-maktx,
matnr LIKE mara-matnr.
LOOP AT p_wt_itab.
AT NEW werks.
CLEAR: unit,maktx,matnr.
FREE: task,materialtaskallocation,sequence,operation.
SELECT SINGLE meins matnr
INTO (unit, matnr)
FROM mara
WHERE matnr = p_wt_itab-matnr.
SELECT SINGLE maktx
INTO maktx
FROM makt
WHERE matnr = p_wt_itab-matnr
AND spras = ‘1’.
READ TABLE p_wt_itab INDEX sy-tabix.
task-valid_from = sy-datum.
task-valid_to_date = ‘99991231’.
task-task_list_group = p_wt_itab-group.
task-group_counter = p_wt_itab-groupcounter.
task-task_list_usage = ‘1’.
task-plant = p_wt_itab-werks.
task-task_list_status = ‘4’.
task-lot_size_from = 0.
task-lot_size_to = 999999999.
task-task_measure_unit = unit.
task-task_measure_unit_iso = unit.
task-description = maktx.
APPEND task.
materialtaskallocation-plant = p_wt_itab-werks.
materialtaskallocation-valid_to_date = ‘99991231’.
materialtaskallocation-valid_from = sy-datum.
materialtaskallocation-material = p_wt_itab-matnr.
APPEND materialtaskallocation.
sequence-sequence_no = ‘000000’.
sequence-valid_from = sy-datum.
sequence-valid_to_date = ‘99991231’.
sequence-sequence_category = ‘0’.
sequence-description = ‘标准工序’.
sequence-lot_sz_min = 0.
sequence-lot_sz_max = 999999999.
sequence-alignment_key_for_scheduling = ‘2’.
sequence-task_measure_unit = unit.
sequence-task_measure_unit_iso = unit.
APPEND sequence.
ENDAT.
operation-sequence_no = ‘000000’.
operation-valid_from = sy-datum.
operation-valid_to_date = ‘99991231’.
line = STRLEN( p_wt_itab-activity ).
CASE line.
WHEN 1.
CONCATENATE ‘000’ p_wt_itab-activity
INTO p_wt_itab-activity.
WHEN 2.
CONCATENATE ’00’ p_wt_itab-activity
INTO p_wt_itab-activity.
WHEN 3.
CONCATENATE ‘0’ p_wt_itab-activity
INTO p_wt_itab-activity.
ENDCASE.
operation-activity = p_wt_itab-activity.
* OPERATION-OPERATION_ID = F_DATA_TAB-OPERATION.
operation-control_key = p_wt_itab-control_key.
* OPERATION-STANDARD_TEXT_KEY = P_WT_ITAB-STANDTEXT.
operation-work_cntr = p_wt_itab-work_cntr.
operation-plant = p_wt_itab-werks.
operation-description = p_wt_itab-description.
operation-denominator = 1.
operation-nominator = 1.
operation-cost_relevant = ‘X’.
operation-base_quantity = p_wt_itab-base_quantity.
operation-std_value_01 = p_wt_itab-prepare.
operation-std_value_02 = p_wt_itab-labor.
operation-std_value_03 = p_wt_itab-machine.
operation-std_value_04 = p_wt_itab-power.
operation-std_value_05 = p_wt_itab-maintain.
operation-std_value_06 = p_wt_itab-other.
operation-ind_splitting_reqrd = p_wt_itab-split.
operation-max_no_of_splits = p_wt_itab-split_num.
operation-userfields_keyword_id = p_wt_itab-keyword.
operation-userfield_ch20_00 = p_wt_itab-workshop.
operation-userfield_ch20_01 = p_wt_itab-class1.
operation-userfield_ch10_02 = p_wt_itab-class2.
operation-userfield_ch10_03 = p_wt_itab-class3.
operation-userfield_quan_04 = p_wt_itab-convers.
APPEND operation.
CLEAR operation.
AT END OF werks.
PERFORM delete_routing USING p_wt_itab-matnr p_wt_itab-werks p_wt_itab-groupcounter .
PERFORM creat_routing USING p_wt_itab-matnr p_wt_itab-werks .
ENDAT.
ENDLOOP.
ENDFORM. “ GET_DATA
*&———————————————————————*
*& Form CREAT_ROUTING
*&———————————————————————*
FORM creat_routing USING matnr
werks.
CALL FUNCTION ‘BAPI_ROUTING_CREATE’
EXPORTING
testrun = testrun
profile = profile
bomusage = bomusage
application = application
IMPORTING
group = group
groupcounter = groupcounter
TABLES
task = task
materialtaskallocation = materialtaskallocation
sequence = sequence
operation = operation
componentallocation = componentallocation
return = return.
COMMIT WORK.
DESCRIBE TABLE return LINES line.
IF line = 1.
READ TABLE return INDEX 1.
IF return-type = ‘S’ AND return-id = ‘BAPI’ AND
return-number = ‘000’.
WRITE:/ matnr,return-message_v2,’SUCCEED’.
ELSE.
WRITE:/ matnr,’Fail,Please check the material’.
ENDIF.
ELSE.
WRITE:/ matnr COLOR COL_NEGATIVE,
‘Fail,Please check the material’.
* / return-fields..
ENDIF.
ENDFORM. “ CREAT_ROUTING
*&———————————————————————*
*& Form DELETE_ROUTING
*&———————————————————————*
FORM delete_routing USING matnr
werks
groupcounter.
CLEAR bdcdata.
REFRESH bdcdata.
CLEAR messtab.
REFRESH messtab.
SELECT SINGLE * FROM mapl WHERE matnr = matnr AND werks = werks AND plnal = groupcounter
AND loekz <> ‘X’ AND plnty = ‘N’.
IF sy-subrc = 0.
PERFORM bdc_dynpro USING ‘SAPLCPDI’ ‘1010’.
PERFORM bdc_field USING ‘BDC_OKCODE’ ‘=ALUE’.
PERFORM bdc_field USING ‘RC27M-MATNR’ matnr.
PERFORM bdc_field USING ‘RC27M-WERKS’ werks.
PERFORM bdc_field USING ‘RC271-PLNNR’ mapl-plnnr.
PERFORM bdc_dynpro USING ‘SAPLCPDI’ ‘1200’.
PERFORM bdc_field USING ‘BDC_OKCODE’ ‘=LOE’.
PERFORM bdc_field USING ‘RC27X-ENTRY_ACT’ ‘1’.
PERFORM bdc_dynpro USING ‘SAPLSPO1’ ‘0100’.
PERFORM bdc_field USING ‘BDC_OKCODE’ ‘=YES’.
PERFORM bdc_dynpro USING ‘SAPLCPDI’ ‘1200’.
PERFORM bdc_field USING ‘BDC_OKCODE’ ‘=BU’.
CALL TRANSACTION ‘CA02’ USING bdcdata
MODE ‘N’
UPDATE ‘L’
MESSAGES INTO messtab.
IF sy-subrc <> 0.
WRITE:/ matnr COLOR COL_NEGATIVE, ‘have not deleted’.
ENDIF.
ENDIF.
ENDFORM. “ DELETE_ROUTING
*———————————————————————-*
* Start new screen *
*———————————————————————-*
FORM bdc_dynpro USING program dynpro.
CLEAR bdcdata.
bdcdata-program = program.
bdcdata-dynpro = dynpro.
bdcdata-dynbegin = ‘X’.
APPEND bdcdata.
ENDFORM. “BDC_DYNPRO
*———————————————————————-*
* Insert field *
*———————————————————————-*
FORM bdc_field USING fnam fval.
CLEAR bdcdata.
bdcdata-fnam = fnam.
bdcdata-fval = fval.
APPEND bdcdata.
ENDFORM. “BDC_FIELD
本文链接 :http://www.hot583.com/2022/05/28/bapi_routing_create/
本文为作者原创,如果这篇文章对您有用,欢迎转载,
转载请务必注明来源《今日热点在看》http://www.hot583.com/
我的微信公众号【 hot583 】 或者在这个链接联系我
微信原文《全文完》