前台:MI01
输入工厂,库存地点,在记账冻结打X,具体什么意思F1查看
回车后,填写物料,回车,项目号会自动变更
BAPI:BAPI_MATPHYSINV_CREATE_MULT
查找bapi参见:http://blog.sina.com.cn/s/blog_c0978c9b0102uxji.html
文本代码:
*&---------------------------------------------------------------------*
*&创建盘点凭证 MI01
*&---------------------------------------------------------------------*
TABLES:MARA.
DATA: IT_ITEM LIKE TABLE OF BAPI_PHYSINV_COUNT_ITEMS WITH HEADER LINE,
RET_MSG LIKE TABLE OF BAPIRET2 WITH HEADER LINE,
G_INVDOC LIKE IKPF-IBLNR.
*&--------------------------------------------------------------------*
*& SEKECTION-SCREEN
*&--------------------------------------------------------------------*
SELECTION-SCREEN BEGIN OF BLOCK BLK1 WITH FRAME TITLE TEXT-001.
PARAMETERS:P_WERKS LIKE MARD-WERKS DEFAULT 'RYL5',
P_LGORT LIKE MARD-LGORT DEFAULT '3100',
P_MATNR LIKE MARD-MATNR DEFAULT '0609990060199112',
P_DATE LIKE SY-DATUM DEFAULT '20140618'.
SELECTION-SCREEN END OF BLOCK BLK1.
*&---------------------------------------------------------------------*
*& START-OF-SELECTION
*&---------------------------------------------------------------------*
START-OF-SELECTION.
*& 创建盘点凭证
PERFORM CREATE_INVENTORY_DOCUMENT.
*&---------------------------------------------------------------------*
*& Form CREATE_INVENTORY_DOCUMENT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM CREATE_INVENTORY_DOCUMENT .
DATA:L_HEAD TYPE BAPI_PHYSINV_CREATE_HEAD,
ITEM LIKE TABLE OF BAPI_PHYSINV_CREATE_ITEMS WITH HEADER LINE .
L_HEAD-PLANT = P_WERKS.
L_HEAD-STGE_LOC = P_LGORT.
L_HEAD-DOC_DATE = P_DATE.
L_HEAD-PLAN_DATE = P_DATE. "盘点日期
L_HEAD-PLAN_DATE = P_DATE. "凭证日期
* GS_HEAD-PLANT = P_WERKS."工厂
* GS_HEAD-STGE_LOC = P_LGORT."库存地点
* GS_HEAD-PLAN_DATE = P_BLDAT."盘点日期
* GS_HEAD-DOC_DATE = P_GIDAT."凭证日期
* GS_HEAD-PHYS_INV_NO = P_INVNU."实际库存编号
* GS_HEAD-PHYS_INV_REF = P_XBLNI."库存盘点参考
*SPEC_STOCK 特殊库存标识
*POST_BLOCK 由于实际盘点而冻结记帐
*FREEZEBOOKINV 冻结帐面库存
*DEL_BATCHES XLVOCA 包括带有删除标识的批量
*GROUPING_TYPE 分组标准类型
* GT_ITEM-MATERIAL = GT_IT_DATA-MATNR. "物料号码
* GT_ITEM-BATCH = GT_IT_DATA-CHARG. "批次编号
** GT_ITEM-STOCK_TYPE = GT_IT_DATA-BSTAR. "库存类型(1~4)
* APPEND GT_ITEM.
* CLEAR GT_ITEM.
ITEM-MATERIAL = P_MATNR.
ITEM-STOCK_TYPE = 1.
APPEND ITEM.
CLEAR ITEM.
CALL FUNCTION 'BAPI_MATPHYSINV_CREATE_MULT'
EXPORTING
HEAD = L_HEAD
TABLES
ITEMS = ITEM[]
RETURN = RET_MSG.
PERFORM COMMIT_OPERATION.
ENDFORM. " CREATE_INVENTORY_DOCUMENT
*&---------------------------------------------------------------------*
*& Form COMMIT_OPERATION
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM COMMIT_OPERATION .
READ TABLE RET_MSG WITH KEY TYPE = 'E'.
IF SY-SUBRC <> 0.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
WAIT = 'X'.
READ TABLE RET_MSG INDEX 1.
IF SY-SUBRC = 0.
WRITE:/ 'document:',RET_MSG-MESSAGE_V1.
ENDIF.
ELSE.
LOOP AT RET_MSG.
WRITE:/ 'erro message:',RET_MSG-MESSAGE.
ENDLOOP.
ENDIF.
ENDFORM. " COMMIT_OPERATION