MIGO采购订单收货批次增强
作者:互联网
需求: MIGO 做采购订单收货时,化学品物料启用批次管理和产品生命周期的管理,采购收货或其他入库时,需要输入生产日期,根据批次生成规则,自动(或手工输入优先)生成批次号,针对移动类型:101、511、501、309、561、
批次生成规则:生产日期(年2位,月2位,日2位)+ 流水码(4位),按照每天的收货入库进行Check,例如:生产日期为:2020年12月31日,则2021年04月06日,第一次收货入库时的批次为:2012310001,第二次收货入库时,批次为:2012310002,依次类推。
MIGO收货入库增强函数参考:EXIT_SAPLV01Z_002 ; SMOD: SAPLV01Z;
"替换为国瓷条件 -- CHECK sy-mandt = '302' OR sy-mandt = '602' OR sy-mandt = '802' OR sy-mandt = '301' OR sy-mandt = '601' OR sy-mandt = '801'. DATA : lv_prog LIKE d020s-prog, lv_dnum LIKE d020s-dnum, lv_datum TYPE datum, lv_dates TYPE datum, lv_bklas TYPE bklas, lv_atwrt TYPE atwrt, lv_atinn TYPE atinn, ls_mch1 TYPE ztpp_mch1, ls_mch2 TYPE ztpp_mch2, it_dyn TYPE STANDARD TABLE OF dynpread. DATA: lv_exit TYPE c. IF x_bncom-werks IS INITIAL. MESSAGE e027(zpp01) WITH '请输入工厂'. RAISE cancelled. ENDIF. PERFORM frm_change_charg IN PROGRAM zmme0003 USING x_bncom CHANGING new_charg lv_exit IF FOUND. IF lv_exit = abap_true. RETURN. ENDIF. SELECT SINGLE bklas INTO lv_bklas FROM mbew WHERE matnr = x_bncom-matnr AND bwkey = x_bncom-werks. *CASE lv_bklas. * WHEN '3010'. CASE lv_bklas+(2). WHEN '30'. CASE sy-tcode. WHEN 'MIGO' . lv_prog = 'SAPLMIGO'. lv_dnum = '0110'. APPEND VALUE #( fieldname = 'GOHEAD-BUDAT' ) TO it_dyn. *获取屏幕记账日期 CALL FUNCTION 'DYNP_VALUES_READ' EXPORTING dyname = lv_prog dynumb = lv_dnum TABLES dynpfields = it_dyn EXCEPTIONS invalid_abapworkarea = 1 invalid_dynprofield = 2 invalid_dynproname = 3 invalid_dynpronummer = 4 invalid_request = 5 no_fielddescription = 6 invalid_parameter = 7 undefind_error = 8 double_conversion = 9 stepl_not_found = 10 OTHERS = 11. IF sy-subrc = 0. READ TABLE it_dyn INDEX 1 ASSIGNING FIELD-SYMBOL(<fs_dyn>). IF sy-subrc = 0. IF <fs_dyn>-fieldvalue IS NOT INITIAL. CALL FUNCTION 'CONVERT_DATE_TO_INTERNAL' EXPORTING date_external = <fs_dyn>-fieldvalue IMPORTING date_internal = lv_datum. ELSE. lv_datum = sy-datum. ENDIF. ENDIF. ENDIF. WHEN 'MSC1N' . lv_datum = sy-datum. WHEN 'ZPDAxx'. DATA(lv_field) = '(SAPLZMM_FG0006)GV_BUDAT'. ASSIGN (lv_field) TO FIELD-SYMBOL(<lfs_budat>). IF <lfs_budat> IS ASSIGNED. lv_datum = <lfs_budat>. ELSE. lv_datum = sy-datum. ENDIF. ENDCASE. IF NOT lv_datum IS INITIAL. SELECT SINGLE * INTO ls_mch1 FROM ztpp_mch1 WHERE datum = lv_datum+2(6). IF sy-subrc = 0. ls_mch1-msnro = ls_mch1-msnro + 1. ELSE. ls_mch1-datum = lv_datum+2(6). ls_mch1-msnro = '0001'. ENDIF. CALL FUNCTION 'RP_CALC_DATE_IN_INTERVAL' EXPORTING date = lv_datum days = 0 months = 2 signum = '-' years = 0 IMPORTING calc_date = lv_dates. DATA(i_dat_del) = lv_dates+2(6). DELETE FROM ztpp_mch1 WHERE datum <= i_dat_del ##WARN_OK. MODIFY ztpp_mch1 FROM ls_mch1 ##WARN_OK. CONCATENATE ls_mch1-datum ls_mch1-msnro INTO new_charg. ELSE. CLEAR new_charg. ENDIF. * WHEN '7010' OR '7020'. "成品 , 半成品, WHEN '70'. "成品 , 半成品 CHECK ( x_bncom-werks = '7500' OR x_bncom-werks = '7599' ) AND ( lv_bklas = '7010' OR lv_bklas = '7020' ). CALL FUNCTION 'CONVERSION_EXIT_ATINN_INPUT' EXPORTING input = 'LSGC_PRODUCTCODE' IMPORTING output = lv_atinn. SELECT SINGLE atwrt INTO lv_atwrt FROM ausp WHERE objek IN ( SELECT cuobj FROM inob WHERE klart = '023' AND objek = x_bncom-matnr AND obtab = 'MARA' ) "CUOBJ AND atinn = lv_atinn AND mafid = 'O' AND klart = '023'. IF sy-subrc = 0. CONDENSE lv_atwrt NO-GAPS. SELECT SINGLE * INTO ls_mch2 FROM ztpp_mch2 WHERE matnr = x_bncom-matnr AND gjahr = sy-datum+2(2). IF sy-subrc = 0. ls_mch2-msnro = ls_mch2-msnro + 1. ELSE. *成品半成品流水码保留一年 DATA(nian_tmp) = sy-datum+2(2) - 1. SELECT COUNT(*) FROM ztpp_mch2 WHERE matnr = x_bncom-matnr AND gjahr = nian_tmp . IF sy-subrc = 0. DELETE ztpp_mch2 FROM ls_mch2. ENDIF. CLEAR ls_mch2. ls_mch2-matnr = x_bncom-matnr. ls_mch2-pdcode = lv_atwrt(2). ls_mch2-gjahr = sy-datum+2(2). ls_mch2-msnro = '00001'. ENDIF. MODIFY ztpp_mch2 FROM ls_mch2. CONCATENATE lv_atwrt(2) sy-datum+2(2) ls_mch2-msnro INTO new_charg. ELSE. CLEAR new_charg. ENDIF. WHEN OTHERS. ENDCASE.
DATA: lr_werks TYPE RANGE OF aufk-werks, lr_xchpf TYPE RANGE OF marc-xchpf, lr_bwart TYPE RANGE OF mseg-bwart. DATA: lv_prog LIKE d020s-prog, lv_dnum LIKE d020s-dnum, it_dyn TYPE STANDARD TABLE OF dynpread, lv_bwart LIKE mseg-bwart, lv_hsdat LIKE mcha-hsdat. * 条件:工厂(GOITEM-WERKS = P101/P121/P900/P000)+ 化学品物料启用批次管理(MARC-XCHPF = ‘X’), SELECT SINGLE * INTO @DATA(ls_ztmm_enhance) FROM ztmm_enhance WHERE prog = 'ZMME0003_001' AND item = '000001' AND active = 'X'. IF sy-subrc NE 0. RETURN. ELSE. "s1.检查工厂 PERFORM frm_value_split TABLES lr_werks USING ls_ztmm_enhance-value1 . IF x_bncom-werks NOT IN lr_werks. RETURN. ELSE. lv_exit = abap_true. ENDIF. "s2.检查是否启用批次号 SELECT SINGLE xchpf INTO @DATA(lv_xchpf) FROM marc WHERE matnr = @x_bncom-matnr AND werks = @x_bncom-werks. PERFORM frm_xchpf_split TABLES lr_xchpf USING ls_ztmm_enhance-value2 . IF lv_xchpf NOT IN lr_xchpf. RETURN. ENDIF. "s3.检查移动类型 CASE sy-tcode. WHEN 'MIGO' . lv_prog = 'SAPLMIGO'. lv_dnum = '0011'. APPEND VALUE #( fieldname = 'GODEFAULT_TV-BWART' ) TO it_dyn. *获取屏幕抬头移动类型 CALL FUNCTION 'DYNP_VALUES_READ' EXPORTING dyname = lv_prog dynumb = lv_dnum TABLES dynpfields = it_dyn EXCEPTIONS invalid_abapworkarea = 1 invalid_dynprofield = 2 invalid_dynproname = 3 invalid_dynpronummer = 4 invalid_request = 5 no_fielddescription = 6 invalid_parameter = 7 undefind_error = 8 double_conversion = 9 stepl_not_found = 10 OTHERS = 11. IF sy-subrc = 0. READ TABLE it_dyn INDEX 1 ASSIGNING FIELD-SYMBOL(<fs_dyn>). IF sy-subrc = 0. IF <fs_dyn>-fieldvalue IS NOT INITIAL. lv_bwart = <fs_dyn>-fieldvalue. ENDIF. ENDIF. ENDIF. WHEN 'MSC1N' . WHEN 'ZPDAxx'. WHEN OTHERS."BAPI 做MIGO ENDCASE. PERFORM frm_bwart_split TABLES lr_bwart USING ls_ztmm_enhance-value3 . IF lv_bwart NOT IN lr_bwart. RETURN. ENDIF. ENDIF. * IF x_bncom-hsdat IS INITIAL. * MESSAGE e027(zpp01) WITH '请输入工厂'. RAISE cancelled. * ENDIF. **获取屏幕项目生产日期 CASE sy-tcode. WHEN 'MIGO' . lv_prog = 'SAPLMIGO'. lv_dnum = '0335'. CLEAR: it_dyn,it_dyn[]. APPEND VALUE #( fieldname = 'GOITEM-HSDAT' ) TO it_dyn. CALL FUNCTION 'DYNP_VALUES_READ' EXPORTING dyname = lv_prog dynumb = lv_dnum TABLES dynpfields = it_dyn EXCEPTIONS invalid_abapworkarea = 1 invalid_dynprofield = 2 invalid_dynproname = 3 invalid_dynpronummer = 4 invalid_request = 5 no_fielddescription = 6 invalid_parameter = 7 undefind_error = 8 double_conversion = 9 stepl_not_found = 10 OTHERS = 11. IF sy-subrc = 0. READ TABLE it_dyn INDEX 1 ASSIGNING FIELD-SYMBOL(<fs_dyn_date>). IF sy-subrc = 0. IF <fs_dyn_date>-fieldvalue IS NOT INITIAL. CALL FUNCTION 'CONVERT_DATE_TO_INTERNAL' EXPORTING date_external = <fs_dyn_date>-fieldvalue IMPORTING date_internal = lv_hsdat. ENDIF. ENDIF. ENDIF. WHEN 'MSC1N' . WHEN 'ZPDAxx'. WHEN OTHERS."BAPI 做MIGO ENDCASE. BREAK sapwb0011. DATA: lv_lsm TYPE numc4. IF lv_hsdat IS NOT INITIAL. "MCHB SELECT MAX( charg ) FROM mchb WHERE matnr = @x_bncom-matnr AND werks = @x_bncom-werks AND substring( charg,1,6 ) = @lv_hsdat+2(6) INTO @DATA(lv_charg). IF sy-subrc EQ 0. lv_lsm = lv_charg+6(4). lv_lsm = lv_lsm + 1. ELSE. lv_lsm = '0001'."改为4位流水码 ENDIF. CONCATENATE lv_hsdat+2(6) lv_lsm INTO new_charg. ENDIF.
标签:sy,收货,批次,datum,MIGO,invalid,lv,ENDIF,TYPE 来源: https://www.cnblogs.com/rainysblog/p/14771327.html