通过vl02n可以修改包装单元(handling unit)的用户状态,如下图:
调用函数HU_STATUS_UPDATE也可以更新HU的用户状态。
例子代码:
REPORT ztest_change_hu_status. TYPES:BEGIN OF ty_objnr, objnr TYPE hustobj-objnr, END OF ty_objnr. DATA: lit_vekp TYPE TABLE OF vekp, lwa_vekp LIKE LINE OF lit_vekp, lit_hustatus_db TYPE vses_t_hustatus, lwa_hustatus_db LIKE LINE OF lit_hustatus_db, lit_objnr TYPE STANDARD TABLE OF ty_objnr, lwa_objnr LIKE LINE OF lit_objnr, lit_hustatus TYPE vses_t_hustatus, lwa_hustatus LIKE LINE OF lit_hustatus, lit_hustobj TYPE vses_t_hustobj, lwa_hustobj LIKE LINE OF lit_hustobj, lit_vepo TYPE TABLE OF vepo, lwa_vepo LIKE LINE OF lit_vepo, l_objnr TYPE hustobj-objnr. CONSTANTS:lco_hu TYPE char2 VALUE 'HU', " HU lco_15 TYPE char5 VALUE 'E0006', " user status 15 HOLD lco_16 TYPE char5 VALUE 'E0007'. " user status 16 UNHOLD PARAMETERS:p_vbeln TYPE likp-vbeln. " get data from VEKP SELECT * INTO TABLE lit_vekp FROM vekp WHERE vpobjkey = p_vbeln. IF sy-subrc = 0. SORT lit_vekp BY exidv. ENDIF. " get data from VEPO IF lit_vekp IS NOT INITIAL. SELECT * INTO TABLE lit_vepo FROM vepo FOR ALL ENTRIES IN lit_vekp WHERE venum = lit_vekp-venum. ENDIF. * get user status * get HU object LOOP AT lit_vepo INTO lwa_vepo. lwa_objnr-objnr = lco_hu. "HU lwa_objnr+2(10) = lwa_vepo-venum. COLLECT lwa_objnr INTO lit_objnr. ENDLOOP. IF lit_objnr[] IS NOT INITIAL. * 查找HU的状态 SELECT * FROM husstat INTO TABLE lit_hustatus_db FOR ALL ENTRIES IN lit_objnr WHERE objnr = lit_objnr-objnr AND stat = lco_15 "Hold AND inact <> 'X'. IF sy-subrc = 0. REFRESH:lit_hustatus. * LOOP AT lit_hustatus_db INTO lwa_hustatus_db . * 将E0006状态设置成无效 lwa_hustatus-objnr = lwa_hustatus_db-objnr. lwa_hustatus-stat = lco_15. lwa_hustatus-inact = abap_true. lwa_hustatus-mod = 'U'. APPEND lwa_hustatus TO lit_hustatus. READ TABLE lit_hustatus_db INTO lwa_hustatus_db WITH KEY objnr = l_objnr stat = lco_16. IF sy-subrc = 0. lwa_hustatus-mod = 'U'. ELSE. lwa_hustatus-mod = 'I'. ENDIF. * 插入或修改新状态 lwa_hustatus-objnr = lwa_hustatus_db-objnr. lwa_hustatus-stat = lco_16. lwa_hustatus-inact = abap_false. APPEND lwa_hustatus TO lit_hustatus. ENDLOOP. IF lit_hustatus[] IS NOT INITIAL. CALL FUNCTION 'HU_STATUS_UPDATE' EXPORTING it_hustatus = lit_hustatus it_hustobj = lit_hustobj. ENDIF. ENDIF. ENDIF.