批次要求年(后两位)月日+四位流水,例:1807110001,用自建表写的
CO41 计划订单批量转生产订单,根据订单物料带入批次
增强点:LCOZVF2M
内表:afpod_tmp
添加位置:342(点击显示增强第二个可以增强的点)
CO01 创建生产订单,点击收货带出来批次
增强点:LCOKO1F3I
内表:AFPOD
添加位置:42(点击显示增强第一个可要增强的点)
if sy-tcode = 'CO41' .
data: it_ztmm type table of ZTMM001.
data: is_ztmm type ZTMM001.
DATA: lv_varkey TYPE VIM_ENQKEY,
ls_mess(30),
lv_id(20).
DATA:LV_MATERIAL LIKE BAPIBATCHKEY-MATERIAL_LONG,
LV_BATCH LIKE BAPIBATCHKEY-BATCH,
LV_PLANT LIKE BAPIBATCHKEY-PLANT.
lv_varkey = sy-mandt && sy-datum+0(4) && '10'.
CALL FUNCTION 'ENQUEUE_E_TABLE'
EXPORTING
mode_rstable = 'E'
tabname = 'ZTMM001' "锁表
varkey = lv_varkey
x_tabname = ' '
x_varkey = ' '
_scope = '2'
_wait = ' '
_collect = ' '
EXCEPTIONS
foreign_lock = 1
system_failure = 2
OTHERS = 3.
IF sy-subrc <> 0.
CALL FUNCTION 'MESSAGE_TEXT_BUILD'
EXPORTING
msgid = sy-msgid
msgnr = sy-msgno
msgv1 = sy-msgv1
msgv2 = sy-msgv1
msgv3 = sy-msgv1
msgv4 = sy-msgv1
IMPORTING
message_text_output = ls_mess.
MESSAGE ls_mess type 'E'.
ENDIF.
SELECT SINGLE *
FROM ZTMM001
into is_ztmm
WHERE BUDAT = sy-datum.
if sy-subrc = 0 .
is_ztmm-GJAHR = is_ztmm-GJAHR + 1.
UPDATE ZTMM001 set GJAHR = is_ztmm-GJAHR WHERE BUDAT = sy-datum.
ELSE.
is_ztmm-BUDAT = sy-datum.
is_ztmm-GJAHR = '0000'.
MODIFY ZTMM001 FROM is_ztmm.
endif .
CALL FUNCTION 'DEQUEUE_E_TABLE'
EXPORTING
mode_rstable = 'E'
tabname = 'ZTMM001'
varkey = lv_varkey
x_tabname = ' '
x_varkey = ' '
_scope = '3'
_synchron = ' '
_collect = ' '.
IF sy-subrc <> 0.
CALL FUNCTION 'MESSAGE_TEXT_BUILD'
EXPORTING
msgid = sy-msgid
msgnr = sy-msgno
msgv1 = sy-msgv1
msgv2 = sy-msgv1
msgv3 = sy-msgv1
msgv4 = sy-msgv1
IMPORTING
message_text_output = ls_mess.
MESSAGE ls_mess type 'E'.
ENDIF.
CONCATENATE is_ztmm-BUDAT+2(6) is_ztmm-GJAHR into afpod_tmp-CHARG.
CONCATENATE SY-UNAME '123' INTO LV_ID."为了在磁盘中能找到
EXPORT
LV_MATERIAL from afpod_tmp-MATNR
LV_PLANT FROM afpod_tmp-pwerk
LV_BATCH FROM afpod_tmp-CHARG
TO MEMORY ID LV_ID.
endif.
在这个地方更改afpod_tmp-CHARG(AFPOD-CHARG )字段就可以直接更新到表
这个时候批次产生了但没有创建,需要调BAPI:BAPI_BATCH_CREATE
增强点:CO_ZV_ORDER_POST(函数)
添加位置:ENDFUNCTION 的前一个增强点
这个增强点适用于CO01和CO41,且CO41在批量创建时每一条都会进,但由于在两个不同的地方需要内存传值
if sy-tcode = 'CO41'or sy-tcode = 'CO01'.
" BREAK-POINT.
data lv_id(20).
DATA:
LV_MATERIAL LIKE BAPIBATCHKEY-MATERIAL_LONG,
LV_BATCH LIKE BAPIBATCHKEY-BATCH,
LV_PLANT LIKE BAPIBATCHKEY-PLANT.
DATA: LS_BATCHCONTROLFIELDS LIKE BAPIBATCHCTRL,
LS_BATCHATTRIBUTES LIKE BAPIBATCHATT.
DATA:IT_RETURN TYPE TABLE OF BAPIRET2 WITH HEADER LINE.
CONCATENATE sy-uname '123' INTO lv_id.
IMPORT
LV_MATERIAL
LV_BATCH
LV_PLANT
FROM MEMORY ID lv_id.
LS_BATCHCONTROLFIELDS-BATCHLEVEL = '0'.
LS_BATCHCONTROLFIELDS-CLASS_NUM = 'Z_BATCH'.
CALL FUNCTION 'BAPI_BATCH_CREATE'
EXPORTING
MATERIAL_LONG = LV_MATERIAL
BATCH = LV_BATCH
PLANT = LV_PLANT
" BATCHATTRIBUTES = LS_BATCHATTRIBUTES
" BATCHCONTROLFIELDS = LS_BATCHCONTROLFIELDS
IMPORTING
BATCH = LV_BATCH
TABLES
RETURN = IT_RETURN.
IF IT_RETURN-TYPE = 'S'.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
WAIT = 'X'.
ELSE.
ROLLBACK WORK.
ENDIF.
FREE MEMORY id LV_ID.
ENDIF.
网友评论
真的是忙。
一号上线,又要通宵达啊