. REPORT ZTY_MM_BAPI_REQUIREMENTS * bapi datadata: req_item like BAPISITEMR.data: req_data like BAPISSHDIN occurs 0 with header line.data: RETURN LIKE BAPIRETURN1 OCCURS 0 WITH HEADER LINE.data: matertemp like BAPISITEMR-MATERIAL.data: begin of wa_itab, index type i "No. matnr like BAPISITEMR-mATERIAL," material coding REQ_QTY like BAPISSHDIN-REQ_QTY, "the number of planned end of wa_itab.data: itab like wa_itab occurs 0 with header line.data:. matemp like BAPISITEMR-mATERIAL" material coding data: begin Of Log Occurs 0, INDEX TYPE I, "Sequence Message Like Return-Message," Message Text End of Log.
SELECTION-SCREEN: BEGIN OF BLOCK FRAME01 WITH FRAME TITLE Text-001.parameters: p_number like pbpt-pbdnr obligatory.parameters: p_today like sy-datum obligatory.parameters: TXTFILE like rlgrap-filename default 'c: /material.txt' obligatory .parameters: logfile like rlgrap-filename default 'c: /log.txt' obligatory.SELECTION-SCREEN: END OF BLOCK FRAME01.SELECTION-SCREEN: BEGIN OF BLOCK FRAME02 WITH FRAME TITLE TEXT-002.SELECTION-SCREEN COMMENT / 5 ( 40) text-003.selection-screen: end of block frame02.
Start-of-selection. Perform frm_create_requ.end-of-selection. * ----------- UPLOAD DATA --------- form frm_get_data.call function 'ws_upload' EXPORTING * CODEPAGE = '' FILENAME = tXTFILE FILETYPE = 'DAT' * HEADLEN = '' * LINE_EXIT = '' * TRUNCLEN = '' * USER_FORM = '' * USER_PROG = '' * DAT_D_FORMAT = '' * IMPORTING * fILELENGTH = TABLES DATA_TAB = ITAB EXCEPTIONS CONVERSION_ERROR = 1 FILE_OPEN_ERROR = 2 FILE_READ_ERROR = 3 INVALID_TYPE = 4 NO_BATCH = 5 UNKNOWN_ERROR = 6 INVALID_TABLE_WIDTH = 7 GUI_REFUSE_FILETRANSFER = 8 CUSTOMER_ERROR = 9 OTHERS = 10 .IF SY-SUBRC <> 0.Write: 'Upload data error, please check if the text file exists or format an error!'. * Message ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO * WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.Exit.Endif.Endform. * Loop at itab. * Itab-index = SY-INDEX. * ITAB-Plan = '8000'. * ITAB-REQU = 'vse'. * ITAB-V = 'X'. * Itab-req_number = p_number. * Modify itab. * Endloop. * ----------- UPLOAD DATA END ------ * ---------- Create Requirements --- Form FRM_CREATE_REQU. loop at itab. Concatenate '00000000000'
itab-matnr into matertemp. req_item-material = matertemp. req_item-plant = '8000'. req_item-REQU_TYPE = 'VSE'. req_item-VERSION = '00'. req_item-VERS_ACTIV = 'X'. req_item-req_number = p_number.
req_data-DATE_TYPE = 3. req_data-req_date = p_today. req_data-REQ_QTY = itab-REQ_QTY. append req_data. CALL FUNCTION 'BAPI_REQUIREMENTS_CREATE' EXPORTING REQUIREMENTS_ITEM = req_item * REQUIREMENT_PARAM = IMPORTING MATERIAL = matemp * PLANT = * REQUIREMENTSTYPE = * VERSION = * REQMTSPLANNUMBER = TABLES REQUIREMENTS_SCHEDULE_IN = REQ_data * REQUIREMENTS_CHAR_IN = RETURN = RETURN IF NOT matemp IS INITIAL WRITE:.. / (10) matemp COLOR 4, (50) 'was created successfully' else log-index = itab-index log-message =... Return-Message. Append log. endif.clear namemp.refresh Req_data.clear Matertemp.clear Req_item.endloop.call function 'ws_download' exporting filename = LOGFILE FILETYPE = 'DAT' TABLES DATA_TAB = LOG EXCEPTIONS INVALID_FILESIZE = 1 INVALID_TABLE_WIDTH = 2 INVALID_TYPE = 3 NO_BATCH = 4 UNKNOWN_ERROR = 5 GUI_REFUSE_FILETRANSFER = 6 CUSTOMER_ERROR = 7 OTHERS = 8 .IF SY-SUBRC <> 0. * MESSAGE ID SY- MSGID TYPE SY-MSGTY NUMBER SY-MSGNO * WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.ENDIF.