PP主数据批导-工艺路线

事务码:CA02

隐式增强:LCPDIFV1


这个函数增加了一个取值

FUNCTION zpp_pr_s4.
*"----------------------------------------------------------------------
*"*"本地接口:
*"  IMPORTING
*"     VALUE(I_PLNTY) TYPE  PLNTY OPTIONAL
*"     VALUE(I_PLNNR) TYPE  PLNNR OPTIONAL
*"     VALUE(I_PLNAL) TYPE  PLNAL OPTIONAL
*"     VALUE(I_MATNR) TYPE  MATNR OPTIONAL
*"     VALUE(I_WERKS) TYPE  WERKS_D OPTIONAL
*"  TABLES
*"      T_RETURN STRUCTURE  BAPIRET2 OPTIONAL
*"----------------------------------------------------------------------
  DATA: l_plnnr TYPE bapi1012_tsk_c-task_list_group.

  DATA: lt_plko    TYPE TABLE OF bapi1012_tsk_c WITH HEADER LINE,
        lt_mapl    TYPE TABLE OF bapi1012_mtk_c WITH HEADER LINE,
        lt_seqx    TYPE TABLE OF bapi1012_seq_c WITH HEADER LINE,
        lt_plpo    TYPE TABLE OF bapi1012_opr_c WITH HEADER LINE,
        lt_subplpo TYPE TABLE OF bapi1012_sub_opr_c WITH HEADER LINE.
  DATA: lt_msg TYPE TABLE OF bapiret2,
        wa_msg LIKE LINE OF lt_msg.
  DATA: lt_tsk TYPE TABLE OF capp_tsk  WITH HEADER LINE.
  DATA: lt_seq TYPE TABLE OF capp_seq  WITH HEADER LINE.
  DATA: lt_opr TYPE TABLE OF capp_opr  WITH HEADER LINE.
  DATA: lt_crhd TYPE TABLE OF crhd  WITH HEADER LINE.


  CALL FUNCTION 'ZCARO_ROUTING_READ' DESTINATION 'BACK'   "读ecc
    EXPORTING
*     DATE_FROM    = '19000101'
*     DATE_TO      = '99991231'
      plnty        = i_plnty
      plnnr        = i_plnnr
      plnal        = i_plnal
      matnr        = i_matnr
*     IV_CREATE_ADD_CHANGE       = ' '
*     werks        = i_werks
    TABLES
      tsk_tab      = lt_tsk
      seq_tab      = lt_seq
      opr_tab      = lt_opr
      t_crhd       = lt_crhd
    EXCEPTIONS
      not_found    = 1
      ref_not_exp  = 2
      not_valid    = 3
      no_authority = 4
      OTHERS       = 5.
  IF sy-subrc <> 0.
* Implement suitable error handling here
  ENDIF.

  "赋值
***表头***
  READ TABLE lt_tsk INDEX 1.
  IF sy-subrc = 0.
    lt_plko-valid_from = sy-datum.  "生效日期
    lt_plko-valid_to_date = '99991231'. "有效期限
    lt_plko-plant = I_WERKS.               "目标工厂
    lt_plko-task_list_usage = lt_tsk-verwe.      "用途
    lt_plko-task_list_status = lt_tsk-statu.      "状态
    lt_plko-task_measure_unit = lt_tsk-plnme.  "单位
    lt_plko-lot_size_from = lt_tsk-losvn.         "批量下限
    lt_plko-lot_size_to = lt_tsk-losbs. "批量上限
    APPEND lt_plko.
    CLEAR lt_plko.



  ENDIF.
***物料指派***
  lt_mapl-material_long = i_matnr.
  lt_mapl-plant = I_WERKS.
  lt_mapl-valid_from = sy-datum..
  lt_mapl-valid_to_date = '99991231'.
  APPEND lt_mapl.
  CLEAR lt_mapl.

***作业***
  LOOP AT lt_opr.
    lt_plpo-activity = lt_opr-vornr.
    lt_plpo-description = lt_opr-ltxa1.
    lt_plpo-plant = I_WERKS.
    "   lt_plpo-group_counter = lt_opr-plnal.
    "   lt_plpo-operation_id = lt_opr-oprid.

    lt_plpo-denominator = lt_opr-umren. "用于转换工艺路线和工序单位的分母
    lt_plpo-nominator = lt_opr-umrez.  "用于转换任务清单和工序计量单位的计数器

    "取arbpl工作中心
    READ TABLE lt_crhd WITH KEY objid = lt_opr-arbid.
    IF sy-subrc = 0.
      lt_plpo-work_cntr = lt_crhd-arbpl.
    ENDIF.

    "   *
    lt_plpo-control_key = lt_opr-steus.  "控制码
    lt_plpo-standard_text_key = lt_opr-ktsch.  "标准内文码
    lt_plpo-base_quantity = lt_opr-bmsch.  "基础数量
    lt_plpo-operation_measure_unit = lt_opr-meinh.  "单位
    lt_plpo-std_value_01 = lt_opr-vgw01.
    lt_plpo-std_unit_01 =  lt_opr-vge01.  "
    lt_plpo-std_value_02 = lt_opr-vgw02.
    lt_plpo-std_unit_02 =  lt_opr-vge02.  "
    lt_plpo-std_value_03 = lt_opr-vgw03.
    lt_plpo-std_unit_03 =  lt_opr-vge03.  "
    lt_plpo-std_value_04 = lt_opr-vgw04. "
    lt_plpo-std_unit_04 =  lt_opr-vge04.  "
    lt_plpo-std_value_05 = lt_opr-vgw05. "
    lt_plpo-std_unit_05 =  lt_opr-vge05.
    lt_plpo-std_value_06 = lt_opr-vgw06. "
    lt_plpo-std_unit_06 =  lt_opr-vge06.
    lt_plpo-scrap_factor = lt_opr-aufak.
    lt_plpo-valid_from = sy-datum.
    lt_plpo-valid_to_date = lt_opr-datub.
    lt_plpo-cost_relevant = 'X'."lt_opr-ckselkz.

    "  lt_plpo-sequence_no  = lt_seq-plnfl..


    APPEND lt_plpo.
    CLEAR lt_plpo.
  ENDLOOP.


  "判断工艺路线是否存在

  SELECT COUNT(*) FROM mapl WHERE matnr = i_matnr AND werks = i_werks .

  IF sy-subrc <> 0.
    "创建工艺路线
    CALL FUNCTION 'BAPI_ROUTING_CREATE'
* EXPORTING
*   testrun                     = ' '
*   profile                      =
*   bomusage                =
*   application                =
      IMPORTING
        group                  = l_plnnr
*       groupcounter           =
      TABLES
        task                   = lt_plko
        materialtaskallocation = lt_mapl
*       sequence               = lt_seqx
        operation              = lt_plpo
*       text                   =
        return                 = lt_msg
*       task_segment           =
      .
  ELSE.
    "修改
    wa_msg-message = '此工艺路线在目标系统已存在'.
    wa_msg-type = 'E'.

    APPEND  wa_msg TO lt_msg.
    CLEAR:wa_msg.



  ENDIF.

  READ TABLE lt_msg INTO wa_msg WITH KEY type = 'E'.
  IF sy-subrc = 0.
    ROLLBACK WORK.
    LOOP AT lt_msg INTO wa_msg.
      CONCATENATE  wa_msg-id wa_msg-number wa_msg-message INTO t_return-message.
      t_return-type = 'E'.
      APPEND t_return.
    ENDLOOP.
  ELSE.
    COMMIT WORK.
    t_return-message = l_plnnr && '/' && i_matnr && '工艺路线已创建成功'.
    t_return-type = 'S'.
    APPEND t_return.
  ENDIF.

  "修改工艺路线





ENDFUNCTION.

留存吧,指不定以后能用到,省点事

知识点

PP主数据批导-生产版本

2020-7-31 21:37:17

知识点

内存传值做成函数,方便查找

2020-8-1 13:10:49

0 条回复 A文章作者 M管理员
    暂无讨论,说说你的看法吧
个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索