?短缺未限制使用的SL? 一般是?BAPI_GOODSMVT_CREATE的参数
GOODSMVT_ITEM 里面含有待移动数量为0的行项目
但是此次比较特殊
?
?跟了很久 都是这样的问题,
解决方案:BAPI BAPI_GOODSMVT_CREATE的?GOODSMVT_ITEM的RES_TYPE 记录类型赋值
FUNCTION ZBOM_MM_CJLL.
*"----------------------------------------------------------------------
*"*"局部接口:
*" IMPORTING
*" VALUE(VBELN) TYPE AUFNR
*" VALUE(LGORT) TYPE LGORT_D
*" VALUE(WERKS) TYPE DWERK
*" EXPORTING
*" VALUE(MATERIALDOCUMENT) TYPE BAPI2017_GM_HEAD_RET-MAT_DOC
*" VALUE(STATUS) TYPE BAPI_MTYPE
*" VALUE(MESSAGE) TYPE BAPI_MSG
*" VALUE(MARK) TYPE BAPI_MTYPE
*" TABLES
*" G_ZTVRESB STRUCTURE ZTVRESB OPTIONAL
*" L_ZSCJKRETURN STRUCTURE ZSCJKRETURN OPTIONAL
*" ITAB STRUCTURE BAPI2017_GM_ITEM_CREATE OPTIONAL
*"----------------------------------------------------------------------
DATA:
gmhead LIKE TABLE OF bapi2017_gm_head_01 WITH HEADER LINE,
gmcode LIKE TABLE OF bapi2017_gm_code WITH HEADER LINE,
lcnt TYPE i,
lGOODSMVT_SERV_PART_DATA LIKE TABLE OF /SPE/BAPI2017_SERVICEPART_DATA WITH HEADER LINE,
mthead LIKE BAPI2017_GM_HEAD_RET,
t_num TYPE C LENGTH 4,
mat_doc LIKE bapi2017_gm_head_ret-mat_doc,
gmatke LIKE TABLE OF ZTVRESB WITH HEADER LINE,
GLABST LIKE TABLE OF ZTVRESB WITH HEADER LINE,
L_ZTVRESB LIKE TABLE OF ZTVRESB WITH HEADER LINE,
L_MATNR TYPE MATNR,
L_LGORT TYPE LGORT_D,
matnr1 TYPE matnr,
L_ENMNG TYPE ENMNG,
L_BDMNG TYPE BDMNG,
time TYPE CO_GLTRP,
L_GSTRP TYPE PM_ORDGSTRP,
temp1 TYPE C LENGTH 1,
temp2 TYPE C LENGTH 5,
NUM TYPE N LENGTH 2,
timetemp TYPE C LENGTH 18,
L_MBLNR TYPE MBLNR,
temp TYPE TABLE OF ZTVCJLLMESSAGE WITH HEADER LINE,
errmsg LIKE TABLE OF BAPIRET2 WITH HEADER LINE.
"查询订单开始日期
SELECT GSTRP INTO L_GSTRP FROM AFKO WHERE AUFNR = vbeln.
ENDSELECT.
*----------移动代码赋值----------*
gmcode-gm_code = '03'."事件
APPEND gmcode.
*----------抬头数据赋值----------*
gmhead-pstng_date = sy-datum."凭证中的过账日期
gmhead-doc_date = sy-datum."凭证中的凭证日期
gmhead-HEADER_TXT = L_GSTRP."凭证抬头文本
APPEND gmhead.
*----------创建物料凭证项目----------*
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
input = VBELN
IMPORTING
output = VBELN.
"查询预留号
SELECT RSNUM FROM RKPF INTO CORRESPONDING FIELDS OF gmatke WHERE AUFNR = vbeln.
APPEND gmatke.
ENDSELECT.
"查询库存数量等信息
select RESB~MATNR RESB~BDMNG RESB~ENMNG RESB~RSPOS RESB~RSNUM MARD~LABST RESB~KZEAR resb~werks RESB~LGORT RESB~KZAUS resb~RSART
INTO (G_ZTVRESB-matnr,G_ZTVRESB-bdmng,G_ZTVRESB-enmng,G_ZTVRESB-rspos,G_ZTVRESB-rsnum,G_ZTVRESB-labst,G_ZTVRESB-kzear,G_ZTVRESB-werks,G_ZTVRESB-lgort,G_ZTVRESB-kzaus,G_ZTVRESB-RSART)
FROM RESB JOIN MARD ON RESB~MATNR = MARD~MATNR and RESB~LGORT = MARD~LGORT and resb~werks = mard~werks
WHERE RSNUM = gmatke-rsnum and
XWAOK = 'X' and DUMPS <> 'X' and BDMNG > '0.000' and " dumps虚件不领料 终止的不要
KZEAR <> 'X' AND XLOEK <> 'X'.
APPEND G_ZTVRESB.
ENDSELECT.
"查询订单的所有要领料的物料号
select MATNR lgort INTO CORRESPONDING FIELDS OF L_ZTVRESB FROM RESB
WHERE RSNUM = gmatke-rsnum and XWAOK = 'X' and DUMPS <> 'X' and BDMNG > '0.000' and " dumps虚件不领料 终止的不要
KZEAR <> 'X' AND XLOEK <> 'X'.
APPEND L_ZTVRESB.
ENDSELECT.
"判断物料是否在指定库位
LOOP AT L_ZTVRESB.
SELECT MATNR LGORT INTO (L_MATNR,L_LGORT) FROM MARD WHERE MARD~MATNR = L_ZTVRESB-MATNR AND LGORT = L_ZTVRESB-LGORT.
ENDSELECT.
IF L_MATNR IS INITIAL.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT'
EXPORTING
input = VBELN
IMPORTING
output = VBELN.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT'
EXPORTING
input = L_ZTVRESB-MATNR
IMPORTING
output = L_ZTVRESB-MATNR.
L_ZSCJKRETURN-AUFNR = VBELN.
L_ZSCJKRETURN-MATNR = L_ZTVRESB-MATNR.
L_ZSCJKRETURN-STATUS = 'E'.
L_ZSCJKRETURN-MESSAGE = '物料不在库位' && L_ZTVRESB-LGORT && ' 中'.
APPEND L_ZSCJKRETURN.
CLEAR L_ZSCJKRETURN.
ENDIF.
ENDLOOP.
*-------------执行程序-------------*
LOOP AT G_ZTVRESB.
LOOP AT itab.
IF itab-material = G_ZTVRESB-MATNR.
IF temp2 IS INITIAL.
temp2 = temp2 + itab-entry_qnt + G_ZTVRESB-BDMNG.
ELSE.
temp2 = temp2 + itab-entry_qnt.
ENDIF.
ENDIF.
ENDLOOP.
IF G_ZTVRESB-LABST >= G_ZTVRESB-BDMNG AND G_ZTVRESB-ENMNG <= G_ZTVRESB-BDMNG AND G_ZTVRESB-LABST >= temp2 and G_ZTVRESB-BDMNG > 0.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
input = VBELN
IMPORTING
output = VBELN.
DESCRIBE TABLE itab LINES lcnt.
lcnt = lcnt + 1.
itab-LINE_ID = lcnt.
itab-material = G_ZTVRESB-MATNR."物料编号
itab-plant = WERKS."工厂
itab-stge_loc = G_ZTVRESB-LGORT."库存地点
itab-move_type = '261'."MOVE_TYPE'."移动类型(库存管理)
itab-entry_qnt = G_ZTVRESB-BDMNG."以输入单位计的数量
itab-ORDERID = VBELN.
itab-RES_TYPE = G_ZTVRESB-RSART. =====================一定要加上
itab-RESERV_NO = G_ZTVRESB-rsnum."预留编号
itab-RES_ITEM = G_ZTVRESB-rspos."预留项目编号
append itab.
CLEAR itab.
CLEAR temp2.
ELSEIF G_ZTVRESB-LABST < G_ZTVRESB-BDMNG.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT'
EXPORTING
input = VBELN
IMPORTING
output = VBELN.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT'
EXPORTING
input = G_ZTVRESB-MATNR
IMPORTING
output = G_ZTVRESB-MATNR.
L_ZSCJKRETURN-AUFNR = VBELN.
L_ZSCJKRETURN-MATNR = G_ZTVRESB-MATNR.
L_ZSCJKRETURN-STATUS = 'E'.
L_ZSCJKRETURN-MESSAGE = '库存' && L_ZTVRESB-LGORT &&'数量' && G_ZTVRESB-LABST && '小于需求量' && G_ZTVRESB-BDMNG .
APPEND L_ZSCJKRETURN.
CLEAR L_ZSCJKRETURN.
ENDIF.
ENDLOOP.
IF NOT itab[] IS INITIAL.
CALL FUNCTION 'BAPI_GOODSMVT_CREATE'
EXPORTING
GOODSMVT_HEADER = gmhead
GOODSMVT_CODE = gmcode
IMPORTING
MATERIALDOCUMENT = MATERIALDOCUMENT
TABLES
GOODSMVT_SERV_PART_DATA = LGOODSMVT_SERV_PART_DATA[]
GOODSMVT_ITEM = itab[]
RETURN = errmsg.
IF NOT MATERIALDOCUMENT IS INITIAL.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
WAIT = 'X'.
commit WORK AND WAIT .
ELSE.
CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
ENDIF.
ENDIF.
SELECT PLNBEZ INTO matnr1 FROM AFKO WHERE AUFNR = vbeln.
ENDSELECT.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT'
EXPORTING
input = matnr1
IMPORTING
output = matnr1.
LOOP AT errmsg.
L_ZSCJKRETURN-AUFNR = VBELN.
L_ZSCJKRETURN-MATNR = matnr1.
L_ZSCJKRETURN-STATUS = errmsg-type.
L_ZSCJKRETURN-MESSAGE = 'OSSNO.' && errmsg-ID && errmsg-NUMBER && ',MSG:' && errmsg-MESSAGE.
APPEND L_ZSCJKRETURN.
CLEAR L_ZSCJKRETURN.
ENDLOOP.
* -----返回信息存入表中
LOOP AT L_ZSCJKRETURN.
GET TIME.
t_num = t_num + 1.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
input = t_num
IMPORTING
output = t_num.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT'
EXPORTING
input = L_ZSCJKRETURN-AUFNR
IMPORTING
output = L_ZSCJKRETURN-AUFNR.
CONCATENATE sy-UZEIT L_ZSCJKRETURN-AUFNR t_num INTO temp-CREATETIME.
temp-AUFNR = L_ZSCJKRETURN-AUFNR.
temp-MATNR = L_ZSCJKRETURN-MATNR.
temp-MESSAGE = L_ZSCJKRETURN-MESSAGE.
temp-time = sy-DATUM.
APPEND temp.
NUM = STRLEN( L_ZSCJKRETURN-MESSAGE ) - 2."字符长度
* CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT'
* EXPORTING
* input = NUM
* IMPORTING
* output = NUM.
L_ZSCJKRETURN-MESSAGE = L_ZSCJKRETURN-MESSAGE+NUM(2).
IF L_ZSCJKRETURN-MESSAGE = '锁定'.
MARK = 1.
ENDIF.
time = sy-DATUM - 5.
delete FROM ZTVCJLLMESSAGE WHERE ZTVCJLLMESSAGE~time = time.
COMMIT WORK.
ENDLOOP.
INSERT ZTVCJLLMESSAGE from table temp."暂时不用日志
COMMIT WORK.
ENDFUNCTION.
|