ABAP 新增PO计划行时 新增行交货日期默认当前最大交期
DATA: ls_poitem TYPE mepoitem.
DATA: ls_jhh TYPE meposchedule.
DATA: ls_poitemc TYPE REF TO if_purchase_order_item_mm.
DATA: is_persistent TYPE mmpur_bool.
DATA: lt_eket TYPE TABLE OF eket.
DATA: ls_eket TYPE eket.
DATA: lv_lfdat TYPE eban-lfdat.
ls_jhh = im_schedule->get_data( ). "当前执行行的计划行
is_persistent = im_schedule->is_persistent( ).
CALL METHOD im_schedule->get_item
RECEIVING
re_item = ls_poitemc.
ls_poitem = ls_poitemc->get_data( ).
IF is_persistent = '' AND ( sy-tcode = 'ME23N' OR sy-tcode = 'ME22N' OR sy-tcode = 'ME54N' OR sy-tcode = 'ME29N' ) AND ls_jhh-ebeln <> ''. "新增计划行
SELECT COUNT(*) FROM eket WHERE ebeln = ls_jhh-ebeln AND ebelp = ls_jhh-ebelp AND etenr = ls_jhh-etenr.
IF sy-subrc NE 0. "为新增计划行
SELECT SINGLE lfdat INTO lv_lfdat FROM eban WHERE banfn = ls_poitem-banfn AND bnfpo = ls_poitem-bnfpo.
IF sy-subrc = 0.
IF lv_lfdat = ls_jhh-eindt."系统默认为PR需求日期,要改为当前PO最大交期
REFRESH lt_eket.
SELECT * INTO TABLE lt_eket FROM eket WHERE ebeln = ls_jhh-ebeln AND ebelp = ls_jhh-ebelp.
SORT lt_eket BY eindt DESCENDING.
READ TABLE lt_eket INTO ls_eket INDEX 1.
ls_jhh-eindt = ls_eket-eindt.
ls_jhh-eeind = ls_eket-eindt.
im_schedule->set_data( ls_jhh ).
ENDIF.
ENDIF.
ENDIF.
ENDIF.