当前位置:   article > 正文

SAP 批量创建生产订单(工单)并下达 BAPI_PRODORD_CREATE <转载>_sap增加生产订单组件

sap增加生产订单组件

原文链接:https://blog.csdn.net/xiaofei2008gxh/article/details/123198226
在这里插入图片描述
实际成果
在这里插入图片描述
在这里插入图片描述
说重点 上代码

*&---------------------------------------------------------------------*
*& REPORT  ZRPT_PP_ORDER_CREATEM
*&
*&---------------------------------------------------------------------*
*&DATE:20220228
*&AUTHOR:gavin
*&TITLE:生产订单批量生成 4 
*&TCODE: ZCO01
*&---------------------------------------------------------------------*
 
REPORT ZRPT_PP_ORDER_CREATEM.
TABLES:ZPPCOSTMDATA,SSCRFIELDS.
*
*定义内表类型
*
TYPES: BEGIN OF W_ITAB,
MATNR LIKE BAPI_PP_ORDER_CREATE-MATERIAL,
WERKS LIKE BAPI_PP_ORDER_CREATE-PLANT,
QUANTT LIKE BAPI_PP_ORDER_CREATE-QUANTITY,
VERID LIKE BAPI_PP_ORDER_CREATE-PROD_VERSION,
START LIKE BAPI_PP_ORDER_CREATE-BASIC_START_DATE,
ENDDT LIKE BAPI_PP_ORDER_CREATE-BASIC_END_DATE,
AUFNR LIKE BAPI_PP_ORDER_CREATE-ORDER_NUMBER,
MSGTXT LIKE      BAPIRET2-MESSAGE,
RELSTT TYPE C,"下达生产订单的状态
MSGREL LIKE      BAPIRET2-MESSAGE,
END OF W_ITAB.
 
FIELD-SYMBOLS: <FS>.
 
DATA:
      FILETAB TYPE FILETABLE WITH HEADER LINE,
      RC TYPE I,
      G_FILE TYPE RLGRAP-FILENAME,
      LT_RETURN TYPE TABLE OF BAPIRET2 WITH HEADER LINE,
      LT_AUFNR TYPE AUFNR,
      ITAB TYPE TABLE OF ALSMEX_TABLINE WITH HEADER LINE.
DATA: WTAB TYPE TABLE OF W_ITAB WITH HEADER LINE.
DATA: COUNT TYPE I.
DATA:STDATUM LIKE SY-DATUM,
      STUZEIT LIKE SY-UZEIT.
DATA:L_FILENAME TYPE STRING,L_MUBAN TYPE STRING.
DATA:GV_FULLPATH TYPE STRING,GV_PATH TYPE STRING,GV_NAME TYPE STRING.
 
data:header_in TYPE BAPI_PP_ORDER_CREATE.
 
*&---------------------------------------------------------------------*
*& 选择界面
*&---------------------------------------------------------------------*
SELECTION-SCREEN BEGIN OF BLOCK BLK1 WITH FRAME TITLE TXT1 .
 
PARAMETER:PAUART TYPE PP_AUFART OBLIGATORY DEFAULT 'ZP05'.
PARAMETER:P_FILE  TYPE STRING OBLIGATORY.
*PARAMETER:DELFLG AS CHECKBOX DEFAULT 'X'.
SELECTION-SCREEN END OF BLOCK BLK1.
 
SELECTION-SCREEN SKIP.
SELECTION-SCREEN BEGIN OF LINE.
*SELECTION-SCREEN PUSHBUTTON 5(60) but1 USER-COMMAND bt1.
SELECTION-SCREEN PUSHBUTTON 5(20) but2 USER-COMMAND bt2.
SELECTION-SCREEN END OF LINE.
 
INITIALIZATION.
  TXT1 = '请输入条件'.
 "生产订单类型固定且不可改 
  LOOP AT SCREEN.
    IF SCREEN-NAME = 'PAUART'.
      SCREEN-INPUT = '0'.
      MODIFY SCREEN.
    ENDIF.
 
  ENDLOOP.
*  CALL FUNCTION 'ICON_CREATE'
*    EXPORTING
*      name                  = ICON_BW_REF_STRUCTURE_SAP
*      TEXT                  = 'SM30维护 视图 ZPPCOSTMDATA'
*      INFO                  = 'SM30维护 视图 ZPPCOSTMDATA'
*    IMPORTING
*      result                = but1
*    EXCEPTIONS
*      icon_not_found        = 1
*      outputfield_too_short = 2
*      OTHERS                = 3.
 
  CALL FUNCTION 'ICON_CREATE'
    EXPORTING
      name                  = ICON_BW_REF_STRUCTURE_SAP
      TEXT                  = '下载维护模板'
      INFO                  = '下载维护模板'
    IMPORTING
      result                = but2
    EXCEPTIONS
      icon_not_found        = 1
      outputfield_too_short = 2
      OTHERS                = 3.
 
*&---------------------------------------------------------------------
 
AT SELECTION-SCREEN.
  CASE SSCRFIELDS-UCOMM.
*    WHEN 'BT1'.
*      PERFORM CALLSM30.
    WHEN 'BT2'.
      PERFORM DOWNLOAD_DATA.
  ENDCASE.
 
AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_FILE.
 
  CALL METHOD CL_GUI_FRONTEND_SERVICES=>FILE_OPEN_DIALOG
    EXPORTING
      DEFAULT_FILENAME = P_FILE
    CHANGING
      RC               = RC
      FILE_TABLE       = FILETAB[].
 
  READ TABLE  FILETAB INDEX  1.
  IF SY-SUBRC EQ 0.
    P_FILE = FILETAB-FILENAME.
  ENDIF.
 
START-OF-SELECTION.
 
  STDATUM = SY-DATUM.
  STUZEIT = SY-UZEIT.
 
  if p_file <> ''.
    PERFORM GETEXCEL."EXCEL数据获取
*  else.
*    MESSAGE '请选择要导入的excel文件' TYPE I.
*    perform getdata."获取版本描述表中数据
  endif.
  COUNT = 0.
  PERFORM WRITERPTRUNRECORD.
  PERFORM DISPLAY."数据ALV输出
 
END-OF-SELECTION.
 
*&---------------------------------------------------------------------*
*&      Form  WRITERPTRUNRECORD
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM WRITERPTRUNRECORD.
 
  get time.
  CALL FUNCTION 'ZSYS_RPT_RUNRECORD'
    EXPORTING
      TCODE     = SY-TCODE
      PROGRAMM  = SY-CPROG
      DATUMRST  = STDATUM
      UZEITRST  = STUZEIT
      BATCH     = SY-BATCH
      DATUMREND = SY-datum
      UZEITREND = sy-UZEIT
      DATUMC    = '20220228'
      RUNNER    = SY-UNAME
      RPTSRC    = 'cfp'.
 
ENDFORM.                    "WRITERPTRUNRECORD
 
*&---------------------------------------------------------------------*
*&      FORM  DISPLAY
*&---------------------------------------------------------------------*
*       TEXT 数据展示
*----------------------------------------------------------------------*
*  -->  P1        TEXT
*  <--  P2        TEXT
*----------------------------------------------------------------------*
FORM DISPLAY .
  DATA: IT_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV,
        IS_VARIANT LIKE DISVARIANT,
        IT_EVENTS   TYPE SLIS_T_EVENT,
        IS_LAYOUT   TYPE SLIS_LAYOUT_ALV,
        TITLE       TYPE LVC_TITLE,
        I_CALLBACK_PROGRAM TYPE SY-REPID,
        IT_SORT     TYPE SLIS_T_SORTINFO_ALV WITH HEADER LINE,
          I_GRID_SETTINGS TYPE LVC_S_GLAY.
  I_GRID_SETTINGS-EDT_CLL_CB = 'X'. "更改数据后更新表数据.
  PERFORM FIELDCAT_INIT USING IT_FIELDCAT.
  PERFORM LAYOUT_INIT USING IS_LAYOUT.
  I_CALLBACK_PROGRAM = SY-REPID.
 
  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
      I_CALLBACK_PROGRAM       = I_CALLBACK_PROGRAM
      I_GRID_TITLE             = TITLE
      I_GRID_SETTINGS          = I_GRID_SETTINGS
      IS_LAYOUT                = IS_LAYOUT
      I_CALLBACK_PF_STATUS_SET = 'SET_PF_STATUS'
      I_CALLBACK_USER_COMMAND  = 'USER_COMMAND'
      IT_FIELDCAT              = IT_FIELDCAT
      IT_EVENTS                = IT_EVENTS
    TABLES
      T_OUTTAB                 = WTAB[]
    EXCEPTIONS
      PROGRAM_ERROR            = 1
      OTHERS                   = 2.
  IF SY-SUBRC <> 0.
  ENDIF.
 
ENDFORM.                    " DISPLAY
 
*&--------------------------------------------------------------------- *
*&      Form  g_status_form 调用自定义屏幕
*&---------------------------------------------------------------------
FORM SET_PF_STATUS  USING rt_extab TYPE slis_t_extab.
  SET PF-STATUS 'STANDARD' EXCLUDING rt_extab.
ENDFORM.                    "SET_PF_STATUS
 
*&---------------------------------------------------------------------*
*&      FORM  FIELDCAT_INIT
*&---------------------------------------------------------------------*
*       TEXT 定义输出项
*----------------------------------------------------------------------*
*      -->P_IT_FIELDCAT  TEXT
*----------------------------------------------------------------------*
FORM FIELDCAT_INIT  USING  IT_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV.
  DATA: LS_FIELDCAT TYPE SLIS_FIELDCAT_ALV.
  DATA:LOC_REPID LIKE SY-REPID.
  LOC_REPID = SY-REPID.
 
  LS_FIELDCAT-FIELDNAME = 'MATNR'.
  LS_FIELDCAT-REPTEXT_DDIC  = '物料'.
  APPEND LS_FIELDCAT TO IT_FIELDCAT.
  CLEAR LS_FIELDCAT.
 
  LS_FIELDCAT-FIELDNAME = 'WERKS'.
  LS_FIELDCAT-REPTEXT_DDIC  = '工厂'.
  APPEND LS_FIELDCAT TO IT_FIELDCAT.
  CLEAR LS_FIELDCAT.
 
  LS_FIELDCAT-FIELDNAME = 'QUANTT'.
  LS_FIELDCAT-REPTEXT_DDIC  = '数量'.
  APPEND LS_FIELDCAT TO IT_FIELDCAT.
  CLEAR LS_FIELDCAT.
 
  LS_FIELDCAT-FIELDNAME = 'VERID'.
  LS_FIELDCAT-REPTEXT_DDIC  = '生产版本'.
  APPEND LS_FIELDCAT TO IT_FIELDCAT.
  CLEAR LS_FIELDCAT.
 
  LS_FIELDCAT-FIELDNAME = 'START'.
  LS_FIELDCAT-REPTEXT_DDIC  = '开始日期'.
  LS_FIELDCAT-REF_TABNAME = 'CAUFV'.
  LS_FIELDCAT-REF_FIELDNAME = 'ERDAT'.
  APPEND LS_FIELDCAT TO IT_FIELDCAT.
  CLEAR LS_FIELDCAT.
 
  LS_FIELDCAT-FIELDNAME = 'ENDDT'.
  LS_FIELDCAT-REPTEXT_DDIC  = '结束日期'.
  LS_FIELDCAT-REF_TABNAME = 'CAUFV'.
  LS_FIELDCAT-REF_FIELDNAME = 'ERDAT'.
  APPEND LS_FIELDCAT TO IT_FIELDCAT.
  CLEAR LS_FIELDCAT.
 
  LS_FIELDCAT-FIELDNAME = 'AUFNR'.
  LS_FIELDCAT-REPTEXT_DDIC  = '生产订单号'.
  LS_FIELDCAT-NO_ZERO = 'X'.
  APPEND LS_FIELDCAT TO IT_FIELDCAT.
  CLEAR LS_FIELDCAT.
 
  LS_FIELDCAT-FIELDNAME = 'MSGTXT'.
  LS_FIELDCAT-REPTEXT_DDIC  = '消息文本'.
  APPEND LS_FIELDCAT TO IT_FIELDCAT.
  CLEAR LS_FIELDCAT.
 
  LS_FIELDCAT-FIELDNAME = 'RELSTT'.
  LS_FIELDCAT-REPTEXT_DDIC  = '生产订单下达状态'.
  APPEND LS_FIELDCAT TO IT_FIELDCAT.
  CLEAR LS_FIELDCAT.
 
  LS_FIELDCAT-FIELDNAME = 'MSGREL'.
  LS_FIELDCAT-REPTEXT_DDIC  = '生产订单下达文本'.
  APPEND LS_FIELDCAT TO IT_FIELDCAT.
  CLEAR LS_FIELDCAT.
 
ENDFORM.                    "FIELDCAT_INIT
" FIELDCAT_INIT
*&---------------------------------------------------------------------*
*&      FORM  LAYOUT_INIT
*&---------------------------------------------------------------------*
*       TEXT  LAYOUT属性设置,双击响应字段设置
*----------------------------------------------------------------------*
*      -->P_IS_LAYOUT  TEXT
*----------------------------------------------------------------------*
FORM LAYOUT_INIT  USING    IS_LAYOUT TYPE SLIS_LAYOUT_ALV.
  IS_LAYOUT-COLWIDTH_OPTIMIZE = 'X'.
ENDFORM.                    " LAYOUT_INIT
**&--------------------------------------------------------------------*
**&      FORM  USER_COMMAND
**&--------------------------------------------------------------------*
**       TEXT
**---------------------------------------------------------------------*
**      -->RF_UCOMM   TEXT
**      -->RS_SELFIELDTEXT
**---------------------------------------------------------------------*
FORM USER_COMMAND USING RF_UCOMM    LIKE SY-UCOMM
                       RS_SELFIELD TYPE SLIS_SELFIELD.      "#EC CALLED
  DATA:BEGIN OF ORDERLIST  OCCURS 0,
    AUFNR TYPE AUFNR,
  END OF ORDERLIST.
  data:pflg TYPE c.
 
  DATA:DELETERETURN TYPE TABLE OF BAPI_ORDER_RETURN.
  DATA:L_DELETERETURN LIKE LINE OF DELETERETURN.
  CASE RF_UCOMM.
    WHEN '&PRT'.
*****插入数据   创建生产订单
      if COUNT = 0.
        COUNT = COUNT + 1.
        CLEAR ORDERLIST[].
        loop at WTAB.
*        HEADER_IN-ORDER_NUMBER = LT_MOINFO-AUFNR."订单号
*          注意:物料前导0 要加上 
          CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
            EXPORTING
              INPUT  = WTAB-MATNR
            IMPORTING
              OUTPUT = HEADER_IN-MATERIAL.
*        HEADER_IN-MATERIAL =  WTAB-MATNR."物料编号
          HEADER_IN-PLANT = WTAB-WERKS."工厂
          HEADER_IN-ORDER_TYPE = PAUART."ORDER_TYPE."订单类型
          HEADER_IN-QUANTITY = WTAB-QUANTT."订单数量总计
          HEADER_IN-BASIC_START_DATE = WTAB-START."基本开始日期
          HEADER_IN-BASIC_END_DATE = WTAB-ENDDT."基本完成日期
          HEADER_IN-PROD_VERSION = WTAB-VERID."生产版本
          CALL FUNCTION 'BAPI_PRODORD_CREATE'
            EXPORTING
              ORDERDATA    = HEADER_IN
            IMPORTING
              ORDER_NUMBER = LT_AUFNR
              RETURN       = LT_RETURN.    "ORDER_TYPE = LT_AUART
 
 
          IF LT_AUFNR IS NOT INITIAL.
            ORDERLIST-AUFNR =  LT_AUFNR.
            APPEND ORDERLIST.
          ELSE.
            WTAB-RELSTT = 'E'.
            WTAB-MSGREL = '生产订单号为空,不能下达'.
          ENDIF.
 
          IF LT_AUFNR <> '' AND LT_RETURN IS INITIAL . "订单创建成功
            WTAB-AUFNR = LT_AUFNR.
            WTAB-MSGTXT = 'STATU = S,订单创建成功 '.
          ELSE.
            WTAB-MSGTXT = 'STATU = E,订单创建失败。' && LT_RETURN-MESSAGE.
          ENDIF.
          MODIFY WTAB.
        ENDLOOP.
        ”等待10s 否则会有生产订单不存在的提示 
        CALL FUNCTION 'AB_SLEEP'
          EXPORTING
            WAIT_TIME = 10.
 
        IF ORDERLIST[] IS NOT INITIAL.
          CALL FUNCTION 'BAPI_PRODORD_RELEASE'
            TABLES
              ORDERS        = ORDERLIST
              DETAIL_RETURN = DELETERETURN.
          LOOP AT WTAB.
            SHIFT WTAB-AUFNR LEFT DELETING LEADING '0'.
            LOOP AT DELETERETURN  INTO L_DELETERETURN WHERE  MESSAGE_V1 = WTAB-AUFNR.
              WTAB-RELSTT = L_DELETERETURN-TYPE.
              WTAB-MSGREL = L_DELETERETURN-MESSAGE.
              MODIFY WTAB.
            ENDLOOP.
          ENDLOOP.
        ENDIF.
        RS_SELFIELD-REFRESH = 'X'.
      ELSE.
        MESSAGE '订单已经创建并下达,请不要重复创建/下达' TYPE 'I'.
      ENDIF.
  ENDCASE.
ENDFORM.                   "USER_COMMAND
*&---------------------------------------------------------------------*
*&      FORM  GETEXCEL
*&---------------------------------------------------------------------*
*       TEXT 获取上传EXCEL文件内相关数据
*----------------------------------------------------------------------*
*  -->  P1        TEXT
*  <--  P2        TEXT
*----------------------------------------------------------------------*
FORM GETEXCEL .
  G_FILE = P_FILE.  "注意两个文件用于不同的函数,所以类型不同
 
  CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'
    EXPORTING
      FILENAME    = G_FILE
      I_BEGIN_COL = 1
      I_BEGIN_ROW = 1
      I_END_COL   = 10
      I_END_ROW   = 5000
    TABLES
      INTERN      = ITAB[].
 
  DELETE ITAB WHERE ROW = 1.  "删除字段名行
 
  LOOP AT ITAB.
    ON CHANGE OF ITAB-ROW.
      IF SY-TABIX NE 1.
        APPEND WTAB.
        CLEAR WTAB.
      ENDIF.
    ENDON.
    ASSIGN COMPONENT ITAB-COL OF STRUCTURE WTAB TO <FS>.         "动态方法将值传到相应的内表
    <FS> = ITAB-VALUE.
  ENDLOOP.
  APPEND WTAB.   "这句不要忘记,要把最后一条APPEND到内表中
  sort wtab by MATNR.
 
ENDFORM.                    " GETEXCEL
*&---------------------------------------------------------------------*
*&      Form  GETDATA
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM GETDATA .
 
*  SELECT *
*  INTO CORRESPONDING FIELDS OF TABLE WTAB
*  FROM  ZPPCOSTMDATA
*  WHERE KOSTL IN S_KOSTL AND
*        ZDEPT1 IN S_ZDEPT1 AND
*        ZDEPT2 IN S_ZDEPT2 AND
*        ZDEPT3 IN S_ZDEPT3 AND
*        ZDEPT4 IN S_ZDEPT4 AND
*        ZDEPT5 IN S_ZDEPT5.
*  SORT WTAB BY KOSTL.
 
ENDFORM.                    " GETDATA
*&---------------------------------------------------------------------*
*&      Form  CALLSM30
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM CALLSM30 .
  CALL FUNCTION 'VIEW_MAINTENANCE_CALL'
    EXPORTING
      action                       = 'U'          " S = Display U = Change T = Transport
      view_name                    = 'ZPPCOSTMDATA'     "读取的表
      no_warning_for_clientindep   = 'X'
    EXCEPTIONS
      client_reference             = 1
      foreign_lock                 = 2
      invalid_action               = 3
      no_clientindependent_auth    = 4
      no_database_function         = 5
      no_editor_function           = 6
      no_show_auth                 = 7
      no_tvdir_entry               = 8
      no_upd_auth                  = 9
      only_show_allowed            = 10
      system_failure               = 11
      unknown_field_in_dba_sellist = 12
      view_not_found               = 13
      OTHERS                       = 14.
ENDFORM.                    " CALLSM30
*&---------------------------------------------------------------------*
*&      Form  DOWNLOAD_DATA
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM DOWNLOAD_DATA .
  l_filename = 'ZPPORDERC.xlsx'.
  l_muban = 'ZPPORDERC'.
*&---下载模板
  PERFORM frm_get_fullpath CHANGING gv_fullpath gv_path gv_name.
*&---路径为空则退出
  IF gv_fullpath IS INITIAL.
    MESSAGE '用户取消操作' TYPE 'S'.
    RETURN.
  ENDIF.
  PERFORM frm_down USING gv_fullpath.
ENDFORM.                    " DOWNLOAD_DATA
 
*&---------------------------------------------------------------------*
*&      Form  FRM_GET_FULLPATH
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      <--P_GV_FULLPATH  text
*      <--P_GV_PATH  text
*      <--P_GV_NAME  text
*----------------------------------------------------------------------*
FORM frm_get_fullpath   CHANGING pv_fullpath TYPE string
  pv_path     TYPE string
  pv_name     TYPE string.
 
  DATA: lv_init_path  TYPE string,
        lv_init_fname TYPE string,
        lv_path       TYPE string,
        lv_filename   TYPE string,
        lv_fullpath   TYPE string.
 
*&---初始名称(输出的文件名称)
*  concatenate 'Material_Doc_' SY-DATUM '.xslx' into L_INIT_FNAME.
  lv_init_fname = l_filename.
 
* 获取桌面路径
  CALL METHOD cl_gui_frontend_services=>get_desktop_directory
    CHANGING
      desktop_directory    = lv_init_path
    EXCEPTIONS
      cntl_error           = 1
      error_no_gui         = 2
      not_supported_by_gui = 3
      OTHERS               = 4.
  IF sy-subrc <> 0.
    EXIT.
  ENDIF.
 
*&---用户选择名称、路径
  CALL METHOD cl_gui_frontend_services=>file_save_dialog
    EXPORTING
*     window_title         = '指定保存文件名'
*     default_extension    = 'DOC'
      default_file_name    = lv_init_fname
*     FILE_FILTER          = CL_GUI_FRONTEND_SERVICES=>FILETYPE_EXCEL
*     FILE_FILTER          = CL_GUI_FRONTEND_SERVICES=>FILETYPE_WORD
      initial_directory    = lv_init_path
      prompt_on_overwrite  = 'X'
    CHANGING
      filename             = lv_filename
      path                 = lv_path
      fullpath             = lv_fullpath
*     USER_ACTION          =
*     FILE_ENCODING        =
    EXCEPTIONS
      cntl_error           = 1
      error_no_gui         = 2
      not_supported_by_gui = 3
      OTHERS               = 4.
  IF sy-subrc = 0.
    pv_fullpath = lv_fullpath.
    pv_path     = lv_path.
  ENDIF.
ENDFORM.                    " FRM_GET_FULLPATH
 
*--------------------------------------------------------------------*
*       下载文件
*--------------------------------------------------------------------*
FORM frm_down  USING pr_filename.
  DATA: lv_objdata     LIKE wwwdatatab,
        lv_mime        LIKE w3mime,
        lv_destination LIKE rlgrap-filename,
        lv_objnam      TYPE string,
        lv_rc          LIKE sy-subrc,
        lv_errtxt      TYPE string.
 
  DATA: lv_filename TYPE string,
        lv_result,
        lv_subrc    TYPE sy-subrc.
 
  DATA: lv_objid TYPE wwwdatatab-objid .
 
 
  lv_objid = l_muban.  "上传的模版名称
 
*&---查找文件是否存在。
  SELECT SINGLE relid objid
  FROM wwwdata
  INTO CORRESPONDING FIELDS OF lv_objdata
  WHERE srtf2    = 0
  AND   relid    = 'MI'
  AND   objid    = lv_objid.
 
*&---判断模版不存在则报错
  IF sy-subrc NE 0 OR lv_objdata-objid EQ space.
    CONCATENATE '模板文件:' lv_objid '不存在,请用TCODE:SMW0进行加载'
    INTO lv_errtxt.
    MESSAGE lv_errtxt TYPE 'E'.
  ENDIF.
 
  lv_filename = pr_filename.
 
  "判断本地地址是否已经存在此文件。
  CALL METHOD cl_gui_frontend_services=>file_exist
    EXPORTING
      file                 = lv_filename
    RECEIVING
      result               = lv_result
    EXCEPTIONS
      cntl_error           = 1
      error_no_gui         = 2
      wrong_parameter      = 3
      not_supported_by_gui = 4
      OTHERS               = 5.
  IF sy-subrc <> 0.
    CASE sy-subrc.
      WHEN 1.
      WHEN 2.
      WHEN OTHERS.
    ENDCASE.
  ENDIF.
 
  IF lv_result EQ 'X'.  "如果存在则删除原始文件,重新覆盖
    CALL METHOD cl_gui_frontend_services=>file_delete
      EXPORTING
        filename             = lv_filename
      CHANGING
        rc                   = lv_subrc
      EXCEPTIONS
        file_delete_failed   = 1
        cntl_error           = 2
        error_no_gui         = 3
        file_not_found       = 4
        access_denied        = 5
        unknown_error        = 6
        not_supported_by_gui = 7
        wrong_parameter      = 8
        OTHERS               = 9.
 
    IF sy-subrc <> 0.
      CASE sy-subrc.
        WHEN 1.
        WHEN 2.
        WHEN OTHERS.
      ENDCASE.
    ENDIF.
 
    IF lv_subrc <> 0. "如果删除失败,则报错。
      CONCATENATE '同名EXCEL文件已打开' '请关闭该EXCEL后重试。'
      INTO lv_errtxt.
      MESSAGE lv_errtxt TYPE 'E'.
    ENDIF.
  ENDIF.
 
  lv_destination   = pr_filename.
 
*&---下载模版。
  CALL FUNCTION 'DOWNLOAD_WEB_OBJECT'
    EXPORTING
      KEY         = lv_objdata
      destination = lv_destination
    IMPORTING
      rc          = lv_rc.
  IF lv_rc NE 0.
    CONCATENATE '模板文件' '下载失败' INTO lv_errtxt.
    MESSAGE lv_errtxt TYPE 'E'.
  ENDIF.
ENDFORM.                    "frm_down
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103
  • 104
  • 105
  • 106
  • 107
  • 108
  • 109
  • 110
  • 111
  • 112
  • 113
  • 114
  • 115
  • 116
  • 117
  • 118
  • 119
  • 120
  • 121
  • 122
  • 123
  • 124
  • 125
  • 126
  • 127
  • 128
  • 129
  • 130
  • 131
  • 132
  • 133
  • 134
  • 135
  • 136
  • 137
  • 138
  • 139
  • 140
  • 141
  • 142
  • 143
  • 144
  • 145
  • 146
  • 147
  • 148
  • 149
  • 150
  • 151
  • 152
  • 153
  • 154
  • 155
  • 156
  • 157
  • 158
  • 159
  • 160
  • 161
  • 162
  • 163
  • 164
  • 165
  • 166
  • 167
  • 168
  • 169
  • 170
  • 171
  • 172
  • 173
  • 174
  • 175
  • 176
  • 177
  • 178
  • 179
  • 180
  • 181
  • 182
  • 183
  • 184
  • 185
  • 186
  • 187
  • 188
  • 189
  • 190
  • 191
  • 192
  • 193
  • 194
  • 195
  • 196
  • 197
  • 198
  • 199
  • 200
  • 201
  • 202
  • 203
  • 204
  • 205
  • 206
  • 207
  • 208
  • 209
  • 210
  • 211
  • 212
  • 213
  • 214
  • 215
  • 216
  • 217
  • 218
  • 219
  • 220
  • 221
  • 222
  • 223
  • 224
  • 225
  • 226
  • 227
  • 228
  • 229
  • 230
  • 231
  • 232
  • 233
  • 234
  • 235
  • 236
  • 237
  • 238
  • 239
  • 240
  • 241
  • 242
  • 243
  • 244
  • 245
  • 246
  • 247
  • 248
  • 249
  • 250
  • 251
  • 252
  • 253
  • 254
  • 255
  • 256
  • 257
  • 258
  • 259
  • 260
  • 261
  • 262
  • 263
  • 264
  • 265
  • 266
  • 267
  • 268
  • 269
  • 270
  • 271
  • 272
  • 273
  • 274
  • 275
  • 276
  • 277
  • 278
  • 279
  • 280
  • 281
  • 282
  • 283
  • 284
  • 285
  • 286
  • 287
  • 288
  • 289
  • 290
  • 291
  • 292
  • 293
  • 294
  • 295
  • 296
  • 297
  • 298
  • 299
  • 300
  • 301
  • 302
  • 303
  • 304
  • 305
  • 306
  • 307
  • 308
  • 309
  • 310
  • 311
  • 312
  • 313
  • 314
  • 315
  • 316
  • 317
  • 318
  • 319
  • 320
  • 321
  • 322
  • 323
  • 324
  • 325
  • 326
  • 327
  • 328
  • 329
  • 330
  • 331
  • 332
  • 333
  • 334
  • 335
  • 336
  • 337
  • 338
  • 339
  • 340
  • 341
  • 342
  • 343
  • 344
  • 345
  • 346
  • 347
  • 348
  • 349
  • 350
  • 351
  • 352
  • 353
  • 354
  • 355
  • 356
  • 357
  • 358
  • 359
  • 360
  • 361
  • 362
  • 363
  • 364
  • 365
  • 366
  • 367
  • 368
  • 369
  • 370
  • 371
  • 372
  • 373
  • 374
  • 375
  • 376
  • 377
  • 378
  • 379
  • 380
  • 381
  • 382
  • 383
  • 384
  • 385
  • 386
  • 387
  • 388
  • 389
  • 390
  • 391
  • 392
  • 393
  • 394
  • 395
  • 396
  • 397
  • 398
  • 399
  • 400
  • 401
  • 402
  • 403
  • 404
  • 405
  • 406
  • 407
  • 408
  • 409
  • 410
  • 411
  • 412
  • 413
  • 414
  • 415
  • 416
  • 417
  • 418
  • 419
  • 420
  • 421
  • 422
  • 423
  • 424
  • 425
  • 426
  • 427
  • 428
  • 429
  • 430
  • 431
  • 432
  • 433
  • 434
  • 435
  • 436
  • 437
  • 438
  • 439
  • 440
  • 441
  • 442
  • 443
  • 444
  • 445
  • 446
  • 447
  • 448
  • 449
  • 450
  • 451
  • 452
  • 453
  • 454
  • 455
  • 456
  • 457
  • 458
  • 459
  • 460
  • 461
  • 462
  • 463
  • 464
  • 465
  • 466
  • 467
  • 468
  • 469
  • 470
  • 471
  • 472
  • 473
  • 474
  • 475
  • 476
  • 477
  • 478
  • 479
  • 480
  • 481
  • 482
  • 483
  • 484
  • 485
  • 486
  • 487
  • 488
  • 489
  • 490
  • 491
  • 492
  • 493
  • 494
  • 495
  • 496
  • 497
  • 498
  • 499
  • 500
  • 501
  • 502
  • 503
  • 504
  • 505
  • 506
  • 507
  • 508
  • 509
  • 510
  • 511
  • 512
  • 513
  • 514
  • 515
  • 516
  • 517
  • 518
  • 519
  • 520
  • 521
  • 522
  • 523
  • 524
  • 525
  • 526
  • 527
  • 528
  • 529
  • 530
  • 531
  • 532
  • 533
  • 534
  • 535
  • 536
  • 537
  • 538
  • 539
  • 540
  • 541
  • 542
  • 543
  • 544
  • 545
  • 546
  • 547
  • 548
  • 549
  • 550
  • 551
  • 552
  • 553
  • 554
  • 555
  • 556
  • 557
  • 558
  • 559
  • 560
  • 561
  • 562
  • 563
  • 564
  • 565
  • 566
  • 567
  • 568
  • 569
  • 570
  • 571
  • 572
  • 573
  • 574
  • 575
  • 576
  • 577
  • 578
  • 579
  • 580
  • 581
  • 582
  • 583
  • 584
  • 585
  • 586
  • 587
  • 588
  • 589
  • 590
  • 591
  • 592
  • 593
  • 594
  • 595
  • 596
  • 597
  • 598
  • 599
  • 600
  • 601
  • 602
  • 603
  • 604
  • 605
  • 606
  • 607
  • 608
  • 609
  • 610
  • 611
  • 612
  • 613
  • 614
  • 615
  • 616
  • 617
  • 618
  • 619
  • 620
  • 621
  • 622
  • 623
  • 624
  • 625
  • 626
  • 627
  • 628
  • 629
  • 630
  • 631
  • 632
  • 633
  • 634
  • 635
  • 636
  • 637
  • 638
  • 639
  • 640
  • 641
  • 642
  • 643
  • 644
  • 645
  • 646
  • 647
  • 648
  • 649
  • 650
  • 651
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/你好赵伟/article/detail/84616
推荐阅读
相关标签
  

闽ICP备14008679号