创建月需求计划

REPORT ZTY_MM_BAPI_REQUIREMENTS .
*bapi data
data: 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,  "序号
          matnr like BAPISITEMR-MATERIAL,     "物料编码
          REQ_QTY like BAPISSHDIN-REQ_QTY,    "计划数量
      end of wa_itab.
data: itab like wa_itab occurs 0 with header line.
data: matemp like BAPISITEMR-MATERIAL.  "物料编码
data: begin of log occurs 0,
         index type i,  "序号
         MESSAGE like return-message,  "消息文本
      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_GET_DATA.
  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 : '上载数据出错,请检查文本文件是否存在或格式错误!'.
* 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) '创建成功'.
 else.
       log-index = itab-index.
       log-message = return-MESSAGE.
       append log.
 ENDIF.
clear matemp.
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.

write : '批输入结束!请检查LOG文件!'.
endform.
*----------create end------------

你可能感兴趣的:(SAP相关)