Sie sind auf Seite 1von 3

*&---------------------------------------------------------------------* *& Report ZBAPI_MB1B_SLOC *& Developed By : - Gamot Bharat *& *&---------------------------------------------------------------------* *& Interface Developement for Material

movement, from Storage Location to *& Storage Location. BAPI for Movement Type "311". *& USE TEXT FILE (NOTEPAD FILE) FOR UPLOAD. *&---------------------------------------------------------------------* REPORT ZBAPI_MB1B_SLOC. DATA: IT_GOODSMVT_HEADER LIKE BAPI2017_GM_HEAD_01 OCCURS 0 WITH HEADER LINE, IT_GOODSMVT_CODE LIKE BAPI2017_GM_CODE OCCURS 0 WITH HEADER LINE, IT_GOODSMVT_ITEM LIKE BAPI2017_GM_ITEM_CREATE OCCURS 0 WITH HEADER LINE , IT_GOODSMVT_HEADRET LIKE BAPI2017_GM_HEAD_RET OCCURS 0 WITH HEADER LINE, IT_RETURN LIKE BAPIRET2 OCCURS 0 WITH HEADER LINE, IT_RETURN1 LIKE BAPIRET2 OCCURS 0 WITH HEADER LINE , WAIT1 TYPE BAPIWAIT. DATA: BEGIN OF IT_DATA OCCURS 0, DOC_DATE LIKE BAPI2017_GM_HEAD_01-DOC_DATE, PSTNG_DATE LIKE BAPI2017_GM_HEAD_01-PSTNG_DATE, HEADER_TXT LIKE BAPI2017_GM_HEAD_01-HEADER_TXT, GM LIKE BAPI2017_GM_CODE-GM_CODE, MOV LIKE BAPI2017_GM_ITEM_CREATE-MOVE_TYPE, PLAN LIKE BAPI2017_GM_ITEM_CREATE-PLANT, STGE LIKE BAPI2017_GM_ITEM_CREATE-STGE_LOC, MOVE_MAT LIKE BAPI2017_GM_ITEM_CREATE-MOVE_MAT, MOVE_PLANT LIKE BAPI2017_GM_ITEM_CREATE-MOVE_PLANT, MOVE_STLOC LIKE BAPI2017_GM_ITEM_CREATE-MOVE_STLOC, MATERIAL LIKE BAPI2017_GM_ITEM_CREATE-MATERIAL, ENTRY_QNT LIKE BAPI2017_GM_ITEM_CREATE-ENTRY_QNT, ENTRY_UOM LIKE BAPI2017_GM_ITEM_CREATE-ENTRY_UOM, BATCH LIKE BAPI2017_GM_ITEM_CREATE-BATCH, END OF IT_DATA. TYPES : BEGIN OF T_RECORD, SRNO(6) TYPE C, MBLNR TYPE MBLNR, MJAHR TYPE MJAHR, MESSAGE TYPE BAPI_MSG, END OF T_RECORD. DATA : IT_RECORD WA_RECORD TYPE TABLE OF T_RECORD, TYPE T_RECORD.

PARAMETER : FNAME LIKE RLGRAP-FILENAME OBLIGATORY. DATA : WS_FNAME TYPE STRING. DATA : WF_MBLNR TYPE MBLNR, WF_MJAHR TYPE MJAHR, SRNO(6) TYPE C, WF_MESSAGE TYPE BAPI_MSG. AT SELECTION-SCREEN ON VALUE-REQUEST FOR FNAME. CALL FUNCTION 'KD_GET_FILENAME_ON_F4' EXPORTING FIELD_NAME = FNAME

CHANGING FILE_NAME = FNAME . IF SY-SUBRC <> 0. MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4. ENDIF. START-OF-SELECTION. WS_FNAME = FNAME. CALL FUNCTION 'GUI_UPLOAD' EXPORTING FILENAME = WS_FNAME FILETYPE = 'ASC' HAS_FIELD_SEPARATOR = 'X' TABLES DATA_TAB = IT_DATA. IF SY-SUBRC <> 0. MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4. ENDIF. LOOP AT IT_DATA. IT_GOODSMVT_HEADER-PSTNG_DATE = IT_DATA-PSTNG_DATE. IT_GOODSMVT_HEADER-DOC_DATE = IT_DATA-DOC_DATE. IT_GOODSMVT_HEADER-HEADER_TXT = IT_DATA-HEADER_TXT. APPEND IT_GOODSMVT_HEADER. IT_GOODSMVT_CODE-GM_CODE APPEND IT_GOODSMVT_CODE. IT_GOODSMVT_ITEM-MOVE_TYPE IT_GOODSMVT_ITEM-PLANT IT_GOODSMVT_ITEM-STGE_LOC IT_GOODSMVT_ITEM-MOVE_MAT IT_GOODSMVT_ITEM-MOVE_PLANT IT_GOODSMVT_ITEM-MOVE_STLOC IT_GOODSMVT_ITEM-MATERIAL IT_GOODSMVT_ITEM-ENTRY_QNT IT_GOODSMVT_ITEM-ENTRY_UOM IT_GOODSMVT_ITEM-BATCH APPEND IT_GOODSMVT_ITEM. = IT_DATA-GM . = = = = = = = = = = IT_DATA-MOV. IT_DATA-PLAN. IT_DATA-STGE. IT_DATA-MOVE_MAT. IT_DATA-MOVE_PLANT. IT_DATA-MOVE_STLOC. IT_DATA-MATERIAL. IT_DATA-ENTRY_QNT. IT_DATA-ENTRY_UOM. IT_DATA-BATCH.

CALL FUNCTION 'BAPI_GOODSMVT_CREATE' EXPORTING GOODSMVT_HEADER = IT_GOODSMVT_HEADER GOODSMVT_CODE = IT_GOODSMVT_CODE TESTRUN = ' ' IMPORTING GOODSMVT_HEADRET = IT_GOODSMVT_HEADRET MATERIALDOCUMENT = WF_MBLNR MATDOCUMENTYEAR = WF_MJAHR TABLES GOODSMVT_ITEM = IT_GOODSMVT_ITEM RETURN = IT_RETURN. SRNO = SRNO + 1. IF NOT WF_MBLNR IS INITIAL.

CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'. WA_RECORD-SRNO = SRNO. WA_RECORD-MBLNR = WF_MBLNR. WA_RECORD-MJAHR = WF_MJAHR. APPEND WA_RECORD TO IT_RECORD. WAIT UP TO 1 SECONDS. ELSE. CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'. READ TABLE IT_RETURN WITH KEY TYPE = 'E'. CALL FUNCTION 'MESSAGE_TEXT_BUILD' EXPORTING MSGID = IT_RETURN-ID MSGNR = IT_RETURN-NUMBER MSGV1 = IT_RETURN-MESSAGE_V1 MSGV2 = IT_RETURN-MESSAGE_V4 MSGV3 = IT_RETURN-MESSAGE_V3 MSGV4 = IT_RETURN-MESSAGE_V4 IMPORTING MESSAGE_TEXT_OUTPUT = WF_MESSAGE. WA_RECORD-SRNO = SRNO. WA_RECORD-MESSAGE = WF_MESSAGE. APPEND WA_RECORD TO IT_RECORD. ENDIF. CLEAR : IT_GOODSMVT_HEADER, IT_RETURN[], IT_GOODSMVT_CODE , IT_GOODSMVT_HEADRET[], IT_GOODSMVT_ITEM[], WF_MBLNR, WF_MJAHR, WF_MESSAGE, WA_RECORD. ENDLOOP. LOOP AT IT_RECORD INTO WA_RECORD. WRITE :/ WA_RECORD-SRNO, WA_RECORD-MBLNR, WA_RECORD-MJAHR, WA_RECORD-MESSAGE. CLEAR WA_RECORD. ENDLOOP.