Chinaunix首页 | 论坛 | 博客
  • 博客访问: 392360
  • 博文数量: 66
  • 博客积分: 1235
  • 博客等级: 少尉
  • 技术积分: 694
  • 用 户 组: 普通用户
  • 注册时间: 2010-03-05 12:24
文章分类

全部博文(66)

文章存档

2010年(66)

分类:

2010-07-16 14:14:46

REPORT  Z_CREATE_MIGO.

PARAMETERS: P-FILE(128).

PARAMETERS: XPOST LIKE SY-DATUM DEFAULT SY-DATUM.

DATA: BEGIN OF GMHEAD.
        INCLUDE STRUCTURE BAPI2017_GM_HEAD_01.
DATA: END OF GMHEAD.

DATA: BEGIN OF GMCODE.
        INCLUDE STRUCTURE BAPI2017_GM_CODE.
DATA: END OF GMCODE.

DATA: BEGIN OF MTHEAD.
        INCLUDE STRUCTURE BAPI2017_GM_HEAD_RET.
DATA: END OF MTHEAD.

DATA: BEGIN OF ITAB OCCURS 100.
        INCLUDE STRUCTURE BAPI2017_GM_ITEM_CREATE.
DATA: END OF ITAB.

DATA: BEGIN OF ERRMSG OCCURS 10.
        INCLUDE STRUCTURE BAPIRET2.
DATA: END OF ERRMSG.

DATA: WMENGE LIKE ISEG-MENGE,
      ERRFLAG.

DATA: BEGIN OF PCITAB OCCURS 100,
*        EXT_DOC(10),           "External Document Number
        MVT_TYPE(3),           "Movement Type
        DOC_DATE(8),           "Document Date
        POST_DATE(8),          "Posting Date
        PLANT(4),              "Plant
        MATERIAL(18),          "Material Number
        QTY(13),               "Quantity
        RECV_LOC(4),           "Receiving Location
        ISSUE_LOC(4),          "Issuing Location
        PUR_DOC(10),           "Purchase Document No
        PO_ITEM(3),            "Purchase Document Item No
        DEL_NO(10),            "Delivery Purchase Order Number
        DEL_ITEM(3),           "Delivery Item
        PROD_DOC(10),          "Production Document No
        SCRAP_REASON(10),      "Scrap Reason
        UPD_STA(1),            "Update Status
      END OF PCITAB.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR P-FILE.
  PERFORM GET_FILE.

START-OF-SELECTION.
  PERFORM GET_DATA.


*---------------------------------------------------------------------*
*       FORM UPD_STA                                                  *
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
FORM UPD_STA.
  LOOP AT PCITAB.
    PCITAB-UPD_STA = 'X'.
    MODIFY PCITAB.
  ENDLOOP.

  CALL FUNCTION 'WS_DOWNLOAD'
    EXPORTING
      FILENAME                      = P-FILE
      FILETYPE                      = 'DAT'
* IMPORTING
*   FILELENGTH                    =
    TABLES
      DATA_TAB                      = PCITAB
* EXCEPTIONS
*   FILE_OPEN_ERROR               = 1
*   FILE_READ_ERROR               = 2
*   NO_BATCH                      = 3
*   GUI_REFUSE_FILETRANSFER       = 4
*   INVALID_TYPE                  = 5
*   OTHERS                        = 6
            .

ENDFORM.                    "upd_sta
*&---------------------------------------------------------------------*
*&      Form  GET_FILE
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM GET_FILE .
  CALL FUNCTION 'WS_FILENAME_GET'
       EXPORTING
            DEF_FILENAME     = P-FILE
            MASK             ',*.txt,*.TXT.'
*'',*.xls,*.XLS.'如果读入txt文件,在后边就需要用函数
*  CALL FUNCTION 'WS_UPLOAD'
            MODE             'O'
            TITLE            'File Name'
       IMPORTING
            FILENAME         =  P-FILE
       EXCEPTIONS
            INV_WINSYS       = 1
            NO_BATCH         = 2
            SELECTION_CANCEL = 3
            SELECTION_ERROR  = 4
            OTHERS           5.
ENDFORM.                    " GET_FILE
*&---------------------------------------------------------------------*
*&      Form  GET_DATA
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM GET_DATA .
  CALL FUNCTION 'WS_UPLOAD'
  EXPORTING
    FILENAME                      = P-FILE
    FILETYPE                      = 'DAT'
* IMPORTING
*   FILELENGTH                    =
  TABLES
    DATA_TAB                      = PCITAB
* EXCEPTIONS
*   FILE_OPEN_ERROR               = 1
*   FILE_READ_ERROR               = 2
*   NO_BATCH                      = 3
*   GUI_REFUSE_FILETRANSFER       = 4
*   INVALID_TYPE                  = 5
*   OTHERS                        = 6
          .
IF SY-SUBRC <> 0.
  MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
          WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  EXIT.
ENDIF.

GMHEAD-PSTNG_DATE = SY-DATUM.
GMHEAD-DOC_DATE = SY-DATUM.
GMHEAD-PR_UNAME = SY-UNAME.
GMCODE-GM_CODE = '01'.   "01 - MB01 - Goods Receipts for Purchase Order

LOOP AT PCITAB.
  CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
      EXPORTING
        INPUT  = PCITAB-MATERIAL
      IMPORTING
        OUTPUT = PCITAB-MATERIAL.
  ITAB-MOVE_TYPE  = PCITAB-MVT_TYPE.
  ITAB-MVT_IND    = 'B'.
  ITAB-PLANT      = PCITAB-PLANT.
  ITAB-MATERIAL   = PCITAB-MATERIAL.
  ITAB-ENTRY_QNT  = PCITAB-QTY.
  ITAB-MOVE_STLOC = PCITAB-RECV_LOC.
  ITAB-STGE_LOC   = PCITAB-ISSUE_LOC.
  ITAB-PO_NUMBER  = PCITAB-PUR_DOC.
  ITAB-PO_ITEM    = PCITAB-PO_ITEM.
  CONCATENATE PCITAB-DEL_NO PCITAB-DEL_ITEM INTO ITAB-ITEM_TEXT.
  ITAB-MOVE_REAS  = PCITAB-SCRAP_REASON.

  APPEND ITAB.
ENDLOOP.

LOOP AT ITAB.
  WRITE:/ ITAB-MATERIAL, ITAB-PLANT, ITAB-STGE_LOC,
          ITAB-MOVE_TYPE, ITAB-ENTRY_QNT, ITAB-ENTRY_UOM,
          ITAB-ENTRY_UOM_ISO, ITAB-PO_NUMBER, ITAB-PO_ITEM.
*                                              PCITAB-EXT_DOC.
ENDLOOP.

CALL FUNCTION 'BAPI_GOODSMVT_CREATE'
  EXPORTING
    GOODSMVT_HEADER             = GMHEAD
    GOODSMVT_CODE               = GMCODE
*   TESTRUN                     = ' '
 IMPORTING
    GOODSMVT_HEADRET            = MTHEAD
*   MATERIALDOCUMENT            =
*   MATDOCUMENTYEAR             =
  TABLES
    GOODSMVT_ITEM               = ITAB
*   GOODSMVT_SERIALNUMBER       =
    RETURN                      = ERRMSG
          .
CLEAR ERRFLAG.
LOOP AT ERRMSG.
  IF ERRMSG-TYPE EQ 'E'.
    WRITE:/'Error in function', ERRMSG-MESSAGE.
    ERRFLAG = 'X'.
  ELSE.
    WRITE:/ ERRMSG-MESSAGE.
  ENDIF.
ENDLOOP.

IF ERRFLAG IS INITIAL.
  COMMIT WORK AND WAIT.
  IF SY-SUBRC NE 0.
    WRITE:/ 'Error in updating'.
    EXIT.
  ELSE.
    WRITE:/ MTHEAD-MAT_DOC, MTHEAD-DOC_YEAR.
    PERFORM UPD_STA.
  ENDIF.
ENDIF.
ENDFORM.                    " GET_DATA
 
BAPI_GOODSMVT_CREATE  GOODSMVT_CODE参数对应值 01     MB01
                                              02     MB31
                                              03     MB1A
                                              04     MB1B
                                              05     MB1C
                                              06     MB11
                                              07     MB04
阅读(15845) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~