SAP ROUTING导入源代码!

原文: http://blog.sina.com.cn/s/blog_76c57b480100z3np.html


 *&---------------------------------------------------------------------*
*& Report  ZCA01UPLOAD
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*


report  ZCA01UPLOAD message-id zdev.            "输出的报表每页的字符宽度.
*---->define table->bapi
data: group               type bapi1012_tsk_c-task_list_group,
      group_counter       type bapi1012_tsk_c-group_counter,
      task                type bapi1012_tsk_c occurs with header line,
      material            type bapi1012_mtk_c occurs with header line,
      sequence            type bapi1012_seq_c   occurs with header line,
      operation           type bapi1012_opr_c   occurs with header line,
      return              type bapiret2   occurs with header line
.
*---->message table
data: begin of t_error occurs 0.
data  material like bapi1012_mtk_c-material.
        include structure bapiret2.     "将结构bapiret2 中所有的字段放入内表 t_error。
data: end of t_error.
*---->inner table
data: begin of t_tab occurs ,

  material      like bapi1012_mtk_c-material,     "物料号
  plant         like bapi1012_mtk_c-plant,        "工厂
 group         like bapi1012_tsk_c-task_list_group,
 group_counter like bapi1012_tsk_c-group_counter,
  description1  like bapi1012_tsk_c-description,  "任务清单描述
  activity      like bapi1012_opr_c-activity,     "操作/活动编号
  work_cntr     like bapi1012_opr_c-work_cntr,    "工作中心
  control_key   like bapi1012_opr_c-control_key,  "控制码
  description   like bapi1012_opr_c-description,  "工序短文本
  base_quantity like bapi1012_opr_c-base_quantity,"基本数量
  std_value_01  like bapi1012_opr_c-std_value_01, "标准值  人工工时
  std_value_02  like bapi1012_opr_c-std_value_02,  "标准值  机器工时

 max_no_of_splits     like bapi1012_opr_c-max_no_of_splits,
 ind_splitting_reqrd  like bapi1012_opr_c-ind_splitting_reqrd,
 required_overlapping like bapi1012_opr_c-required_overlapping,
 min_send_ahead_qty   like bapi1012_opr_c-min_send_ahead_qty,
end of t_tab.

data:BEGIN OF t_mapl OCCURS 0,
  MATNR like mapl-matnr,
  WERKS like mapl-werks,
  PLNTY like mapl-plnty,
  PLNNR like mapl-plnnr,
  PLNAL like mapl-plnal,
  LOEKZ like mapl-loekz,
  END OF t_mapl.


data gt_tab like t_tab occurs with header line.
data lv_cancel(1) type c.

selection-screen begin of block blk with frame title text-001.
parameters:p_file like rlgrap-filename obligatory.
selection-screen end of block blk.

at selection-screen on value-request for p_file.
  perform select_file.


start-of-selection.
 perform  upload_data.
 perform call_bapi.
*&---------------------------------------------------------------------*
*&      Form  call_bapi
*&---------------------------------------------------------------------*
      text
*----------------------------------------------------------------------*
form call_bapi.
 sort t_tab by  material plant.  "按照 material plant activity进行排序
 sort t_tab by material plant.
  loop at t_tab.

    call function 'CONVERSION_EXIT_ALPHA_INPUT'
      exporting
        input  t_tab-material
      importing
        output t_tab-material.
    move t_tab to gt_tab.
    append gt_tab.
      perform  check_plnnr.

*-----〉item-sequence

    operation-activity t_tab-activity.  "操作/活动编号
    operation-control_key t_tab-control_key. "控制码
    operation-work_cntr t_tab-work_cntr. "工作中心
    operation-description t_tab-description. "工序短文本

    operation-plant t_tab-plant.     "工厂
    operation-denominator 1.   "用于转换工艺路线和工序单位的分母
    operation-nominator 1.    "用于转换任务清单和工序计量单位的计数器
    operation-base_quantity t_tab-base_quantity.   "基本数量
    operation-std_value_01 t_tab-std_value_01.     "标准值  人工工时
    operation-std_value_02 t_tab-std_value_02.    "标准值  机器工时
    operation-VALID_FROM   sy-datum 30.
    operation-valid_to_date '99991231'.
    operation-COST_RELEVANT 'X'.
    append operation.
*---------对于有同种物料、同一工厂,相同组,不同组计数器,有不同工艺路线的情况,模版的同一计数器放在一起,中间用不同的物料隔开。-----*
    at end of material.             "当同一物料结束时调用bapi  ,
*-----〉header
      READ TABLE t_mapl with key matnr  gt_tab-material werks gt_tab-plant.
      IF  sy-subrc 0.
         task-task_list_group t_mapl-plnnr.
      ENDIF.
      task-task_list_usage '1'.  "任务清单使用
      task-task_list_status '4'.  "状态
**---->unit
      select single meins into task-task_measure_unit
      from mara
      where matnr gt_tab-material.
      task-description gt_tab-description1."'TEST ROUTING'.
      task-plant gt_tab-plant.
      task-valid_from sy-datum 30.
      task-valid_to_date '99991231'.
      append task.

      material-material gt_tab-material.
      material-plant gt_tab-plant.
      append material.

      call function 'BAPI_ROUTING_CREATE'
      importing
        group                  group
        groupcounter           group_counter
      tables
        task                   task
        materialtaskallocation material
        sequence               sequence
        operation              operation
        return                 return.

      refresh task.
      refresh gt_tab.
      refresh material.
      refresh operation.
      refresh t_error.
      loop at return.
        if return-type 'E' or return-type 'A'.
          t_error-material material-material.
          t_error-message return-message.
          append t_error.
        else.
          t_error-material material-material.
          t_error-message gt_tab-description1.
           append t_error.
          call function 'BAPI_TRANSACTION_COMMIT' .
        endif.
      endloop.
      loop at t_error.
        write:/ t_error-material,t_error-message.
      endloop.
    endat.
  endloop.
*endif.
endform.                    "call_bapi
*&---------------------------------------------------------------------*
*&      Form  upload_data
*&---------------------------------------------------------------------*
      text
*----------------------------------------------------------------------*
 -->  p1        text
 <--  p2        text
*----------------------------------------------------------------------*
form upload_data .
  data l_fname type string.
  l_fname p_file.
  call function 'GUI_UPLOAD'
  exporting
    filename                      l_fname
    filetype                      'DAT'
    has_field_separator           'X'
  HEADER_LENGTH                 0
  READ_BY_LINE                  'X'
  DAT_MODE                      '
  CODEPAGE                      '
  IGNORE_CERR                   ABAP_TRUE
  REPLACEMENT                   '#'
  CHECK_BOM                     '
  VIRUS_SCAN_PROFILE            =
  NO_AUTH_CHECK                 '
IMPORTING
  FILELENGTH                    =
  HEADER                        =
  tables
    data_tab                      t_tab
  exceptions
    file_open_error               1
    file_read_error               2
    no_batch                      3
    gui_refuse_filetransfer       4
    invalid_type                  5
    no_authority                  6
    unknown_error                 7
    bad_data_format               8
    header_not_allowed            9
    separator_not_allowed         10
    header_too_long               11
    unknown_dp_error              12
    access_denied                 13
    dp_out_of_memory              14
    disk_full                     15
    dp_timeout                    16
    others                        17
    .
  if sy-subrc <> 0.
    message id sy-msgid type sy-msgty number sy-msgno
    with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  endif.
endform.                    upload_data
*&---------------------------------------------------------------------*
*&      Form  SELECT_FILE
*&---------------------------------------------------------------------*
      text
*----------------------------------------------------------------------*
form select_file .
  data: l_filetab type filetable,
        l_waftab like line of l_filetab,
        l_rc type i.
  call method cl_gui_frontend_services=>file_open_dialog
  exporting
    window_title            '打开文件'
     DEFAULT_EXTENSION       =
     DEFAULT_FILENAME        =
     FILE_FILTER             =
     WITH_ENCODING           =
    initial_directory       'C:/'
     MULTISELECTION          =
  changing
    file_table              l_filetab
    rc                      l_rc
     USER_ACTION             =
     FILE_ENCODING           =
  exceptions
    file_open_dialog_failed 1
    cntl_error              2
    error_no_gui            3
    not_supported_by_gui    4
    others                  5
    .
  if sy-subrc <> 0.
    message id sy-msgid type sy-msgty number sy-msgno
    with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
    exit.
  else.
    read table l_filetab into l_waftab index 1.
    p_file l_waftab-filename.
    clear: l_filetab,
    l_waftab.
  endif.
endform.                    "select_file
*&---------------------------------------------------------------------*
*&      Form  CHECK_PLNNR
*&---------------------------------------------------------------------*
      text
*----------------------------------------------------------------------*
 -->  p1        text
 <--  p2        text
*----------------------------------------------------------------------*
FORM CHECK_PLNNR .


  select  MATNR
          WERKS
          PLNTY
          PLNNR
          PLNAL
          LOEKZ
    into TABLE t_mapl
    from mapl
    where matnr gt_tab-material
    and   werks gt_tab-plant
    and   loekz <> 'X'
    and   plnnr is NOT NULL.

ENDFORM.                    CHECK_PLNNR

数据导入模板:



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值