SAP R/3 форум ABAP консультантов
Russian ABAP Developer's Club

Home - FAQ - Search - Memberlist - Usergroups - Profile - Log in to check your private messages - Register - Log in - English
Blogs - Weblogs News

BAPI_GOODSMVT_CREATE



 
Post new topic   Reply to topic    Russian ABAP Developer's Club Forum Index -> PP
View previous topic :: View next topic  
Author Message
admin
Администратор
Администратор



Joined: 01 Sep 2007
Posts: 1639

PostPosted: Thu Jan 21, 2010 3:58 pm    Post subject: BAPI_GOODSMVT_CREATE Reply with quote

Code:
* GMCODE Table T158G - 01 - MB01 - Goods Receipts for Purchase Order
*                      02 - MB31 - Goods Receipts for Prod Order
*                      03 - MB1A - Goods Issue
*                      04 - MB1B - Transfer Posting
*                      05 - MB1C - Enter Other Goods Receipt
*                      06 - MB11
*
* Domain: KZBEW - Movement Indicator
*      Goods movement w/o reference
*  B - Goods movement for purchase order
*  F - Goods movement for production order
*  L - Goods movement for delivery note
*  K - Goods movement for kanban requirement (WM - internal only)
*  O - Subsequent adjustment of "material-provided" consumption
*  W - Subsequent adjustment of proportion/product unit material

*&---------------------------------------------------------------------*
*& Report  ZCNRPP0018                                                  *
*& description: AKMC WO 超领物料自动过帐                              *
*& author  : tom.bai                                                   *
*& date: 20080309                                                      *
*&---------------------------------------------------------------------*

REPORT  ZCNRPP0018                              .

TABLES: RESB,
        RLGRAP,
        AFKO.
* FLAG
DATA: FLAG(4).


DATA:BEGIN OF LT_ITEM OCCURS 0,
      AUFNR LIKE AFKO-AUFNR,
      MATNR LIKE RESB-MATNR,
      ERFMG LIKE RESB-ERFMG.
DATA:END OF LT_ITEM.

*Material Document Header Data

DATA: LT_GM_HEAD TYPE STANDARD TABLE OF BAPI2017_GM_HEAD_01,
      L_GM_HEAD  LIKE BAPI2017_GM_HEAD_01,

* New Key Assignment GM_CODE to Transaction of Inv. Mgmt
      LT_GM_CODE TYPE STANDARD TABLE OF BAPI2017_GM_CODE,
      L_GM_CODE  LIKE BAPI2017_GM_CODE,

      LT_MAT_DOC TYPE STANDARD TABLE OF BAPI2017_GM_HEAD_RET,
      L_MAT_DOC LIKE BAPI2017_GM_HEAD_RET,


      LT_GM_ITEM TYPE STANDARD TABLE OF BAPI2017_GM_ITEM_CREATE,
      L_GM_ITEM LIKE BAPI2017_GM_ITEM_CREATE,

 

      LT_RETURN TYPE STANDARD TABLE OF BAPIRET2,
      L_RETURN  TYPE BAPIRET2,

      L_ERRFLAG(1) TYPE C.
*以发料小于需求量,
DATA: LT_GM_ITEM1 TYPE STANDARD TABLE OF BAPI2017_GM_ITEM_CREATE,
      L_GM_ITEM1 LIKE BAPI2017_GM_ITEM_CREATE.

 

 


SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-001.
PARAMETERS: P_FILE LIKE RLGRAP-FILENAME DEFAULT 'C:\WOexcess.TXT'.
PARAMETERS: P_INDEX AS CHECKBOX .
SELECTION-SCREEN END OF BLOCK B1.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_FILE.
  PERFORM GET_FILE_NAME CHANGING P_FILE.

INITIALIZATION.
  PERFORM INITIAL_ITAB.

START-OF-SELECTION.
  PERFORM GET_DATA.
  PERFORM PROCESS_DATA.
  PERFORM CALL_BAPI_PROCESS.

*&---------------------------------------------------------------------*
*&      Form  GET_FILE_NAME
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      <--P_P_FILE  text
*----------------------------------------------------------------------*
FORM GET_FILE_NAME  CHANGING P_FILE.
  CALL FUNCTION 'WS_FILENAME_GET'
    EXPORTING
      MASK             = '*.txt.'
      MODE             = '0'
      TITLE            = '选取数据文件路径'
    IMPORTING
      FILENAME         = P_FILE
    EXCEPTIONS
      INV_WINSYS       = 1
      NO_BATCH         = 2
      SELECTION_CANCEL = 3
      SELECTION_ERROR  = 4
      OTHERS           = 5.
ENDFORM.                    " GET_FILE_NAME
*&---------------------------------------------------------------------*
*&      Form  INITIAL_ITAB
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM INITIAL_ITAB .
  CLEAR:LT_ITEM,L_GM_HEAD,L_GM_CODE,L_MAT_DOC,L_GM_ITEM,L_RETURN.
  REFRESH: LT_ITEM,LT_GM_HEAD, LT_GM_CODE, LT_MAT_DOC ,LT_GM_ITEM, LT_RETURN.
  FLAG = 'YES'.
ENDFORM.                    " INITIAL_ITAB
*&---------------------------------------------------------------------*
*&      Form  GET_DATA
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM GET_DATA .
  CALL FUNCTION 'WS_UPLOAD'
    EXPORTING
      FILENAME     = P_FILE
      FILETYPE     = 'DAT'
    TABLES
      DATA_TAB     = LT_ITEM.
  IF SY-SUBRC NE 0.
    EXIT.
  ELSE.
    LOOP AT LT_ITEM.
      CALL FUNCTION 'CONVERSION_EXIT_MATN1_INPUT'
        EXPORTING
          INPUT      = LT_ITEM-MATNR
        IMPORTING
          OUTPUT     = LT_ITEM-MATNR.
      MODIFY LT_ITEM.
    ENDLOOP.
  ENDIF.

ENDFORM.                    " GET_DATA
*&---------------------------------------------------------------------*
*&      Form  PROCESS_DATA
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM PROCESS_DATA .
  LOOP AT LT_ITEM.
    SELECT SINGLE RSNUM INTO AFKO-RSNUM   "得到预留单号
      FROM AFKO
      WHERE AUFNR = LT_ITEM-AUFNR.
    L_GM_ITEM-RESERV_NO = AFKO-RSNUM.
    L_GM_ITEM-MATERIAL  = LT_ITEM-MATNR.
    L_GM_ITEM-ORDERID   = LT_ITEM-AUFNR.
    L_GM_ITEM-ENTRY_QNT = LT_ITEM-ERFMG.
    APPEND L_GM_ITEM TO LT_GM_ITEM.
    CLEAR :L_GM_ITEM,LT_ITEM.
  ENDLOOP.

  LOOP AT LT_GM_ITEM INTO L_GM_ITEM.
    SELECT SINGLE RSPOS WERKS LGORT ENMNG BDMNG
      INTO (RESB-RSPOS,RESB-WERKS,RESB-LGORT,RESB-ENMNG,RESB-BDMNG) "得到预留单项号,工厂,库位
      FROM RESB
      WHERE RSNUM = L_GM_ITEM-RESERV_NO
        AND MATNR = L_GM_ITEM-MATERIAL.
    IF RESB-ENMNG >= RESB-BDMNG.
      L_GM_ITEM-RES_ITEM = RESB-RSPOS.
      L_GM_ITEM-PLANT = RESB-WERKS.
      L_GM_ITEM-STGE_LOC = RESB-LGORT.
      L_GM_ITEM-MOVE_TYPE  = '261'.
      L_GM_ITEM-ENTRY_UOM  = 'ST'.
      L_GM_ITEM-IND_PROPOSE_QUANX = 'X'.
      MODIFY LT_GM_ITEM FROM L_GM_ITEM.
    ELSEIF RESB-ENMNG < RESB-BDMNG.
      L_GM_ITEM1-ORDERID   = L_GM_ITEM-ORDERID.
      L_GM_ITEM1-MATERIAL  = L_GM_ITEM-MATERIAL.
      L_GM_ITEM1-ENTRY_QNT = L_GM_ITEM-ENTRY_QNT.
      APPEND L_GM_ITEM1 TO LT_GM_ITEM1.
      CLEAR L_GM_ITEM1.
    ENDIF.
  ENDLOOP.
  IF P_INDEX = 'X'.
    LOOP AT LT_GM_ITEM INTO L_GM_ITEM.
      WRITE:/ L_GM_ITEM-ORDERID ,L_GM_ITEM-MATERIAL,L_GM_ITEM-RESERV_NO,L_GM_ITEM-RES_ITEM,L_GM_ITEM-ENTRY_QNT.
    ENDLOOP.

  ENDIF.
ENDFORM.                    " PROCESS_DATA
*&---------------------------------------------------------------------*
*&      Form  CALL_BAPI_PROCESS
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM CALL_BAPI_PROCESS .

*SET BAPI HEAD
  L_GM_HEAD-PSTNG_DATE = SY-DATUM.
  L_GM_HEAD-DOC_DATE    = SY-DATUM.
  L_GM_HEAD-PR_UNAME    = SY-UNAME.


  IF P_INDEX = 'X'.
    CALL FUNCTION 'BAPI_GOODSMVT_CREATE'
      EXPORTING
        GOODSMVT_HEADER = L_GM_HEAD
        GOODSMVT_CODE   = '03'
        TESTRUN         = P_INDEX
      IMPORTING
        GOODSMVT_HEADRET  = L_MAT_DOC
      TABLES
        GOODSMVT_ITEM     = LT_GM_ITEM
        RETURN            = LT_RETURN.
     LOOP AT LT_RETURN INTO L_RETURN .
       IF L_RETURN-TYPE = 'E'.
         IF SY-TABIX = 1.
           SKIP.
         ENDIF.
         WRITE:/ L_RETURN-TYPE, L_RETURN-ID,L_RETURN-MESSAGE.
         CLEAR L_RETURN.
       ENDIF.
     ENDLOOP.
   ELSEIF P_INDEX NE 'X'.
     CALL FUNCTION 'BAPI_GOODSMVT_CREATE'
        EXPORTING
          GOODSMVT_HEADER = L_GM_HEAD
          GOODSMVT_CODE   = '03'
*          TESTRUN         = P_INDEX
        IMPORTING
          GOODSMVT_HEADRET  = L_MAT_DOC
        TABLES
          GOODSMVT_ITEM     = LT_GM_ITEM
          RETURN            = LT_RETURN.
         
         
     LOOP AT LT_RETURN INTO L_RETURN .
       IF L_RETURN-TYPE = 'E'.
         FLAG = 'NO'.
       ENDIF.
     ENDLOOP.
     IF FLAG = 'YES'.
       CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
          EXPORTING
            WAIT = 'X'.
        WRITE:/ L_MAT_DOC-MAT_DOC,L_MAT_DOC-DOC_YEAR.
     ELSEIF FLAG = 'NO'.
       MESSAGE I005(YMESS) WITH 'ERROR'.
     ENDIF.
   ENDIF.
ENDFORM.                    " CALL_BAPI_PROCESS
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Russian ABAP Developer's Club Forum Index -> PP All times are GMT + 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum


All product names are trademarks of their respective companies. SAPNET.RU websites are in no way affiliated with SAP AG.
SAP, SAP R/3, R/3 software, mySAP, ABAP, BAPI, xApps, SAP NetWeaver and any other are registered trademarks of SAP AG.
Every effort is made to ensure content integrity. Use information on this site at your own risk.