*&---------------------------------------------------------------------* *& Report YCX_QP01 *&---------------------------------------------------------------------* *BAPI_INSPECTIONPLAN_CREATE 该函数主要用于检验的创建,对应于事物代码为QP01。 * *&---------------------------------------------------------------------* REPORT ycx_qp01. PARAMETERS: p_werks LIKE t001w-werks DEFAULT '8047', p_matnr LIKE mara-matnr. "105331 DATA: lt_task LIKE TABLE OF bapi1191_tsk_c WITH HEADER LINE, "检验计划数据 lt_materialtaskallocation LIKE TABLE OF bapi1191_mtk_c WITH HEADER LINE, "物料分配数据 lt_operation LIKE TABLE OF bapi1191_opr_c WITH HEADER LINE, "工序数据 lt_inspection LIKE TABLE OF bapi1191_cha_c WITH HEADER LINE, "检验特性数据 lt_textloc LIKE TABLE OF bapi1191_txt_hdr_c WITH HEADER LINE, "CREATE-BAPI 中的文本分配用于检验计划 lt_text LIKE TABLE OF bapi1012_txt_c WITH HEADER LINE, "工艺路线 CREATE-BAPI 中长文本行 lt_return LIKE TABLE OF bapiret2 WITH HEADER LINE, "返回参数 * ls_task LIKE bapi1191_tsk_c, * ls_material LIKE bapi1191_mtk_c, ls_operation LIKE bapi1191_opr_c, * ls_inspection LIKE bapi1191_cha_c, * ls_textloc LIKE bapi1191_txt_hdr_c, * ls_text LIKE bapi1012_txt_c, ls_bapiret2 LIKE bapiret2, ls_bapiret LIKE bapiret2. DATA: lv_group LIKE bapi1191_tsk_c-task_list_group, lv_counter LIKE bapi1191_tsk_c-group_counter. DATA: ls_result TYPE zbqms007, lt_result LIKE TABLE OF zbqms007. *IF gs_zmaterielh-quality_view = 'X' AND gs_zmaterieli-art = '01' AND gs_zmaterieli-aktiv = 'X' AND ls_mapl IS INITIAL. DATA: lv_meins TYPE mara-meins. CALL FUNCTION 'CONVERSION_EXIT_CUNIT_INPUT' "单位转换 EXPORTING input = 'KG' * LANGUAGE = SY-LANGU IMPORTING output = lv_meins EXCEPTIONS unit_not_found = 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. ENDIF. " CREATE_BAPI 中的物料任务清单用于检验计划 CLEAR lt_materialtaskallocation[]. lt_materialtaskallocation-material = p_matnr. " 物料编码 lt_materialtaskallocation-plant = p_werks. "'8047'.工厂 lt_materialtaskallocation-valid_from = sy-datum."有效起始日期 APPEND lt_materialtaskallocation. " CREATE-BAPI 中的任务清单抬头数据用于检验计划 * CLEAR lt_task[]. lt_task-valid_from = '20201201'. "有效起始日期 * lt_task-DESCRIPTION = F_MAKTG. "物料描述 lt_task-task_list_usage = '5'. "用途 lt_task-task_list_status = '4'. "状态 lt_task-lot_size_from = '0'. "从批量 lt_task-lot_size_to = '9999999999'. "到批量 lt_task-planning_work_center = ''. "计划员组 lt_task-plant = p_werks. "工厂 lt_task-task_measure_unit = lv_meins. "单位 lt_task-dyn_modif_level = '0'. APPEND lt_task. " CREATE-BAPI 中的工序用于检验批 * CLEAR Lt_operation[]. lt_operation-valid_from = '20201201'. "有效起始日期 lt_operation-activity = '1'. "操作/活动编号 lt_operation-plant = p_werks. "工厂 lt_operation-control_key = 'QM01'. "控制码 lt_operation-work_cntr = ''. "工作中心 lt_operation-standard_text_key = ''. "标准文本码 lt_operation-description = '质量检验'. "工序短文本 lt_operation-operation_measure_unit = lv_meins . "作业/工序的计量单位 lt_operation-denominator = '1'. "用于转换工艺路线和工序单位的分母 lt_operation-nominator = '1'. "用于转换任务清单和工序计量单位的计数器 lt_operation-base_quantity = '1.000'. "基本数量 APPEND lt_operation. " 检验计划 CREATE-BAPI 中的检验特性 * CLEAR lt_inspection[]. lt_inspection-activity = '1'. "操作/活动编号 lt_inspection-inspchar = '0010'. "检验特性编号 lt_inspection-valid_from = '20201201'. "有效起始日期 lt_inspection-mstr_char = 'COLOR1'." 'M0000001'. "主文件检验特性 lt_inspection-pmstr_char = 'Q100'. "工厂 lt_inspection-smpl_procedure = '000BQL01'. " 检验特性中的采样程序 lt_inspection-smpl_unit = lv_meins. " 采样计量单位 lt_inspection-smpl_quant = '1.00'. " 采样的采样数量因子(多重采样计量单位) lt_inspection-cha_master_import_modus = 'C'. " 参考主文件检验特性的方式 APPEND lt_inspection. DATA: l_flag TYPE char1 . CLEAR l_flag . IF lt_materialtaskallocation IS NOT INITIAL. CALL FUNCTION 'BAPI_INSPECTIONPLAN_CREATE' "创建检验计划 * EXPORTING * TESTRUN = ' ' * PROFILE = IMPORTING group = lv_group groupcounter = lv_counter TABLES task = lt_task materialtaskallocation = lt_materialtaskallocation operation = lt_operation * REFERENCEOPERATION = * PRODUCTIONRESOURCE = inspcharacteristic = lt_inspection * TEXTALLOCATION = * TEXT = return = lt_return * INSP_CHAR_VALUES = . " 判断程序是否成功 READ TABLE lt_return INDEX 1. DESCRIBE TABLE lt_return. IF lt_return-type EQ 'S' AND sy-tfill EQ 1. ls_result-code = 'S'. ls_result-message = '02:检验计划创建成功'. APPEND ls_result TO lt_result. CLEAR ls_result. " 如果程序没有发生错误则进行提交 CALL FUNCTION 'BAPI_TRANSACTION_COMMIT' EXPORTING wait = 'X'. " " 创建成功后更新输出内表的值 l_flag = 'S'. ELSE. l_flag = 'E'. DATA: text TYPE string. LOOP AT lt_return WHERE type = 'E'. CONCATENATE text lt_return-message INTO text. ENDLOOP. ls_result-code = 'E'. CONCATENATE '03:' text INTO ls_result-message. APPEND ls_result TO lt_result. CLEAR ls_result. ROLLBACK WORK. ENDIF. CLEAR: lt_task, lt_materialtaskallocation, lt_operation, lt_inspection, lt_return. CLEAR: lt_task[], lt_materialtaskallocation[], lt_operation[], lt_inspection[], lt_return[]. CLEAR: lv_group,lv_counter. ENDIF. WRITE: l_flag, text.