REPORT Z_CREATE_MATPHYSINV.
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,
P_LGORT LIKE MARD-LGORT,
P_MATNR LIKE MARD-MATNR.
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 = SY-DATUM.
L_HEAD-PLAN_DATE = SY-DATUM.
ITEM-MATERIAL = P_MATNR.
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
阅读(3294) | 评论(0) | 转发(0) |